froth-webdriverio-framework 6.0.74 → 6.0.76
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 to login Browserstack for getting session info");
|
|
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 to login Browserstack");
|
|
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
|
-
|
|
@@ -29,7 +29,7 @@ module.exports = (bsCaps) => {
|
|
|
29
29
|
platformName: bsCaps.platformName || 'Android',
|
|
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',
|
|
@@ -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();
|
|
@@ -150,6 +152,8 @@ const commonHooks = {
|
|
|
150
152
|
console.log('final cinfig dteials :' + JSON.stringify(capabilities))
|
|
151
153
|
|
|
152
154
|
console.log("config details " + JSON.stringify(config))
|
|
155
|
+
process.env.BROWSERSTACK_USERNAME = config.userName
|
|
156
|
+
process.env.BROWSERSTACK_ACCESS_KEY = config.accessKey
|
|
153
157
|
|
|
154
158
|
|
|
155
159
|
} catch (error) {
|
|
@@ -184,6 +188,7 @@ const commonHooks = {
|
|
|
184
188
|
/* ========== AFTER TEST ========== */
|
|
185
189
|
afterTest: async (test, _, { error, duration, passed }) => {
|
|
186
190
|
console.log(`==== AFTER TEST HOOK ===='${test.title}'`);
|
|
191
|
+
if (!totalTestDuration) totalTestDuration = 0;
|
|
187
192
|
totalTestDuration += duration;
|
|
188
193
|
|
|
189
194
|
const fileName = path.basename(test.file);
|
|
@@ -191,7 +196,8 @@ const commonHooks = {
|
|
|
191
196
|
|
|
192
197
|
if (!passed) {
|
|
193
198
|
resultdetails.comments.push(`${test.title} - ${error?.message || 'Failed'}`);
|
|
194
|
-
}
|
|
199
|
+
}else
|
|
200
|
+
resultdetails.comments.push(`${test.title} - 'Passed'}`);
|
|
195
201
|
|
|
196
202
|
const suiteDetails = JSON.parse(BUFFER.getItem('FROTHE_SUITE_DETAILS'));
|
|
197
203
|
const script = suiteDetails.find(s => s.scriptName === fileName.replace('.js', ''));
|
|
@@ -220,21 +226,7 @@ const commonHooks = {
|
|
|
220
226
|
console.log('==== AFTER SESSION ====');
|
|
221
227
|
// Do not calculate time here; we will use WDIO's total duration in onComplete
|
|
222
228
|
console.log('⏱ Leaving execution time calculation for onComplete hook');
|
|
223
|
-
|
|
224
|
-
// if (!suiteStartTime) suiteStartTime = endTime;
|
|
225
|
-
|
|
226
|
-
// const totalTime = Math.max(endTime - suiteStartTime, totalTestDuration);
|
|
227
|
-
// // resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
|
|
228
|
-
// resultdetails.excution_time = msToTime(totalTime);
|
|
229
|
-
|
|
230
|
-
// console.log('⏱ Final execution time:', resultdetails.excution_time);
|
|
231
|
-
|
|
232
|
-
// console.log('📤 Updating DB with final execution details');
|
|
233
|
-
// console.log('Status:', resultdetails.excution_status);
|
|
234
|
-
// console.log('Duration:', resultdetails.excution_time);
|
|
235
|
-
|
|
236
|
-
// await safeUpdateExecution();
|
|
237
|
-
// BUFFER.clear();
|
|
229
|
+
|
|
238
230
|
},
|
|
239
231
|
|
|
240
232
|
/* ========== ON ERROR ========== */
|
|
@@ -258,34 +250,24 @@ const commonHooks = {
|
|
|
258
250
|
},
|
|
259
251
|
/* ========== ON COMPLETE ========== */
|
|
260
252
|
onComplete: async (exitCode, _, __, results) => {
|
|
261
|
-
console.log('==== ON COMPLETE ====');
|
|
262
253
|
console.log('==== ON COMPLETE ====');
|
|
263
254
|
console.log(`Total: ${results.total || 0}, Passed: ${results.passed || 0}, Failed: ${results.failed || 0}`);
|
|
264
255
|
|
|
265
|
-
|
|
266
|
-
|
|
256
|
+
const endTime = Date.now();
|
|
257
|
+
const totalTime = endTime - suiteStartTime; // Full WDIO+CI elapsed time
|
|
267
258
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
resultdetails.excution_time = msToTime(totalDuration);
|
|
271
|
-
console.log('⏱ Final execution time (ms):', totalDuration);
|
|
272
|
-
console.log('⏱ Final execution time (hh:mm:ss):', resultdetails.excution_time);
|
|
259
|
+
resultdetails.excution_time = await msToTime(totalTime);
|
|
260
|
+
resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
|
|
273
261
|
|
|
274
|
-
// Add generic failure comment if exitCode != 0 and no comments yet
|
|
275
262
|
if (exitCode !== 0 && resultdetails.comments.length === 0) {
|
|
276
263
|
resultdetails.comments.push(`Execution failed with exit code ${exitCode}`);
|
|
277
264
|
}
|
|
278
265
|
|
|
279
|
-
|
|
280
|
-
console.log('
|
|
281
|
-
console.log('Status:', resultdetails.excution_status);
|
|
282
|
-
console.log('Duration:', resultdetails.excution_time);
|
|
283
|
-
console.log('Comments:', resultdetails.comments.join('; '));
|
|
266
|
+
console.log('⏱ Final execution time (ms):', totalTime);
|
|
267
|
+
console.log('⏱ Final execution time (hh:mm:ss):', resultdetails.excution_time);
|
|
284
268
|
|
|
285
269
|
await safeUpdateExecution();
|
|
286
270
|
BUFFER.clear();
|
|
287
|
-
|
|
288
|
-
|
|
289
271
|
return exitCode;
|
|
290
272
|
},
|
|
291
273
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froth-webdriverio-framework",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.76",
|
|
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": {
|