-
Notifications
You must be signed in to change notification settings - Fork 21
/
transaction-end.js
78 lines (66 loc) · 2.41 KB
/
transaction-end.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Transaction End
*
* End a transaction
*
* Parameters
*
* transactionName (JS) : Name of transaction
* If transactionName is set to "OpenTransactions" then all open transactions will be ended
*
* Notes
* Transaction Begin/End can be added as Before/After test hooks to get timing information for every step
*
* Disclaimer
* This Custom Action is provided "AS IS". It is for instructional purposes only and is not officially supported by Testim
*
* Base Step
* Custom Action
*
* Installation
* Create a new "Custom Action"
* Name it "Transaction End"
* Add parameters
* transactionName (JS)
* Set the new custom action's function body to this javascript
* Exit the step editor
* Share the step if not already done so
* Save the test
* Bob's your uncle
**/
/* global transactionName, transactions */
//console.log("End Transaction");
/* Create global transactions accumulator if necessary
*/
exportsTest.transactions = (typeof transactions === 'undefined' || transactions == null) ? [] : transactions;
/* If transactionName is undefined then use a generic
*/
let DEFAULT_TRANSACTION_NAME = "Transaction_" + exportsTest.transactions.length;
let transaction_name;
if (typeof _stepData !== 'undefined') {
transaction_name = "_stepData";
}
else {
transaction_name = (typeof transactionName !== 'undefined' && transactionName != null) ? transactionName : DEFAULT_TRANSACTION_NAME;
}
/* Close target (named) or all opened transactions
*/
if (exportsTest.transactions !== null && exportsTest.transactions.length > 0) {
exportsTest.transactions.forEach((transaction, index) => {
/* Mark the target transaction completed
*/
if ((transaction.transactionName === transaction_name || transaction_name === "OpenTransactions")
&& transaction.status === "Open"
) {
/* If this is an endStep hook call
* then NOW we can set the transaction name to the step name
*/
if (transaction_name == "_stepData") {
transaction.transactionName = _stepData.name;
}
transaction.endTime = new Date();
transaction.status = "Complete";
transaction.duration = (new Date(transaction.endTime.valueOf()) - new Date(transaction.startTime.valueOf())) / 1000;
}
});
}