froth-webdriverio-framework 6.0.73 → 6.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
async function getBSBuildDetails(sessiontype, bs_username, bs_pwd) {
|
|
1
|
+
async function getBSBuildDetails(sessionType, bsUsername, bsPassword) {
|
|
3
2
|
try {
|
|
4
|
-
|
|
5
|
-
console.log("sessiontype:" + sessiontype)
|
|
6
|
-
const username = bs_username;
|
|
7
|
-
const accessKey = bs_pwd;
|
|
8
|
-
console.log("accessKey:" + accessKey)
|
|
9
|
-
const basicAuth = btoa(`${username}:${accessKey}`);
|
|
3
|
+
console.log(`Session type: ${sessionType}`);
|
|
10
4
|
|
|
11
|
-
|
|
5
|
+
const basicAuth = btoa(`${bsUsername}:${bsPassword}`);
|
|
6
|
+
const buildName = sessionType === 'app-automate'
|
|
7
|
+
? `Mobile_Build-${process.env.FROTH_TESTOPS_BUILD_NAME}`
|
|
8
|
+
: `Web_Build-${process.env.FROTH_TESTOPS_BUILD_NAME}`;
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
console.log("Browsersatck build name :" + process.env.FROTH_TESTOPS_BUILD_NAME)
|
|
15
|
-
const url = `https://api.browserstack.com/${sessiontype}/builds.json?name=${process.env.FROTH_TESTOPS_BUILD_NAME}`;
|
|
10
|
+
console.log(`BrowserStack build name: ${buildName}`);
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
const url = `https://api.browserstack.com/${sessionType}/builds.json?name=${buildName}`;
|
|
13
|
+
console.log(`URL: ${url}`);
|
|
18
14
|
|
|
19
15
|
const response = await fetch(url, {
|
|
20
16
|
method: 'GET',
|
|
@@ -25,47 +21,34 @@ async function getBSBuildDetails(sessiontype, bs_username, bs_pwd) {
|
|
|
25
21
|
|
|
26
22
|
if (response.ok) {
|
|
27
23
|
const data = await response.json();
|
|
28
|
-
console.log(
|
|
29
|
-
// Accessing the public_url property
|
|
30
|
-
hashed_id = data[0].automation_build.hashed_id;
|
|
31
|
-
|
|
32
|
-
return hashed_id;
|
|
33
|
-
} else if (response.status === 401) { //
|
|
34
|
-
console.log("Unauthorized, token expired")
|
|
24
|
+
console.log(`Build data: ${JSON.stringify(data)}`);
|
|
35
25
|
|
|
26
|
+
return data[0].automation_build.hashed_id;
|
|
27
|
+
} else if (response.status === 401) {
|
|
28
|
+
console.error("Unauthorized: token expired");
|
|
36
29
|
} else {
|
|
37
30
|
const errorText = await response.text();
|
|
38
|
-
console.error(`
|
|
39
|
-
// console.error(`Data fetch failed response in getBSBuildDetails:${errorText}`);
|
|
40
|
-
// throw new Error(`HTTP error! status: ${response.status}`);
|
|
31
|
+
console.error(`Failed to fetch build details: ${response.status}, ${errorText}`);
|
|
41
32
|
}
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
34
|
} catch (error) {
|
|
46
|
-
console.error('Error fetching
|
|
47
|
-
|
|
35
|
+
console.error('Error fetching build details:', error);
|
|
48
36
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
37
|
}
|
|
52
38
|
|
|
53
|
-
async function getBSSessionDetails(
|
|
39
|
+
async function getBSSessionDetails(sessionType, bsUsername, bsPassword) {
|
|
54
40
|
try {
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
// const accessKey = Buffer.from(bs_pwd, 'base64').toString('utf-8');
|
|
58
|
-
const accessKey = bs_pwd;
|
|
41
|
+
const basicAuth = btoa(`${bsUsername}:${bsPassword}`);
|
|
42
|
+
const hashId = await getBSBuildDetails(sessionType, bsUsername, bsPassword);
|
|
59
43
|
|
|
60
|
-
|
|
44
|
+
if (!hashId) {
|
|
45
|
+
console.error("Build hash ID not found. Cannot fetch session details.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
61
48
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
console.log("hash_id" + hash_id)
|
|
49
|
+
const url = `https://api.browserstack.com/${sessionType}/builds/${hashId}/sessions.json`;
|
|
50
|
+
console.log(`URL: ${url}`);
|
|
65
51
|
|
|
66
|
-
// const url = `https://api.browserstack.com/${sessiontype}/sessions/${sessionid}.json`;
|
|
67
|
-
const url = `https://api.browserstack.com/${sessiontype}/builds/${hash_id}/sessions.json`;
|
|
68
|
-
console.log("url:" + url)
|
|
69
52
|
const response = await fetch(url, {
|
|
70
53
|
method: 'GET',
|
|
71
54
|
headers: {
|
|
@@ -75,71 +58,39 @@ async function getBSSessionDetails(sessiontype, bs_username, bs_pwd) {
|
|
|
75
58
|
|
|
76
59
|
if (response.ok) {
|
|
77
60
|
const data = await response.json();
|
|
78
|
-
|
|
79
|
-
// Accessing the public_url property
|
|
80
61
|
const publicUrl = data[0].automation_session.public_url;
|
|
81
62
|
const duration = data[0].automation_session.duration;
|
|
82
|
-
BUFFER.setItem("REPORT_URL", publicUrl)
|
|
83
|
-
BUFFER.setItem("FROTH_TOTAL_DURATION", duration)
|
|
84
|
-
console.log("public url:" + publicUrl)
|
|
85
|
-
//return jsondata;
|
|
86
|
-
} else if (response.status === 401) { //
|
|
87
|
-
console.log("Unauthorized, token expired")
|
|
88
63
|
|
|
64
|
+
BUFFER.setItem("REPORT_URL", publicUrl);
|
|
65
|
+
BUFFER.setItem("FROTH_TOTAL_DURATION", duration);
|
|
66
|
+
|
|
67
|
+
console.log(`Public URL: ${publicUrl}`);
|
|
68
|
+
} else if (response.status === 401) {
|
|
69
|
+
console.error("Unauthorized: token expired");
|
|
89
70
|
} else {
|
|
90
71
|
const errorText = await response.text();
|
|
91
|
-
console.error(`
|
|
92
|
-
// throw new Error(`HTTP error! status: ${response.status}`);
|
|
72
|
+
console.error(`Failed to fetch session details: ${response.status}, ${errorText}`);
|
|
93
73
|
}
|
|
94
74
|
|
|
95
|
-
|
|
96
|
-
|
|
97
75
|
} catch (error) {
|
|
98
|
-
console.error('Error fetching
|
|
99
|
-
|
|
76
|
+
console.error('Error fetching session details:', error);
|
|
100
77
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
78
|
}
|
|
104
79
|
|
|
105
80
|
async function amend2Browserstack(annotationMessage, level) {
|
|
106
81
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
82
|
+
console.log(`Annotation message: ${annotationMessage}`);
|
|
83
|
+
if (process.env.PLATFORM === 'browserstack') {
|
|
84
|
+
await driver.execute(`browserstack_executor: {"action": "annotate", "arguments": {"data":"${annotationMessage}","level": "${level}"}}`);
|
|
85
|
+
}
|
|
112
86
|
} catch (error) {
|
|
113
|
-
console.error('Error
|
|
87
|
+
console.error('Error annotating BrowserStack session:', error);
|
|
114
88
|
throw error;
|
|
115
89
|
}
|
|
116
90
|
}
|
|
117
91
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// Execute the main function
|
|
122
|
-
|
|
123
|
-
// Main function to execute the API call
|
|
124
|
-
// async function main() {
|
|
125
|
-
// try {
|
|
126
|
-
// /// BUFFER.setItem("EXECUTION_SESSIONID","297666e2fd4195de98d7da3b359669072ff41a2a");
|
|
127
|
-
// const login=0.30;
|
|
128
|
-
// const landing=0.30;
|
|
129
|
-
// const home=0.30;
|
|
130
|
-
// const payment=0.30;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// await amend2Browserstack("\n Page load time for login page:"+login+"\n Page load time for landing page:"+landing+"\n Page load time for home page:"+home+"\n Page load time for payment page:"+payment, "info");
|
|
134
|
-
// } catch (error) {
|
|
135
|
-
// console.error('Error in main function:', error);
|
|
136
|
-
// }
|
|
137
|
-
// }
|
|
138
|
-
|
|
139
|
-
// main();
|
|
140
92
|
module.exports = {
|
|
141
93
|
getBSSessionDetails,
|
|
142
94
|
getBSBuildDetails,
|
|
143
95
|
amend2Browserstack,
|
|
144
96
|
};
|
|
145
|
-
|
|
@@ -30,7 +30,7 @@ module.exports = (bsCaps) => {
|
|
|
30
30
|
'bstack:options': {
|
|
31
31
|
// projectName: 'BrowserStack Samples',
|
|
32
32
|
buildName: 'Mobile_Build-',
|
|
33
|
-
|
|
33
|
+
// sessionName: 'Mobile Test',
|
|
34
34
|
deviceName: bsCaps.deviceName || 'Samsung Galaxy S22 Ultra',
|
|
35
35
|
osVersion: bsCaps.platformVersion || '12.0',
|
|
36
36
|
debug: bsCaps.debug,
|
|
@@ -31,7 +31,7 @@ module.exports = (bsCaps) => {
|
|
|
31
31
|
'bstack:options': {
|
|
32
32
|
os: bsCaps.os,
|
|
33
33
|
osVersion: bsCaps.osVersion,
|
|
34
|
-
|
|
34
|
+
// buildName: 'Web_Build-',
|
|
35
35
|
debug: bsCaps.debug,
|
|
36
36
|
networkLogs: bsCaps.networkLogs,
|
|
37
37
|
interactiveDebugging: bsCaps.interactiveDebugging,
|
|
@@ -3,7 +3,7 @@ const setAllDetails = require('./setallDatailinBuffer');
|
|
|
3
3
|
const exeDetails = require('../froth_api_calls/getexecutionDetails');
|
|
4
4
|
const { getBSSessionDetails } = require('../froth_api_calls/browsersatckSessionInfo');
|
|
5
5
|
let globalErrorHandled = false;
|
|
6
|
-
let suiteStartTime;
|
|
6
|
+
let suiteStartTime = 0;
|
|
7
7
|
let totalTestDuration = 0;
|
|
8
8
|
const url = require('url');
|
|
9
9
|
const fs = require('fs');
|
|
@@ -59,7 +59,7 @@ async function safeUpdateExecution() {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/* ----------------- HELPER FUNCTIONS ----------------- */
|
|
62
|
-
function msToTime(ms) {
|
|
62
|
+
async function msToTime(ms) {
|
|
63
63
|
if (!ms || isNaN(ms)) return '00:00:00';
|
|
64
64
|
|
|
65
65
|
let seconds = Math.floor(ms / 1000);
|
|
@@ -87,9 +87,11 @@ const commonHooks = {
|
|
|
87
87
|
|
|
88
88
|
/* ========== ON PREPARE ========== */
|
|
89
89
|
onPrepare: async () => {
|
|
90
|
+
suiteStartTime = Date.now();
|
|
90
91
|
registerGlobalErrorHandlers();
|
|
91
92
|
|
|
92
93
|
console.log('==== ON PREPARE HOOK ====');
|
|
94
|
+
|
|
93
95
|
await setAllDetails.setEnvVariables();
|
|
94
96
|
await setAllDetails.setExecutionDetails();
|
|
95
97
|
await setAllDetails.setSuiteDetails();
|
|
@@ -184,6 +186,7 @@ const commonHooks = {
|
|
|
184
186
|
/* ========== AFTER TEST ========== */
|
|
185
187
|
afterTest: async (test, _, { error, duration, passed }) => {
|
|
186
188
|
console.log(`==== AFTER TEST HOOK ===='${test.title}'`);
|
|
189
|
+
if (!totalTestDuration) totalTestDuration = 0;
|
|
187
190
|
totalTestDuration += duration;
|
|
188
191
|
|
|
189
192
|
const fileName = path.basename(test.file);
|
|
@@ -218,14 +221,16 @@ const commonHooks = {
|
|
|
218
221
|
/* ==== AFTER SESSION ==== */
|
|
219
222
|
afterSession: async (config, capabilities, specs, exitCode) => {
|
|
220
223
|
console.log('==== AFTER SESSION ====');
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
// Do not calculate time here; we will use WDIO's total duration in onComplete
|
|
225
|
+
console.log('⏱ Leaving execution time calculation for onComplete hook');
|
|
226
|
+
// const endTime = Date.now();
|
|
227
|
+
// if (!suiteStartTime) suiteStartTime = endTime;
|
|
223
228
|
|
|
224
|
-
const totalTime = Math.max(endTime - suiteStartTime, totalTestDuration);
|
|
225
|
-
// resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
|
|
226
|
-
resultdetails.excution_time = msToTime(totalTime);
|
|
229
|
+
// const totalTime = Math.max(endTime - suiteStartTime, totalTestDuration);
|
|
230
|
+
// // resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
|
|
231
|
+
// resultdetails.excution_time = msToTime(totalTime);
|
|
227
232
|
|
|
228
|
-
console.log('⏱ Final execution time:', resultdetails.excution_time);
|
|
233
|
+
// console.log('⏱ Final execution time:', resultdetails.excution_time);
|
|
229
234
|
|
|
230
235
|
// console.log('📤 Updating DB with final execution details');
|
|
231
236
|
// console.log('Status:', resultdetails.excution_status);
|
|
@@ -257,40 +262,24 @@ const commonHooks = {
|
|
|
257
262
|
/* ========== ON COMPLETE ========== */
|
|
258
263
|
onComplete: async (exitCode, _, __, results) => {
|
|
259
264
|
console.log('==== ON COMPLETE ====');
|
|
260
|
-
console.log(
|
|
265
|
+
console.log('==== ON COMPLETE ====');
|
|
266
|
+
console.log(`Total: ${results.total || 0}, Passed: ${results.passed || 0}, Failed: ${results.failed || 0}`);
|
|
261
267
|
|
|
262
|
-
|
|
268
|
+
const endTime = Date.now();
|
|
269
|
+
const totalTime = endTime - suiteStartTime; // Full WDIO+CI elapsed time
|
|
263
270
|
|
|
264
|
-
|
|
265
|
-
resultdetails.comments.push(`Execution failed with exit code ${exitCode}`);
|
|
266
|
-
}
|
|
267
|
-
// ✅ Set final status
|
|
271
|
+
resultdetails.excution_time = await msToTime(totalTime);
|
|
268
272
|
resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
|
|
269
273
|
|
|
270
|
-
// ✅ If execution failed but no comments, add default comment
|
|
271
274
|
if (exitCode !== 0 && resultdetails.comments.length === 0) {
|
|
272
275
|
resultdetails.comments.push(`Execution failed with exit code ${exitCode}`);
|
|
273
276
|
}
|
|
274
277
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const fallbackTime = totalTestDuration || 0;
|
|
278
|
-
resultdetails.excution_time = msToTime(fallbackTime);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
console.log('📤 Updating DB with final execution details');
|
|
282
|
-
console.log('Status:', resultdetails.excution_status);
|
|
283
|
-
console.log('Duration:', resultdetails.excution_time);
|
|
278
|
+
console.log('⏱ Final execution time (ms):', totalTime);
|
|
279
|
+
console.log('⏱ Final execution time (hh:mm:ss):', resultdetails.excution_time);
|
|
284
280
|
|
|
285
|
-
// await exeDetails.updateExecuitonDetails(
|
|
286
|
-
// BUFFER.getItem('ORGANISATION_DOMAIN_URL'),
|
|
287
|
-
// BUFFER.getItem('FROTH_LOGIN_TOKEN'),
|
|
288
|
-
// BUFFER.getItem('FROTH_EXECUTION_ID'),
|
|
289
|
-
// resultdetails
|
|
290
|
-
// );
|
|
291
281
|
await safeUpdateExecution();
|
|
292
282
|
BUFFER.clear();
|
|
293
|
-
|
|
294
283
|
return exitCode;
|
|
295
284
|
},
|
|
296
285
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froth-webdriverio-framework",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.75",
|
|
4
4
|
"readme": "WendriverIO Integration with [BrowserStack](https://www.browserstack.com)",
|
|
5
5
|
"description": "Selenium examples for WebdriverIO and BrowserStack App Automate",
|
|
6
6
|
"scripts": {
|