froth-webdriverio-framework 6.0.59 → 6.0.61

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "6.0.59",
3
+ "version": "6.0.61",
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": {
@@ -1 +0,0 @@
1
- undefined
@@ -1 +0,0 @@
1
- 2472
@@ -1 +0,0 @@
1
- eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzY1MzUzNTY3LCJpYXQiOjE3NjUzNDk5NjcsImp0aSI6IjZhOTQ2MDdkYjU1ZDQ4MDRiYTQ5OTk0NTQwOGJhMDZhIiwidXNlcl9pZCI6MX0.N5zPsGN5PUeiB3DV9bGHDKySdNT6uD_2OX1O4PEho6o
@@ -1 +0,0 @@
1
- 0
@@ -1 +0,0 @@
1
- https://api.frothtestops.com
@@ -1,39 +0,0 @@
1
-
2
- const commonHooks = require('../commonhook');
3
- module.exports = (bsCaps) => ({
4
-
5
- ...commonHooks,
6
- user: bsCaps.userName,
7
- key: Buffer.from(bsCaps.accessKey, 'base64').toString('utf-8'),
8
-
9
- services: [
10
- [
11
- 'browserstack',
12
- {
13
- buildIdentifier: process.env.BUILD_NUMBER || 'local-build',
14
- browserstackLocal: true,
15
- opts: {
16
- forcelocal: true,
17
- localIdentifier: `wdio-${process.pid}`,
18
- },
19
- app: process.env.BROWSERSTACK_APP_PATH,
20
- },
21
- ],
22
- ],
23
-
24
-
25
- capabilities: [{
26
- 'bstack:options': {
27
- projectName: 'BrowserStack Samples',
28
- buildName: 'browserstack build',
29
- sessionName: 'Mobile Test',
30
- deviceName: bsCaps.deviceName || 'Samsung Galaxy S22 Ultra',
31
- osVersion: bsCaps.platformVersion || '12.0',
32
- debug: bsCaps.debug,
33
- networkLogs: bsCaps.networkLogs,
34
- interactiveDebugging: bsCaps.interactiveDebugging
35
- }
36
- }],
37
-
38
- updateJob: false
39
- });
@@ -1,25 +0,0 @@
1
- module.exports = (bsCaps) => ({
2
- user: bsCaps.userName,
3
- key: Buffer.from(bsCaps.accessKey, 'base64').toString('utf-8'),
4
-
5
-
6
- services: [
7
- [
8
- 'browserstack',
9
- {
10
- browserstackLocal: true,
11
- opts: { forcelocal: true }
12
- }
13
- ]
14
- ],
15
-
16
-
17
- capabilities: [{
18
- browserName: process.env.BROWSER || 'chrome',
19
- 'bstack:options': {
20
- os: 'Windows',
21
- osVersion: '11',
22
- buildName: 'BS Web Build'
23
- }
24
- }]
25
- });
@@ -1,410 +0,0 @@
1
- const path = require('path');
2
- const url = require('url');
3
- const fs = require('fs');
4
- const { LocalStorage } = require('node-localstorage');
5
- global.BUFFER = new LocalStorage('./storage');
6
- const setAllDetails = require("./setallDatailinBuffer")
7
- const exeDetails = require("../froth_api_calls/getexecutionDetails")
8
- const getBSSessionDetails = require("../froth_api_calls/browsersatckSessionInfo").getBSSessionDetails;
9
- const { fail } = require("assert");
10
- const { error } = require('console');
11
- global.Util=require('../froth_common_actions/Utils');
12
- //const isBrowserStackEnabled = process.env.BROWSERSTACK;
13
- let starttime;
14
- let endtime;
15
- let duration_tests = 0;
16
- console.log('===== common config===== ');
17
- const resultdetails = {
18
- comments: [],
19
- excution_status: null, // Pass/Fail
20
- excution_time: null, // Execution time in milliseconds
21
- };
22
- // Description: This file contains the common configuration for the webdriverio framework.
23
- const commonconfig = {
24
-
25
- onPrepare: async function (capabilities, specs) {
26
- try {
27
-
28
- console.log('==== ON PREPARE HOOK ====');
29
- // This code runs before the test suite starts
30
- await setAllDetails.setEnvVariables();
31
- await setAllDetails.setExecutionDetails();
32
- await setAllDetails.setSuiteDetails();
33
- await setAllDetails.setTestDataDetails();
34
- console.log("on prepare:", JSON.stringify(capabilities))
35
-
36
- // console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
37
- } catch (e) {
38
- console.log("====> Error in onPrepare:", e);
39
-
40
- }
41
- },
42
-
43
-
44
- beforeSession: async function (config, capabilities, specs) {
45
- try {
46
- let syntaxFailed = false;
47
-
48
- console.log('==== BEFORE SESSION HOOK ====');
49
- // Perform any setup or pre-test actions here
50
- console.log("specdat:", specs);
51
- console.log("length:", specs.length);
52
- //checking the syntax error in the test files
53
- for (const fileUrl of specs) {
54
- const filePath = url.fileURLToPath(fileUrl); // convert file:// URL to file path
55
- try {
56
- const code = fs.readFileSync(filePath, 'utf8');
57
- new Function(code); // Try to compile
58
- } catch (err) {
59
- // Extract line number from stack trace
60
- const match = err.stack.match(/\((.*):(\d+):(\d+)\)/);
61
- const lineInfo = match ? ` at line ${match[2]}, column ${match[3]}` : '';
62
-
63
- const errorMsg = `❌ Syntax error in '${path.basename(filePath)}'${lineInfo}: ${err.message}`;
64
- console.error("🚨", errorMsg);
65
- resultdetails.comments.push(errorMsg);
66
- syntaxFailed = true;
67
- }
68
- }
69
- if (syntaxFailed) {
70
- resultdetails.excution_status = 'FAILED';
71
- await exeDetails.updateExecuitonDetails(
72
- BUFFER.getItem("ORGANISATION_DOMAIN_URL"),
73
- BUFFER.getItem("FROTH_LOGIN_TOKEN"),
74
- BUFFER.getItem("FROTH_EXECUTION_ID"),
75
- resultdetails
76
- );
77
- process.exit(1);
78
- }
79
- // set the capability like media and app and bs local
80
- // if (process.env.PLATFORM === 'browserstack') {
81
- // /// console.log("capabilities:", capabilities);
82
- // capabilities.browserstackLocal = process.env.BROWSERSTACK_LOCAL;
83
- // // capabilities.accessKey = Buffer.from(capabilities.accessKey, 'base64').toString('utf-8');
84
- // if (capabilities.platformName === 'android' || capabilities.platformName === 'ios') {
85
- // capabilities.app = process.env.BROWSERSTACK_APP_PATH;
86
- // if (capabilities.app === undefined || capabilities.app === null || capabilities.app === '') {
87
- // console.error("🚨 Error: BROWSERSTACK_APP_PATH is not defined or empty.");
88
- // resultdetails.excution_status = 'FAILED';
89
- // resultdetails.comments.push("BROWSERSTACK_APP_PATH is not defined or empty.");
90
- // await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails);
91
- // process.exit(1); // Stop execution if app path is not set
92
- // } else {
93
- // console.log("App Path:", capabilities.app);
94
- // console.log("Browserstack Local:", capabilities.browserstackLocal);
95
- // }
96
- // }
97
-
98
- // try {
99
- // let mediaFiles = process.env.MEDIA_FILES ? JSON.parse(process.env.MEDIA_FILES) : [];
100
- // console.log("Size of Media Files:", Array.isArray(mediaFiles) ? mediaFiles.length : "Invalid data");
101
-
102
- // if (Array.isArray(mediaFiles) && mediaFiles.length > 0) {
103
- // console.log("Media Files:", JSON.parse(process.env.MEDIA_FILES));
104
- // capabilities['browserstack.uploadMedia'] = JSON.parse(process.env.MEDIA_FILES);
105
- // }
106
- // } catch (error) {
107
- // console.error("Error parsing MEDIA_FILES:", error);
108
- // }
109
-
110
- // console.log(`Running tests on after app,bslocal,mediafiles: ${JSON.stringify(capabilities)}`);
111
- // }
112
-
113
- } catch (error) {
114
- console.error('🚨 Error in beforeSession:', error);
115
- console.error('🚨 Error in beforeSession:', error.message);
116
- resultdetails.excution_status = 'FAILED';
117
- resultdetails.comments.push("Session creation failed:", error.message);
118
- await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
119
- // throw new Error(`Session creation failed: ${error.message}`);
120
- process.exit(1); // Stop execution if session creation fails
121
-
122
- }
123
-
124
-
125
- },
126
- /**
127
- * Gets executed before the suite starts (in Mocha/Jasmine only).
128
- * @param {object} suite suite details
129
- */
130
- beforeSuite: async function (suite) {
131
- try {
132
- console.log('==== BEFORE SUITE HOOK ====');
133
- console.log(`====> Test suite has been started ' ${suite.title}' `,);
134
-
135
- starttime = new Date().getTime();
136
-
137
- if (process.env.PLATFORM === 'browserstack')
138
- await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_ACCESS_KEY);
139
-
140
-
141
- // const resultdetails = {};
142
- await exeDetails.update_CICDRUNID_ReportUrl(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"))
143
- BUFFER.setItem("UPDATE_EXECUTION", 'FALSE') //i need to recall
144
-
145
- } catch (e) {
146
- console.log("Error in beforeSuite:", e);
147
- }
148
- },
149
-
150
- before: async function (capabilities, specs) {
151
- if (process.env.BS_SESSION_TYPE === 'automate') {
152
- console.log('==== BEFORE HOOK ====')
153
- await browser.maximizeWindow()
154
- }
155
- else {
156
- console.log('==== BEFORE HOOK FOR MOBILE ====');
157
- }
158
-
159
- },
160
-
161
- /**
162
- * Function to be executed before a test (in Mocha/Jasmine only)
163
- * @param {object} test test object
164
- * @param {object} context scope object the test was executed with
165
- */
166
- beforeTest: async function (test, context) {
167
-
168
- console.log('==== BEFORE TEST HOOK ====');
169
- console.log(`====> Test Started '${test.title}'`);
170
-
171
- },
172
-
173
-
174
- /**
175
- * Function to be executed after a test (in Mocha/Jasmine only)
176
- * @param {object} test test object
177
- * @param {object} context scope object the test was executed with
178
- * @param {Error} result.error error object in case the test fails, otherwise `undefined`
179
- * @param {*} result.result return object of test function
180
- * @param {number} result.duration duration of test
181
- * @param {boolean} result.passed true if test has passed, otherwise false
182
- * @param {object} result.retries information about spec related retries, e.g. `{ attempts: 0, limit: 0 }`
183
- */
184
- afterTest: async function (test, context, { error, result, duration, passed, retries }) {
185
- console.log('==== AFTER TEST HOOK ====');
186
- console.log(`====> Test name finished '${test.title}'`);
187
-
188
- const fileName = path.basename(test.file);
189
- console.log('====> Test File Name:', fileName);
190
- // BUFFER.setItem("FROTH_TOTAL_DURATION", Number(BUFFER.getItem("FROTH_TOTAL_DURATION")) + duration)
191
- console.log(`====> Total Duration for this test: ${duration}ms`);
192
- duration_tests += duration;
193
- console.log(`====> Total Duration for all tests: ${duration_tests}ms`);
194
- console.log(`====> Status of test: ${passed}`);
195
-
196
- let scriptresult = "NOT RUN";
197
- // Default assumption: test passed (unless soft assertion failed)
198
- let finalPassed = passed;
199
-
200
- if (passed) {
201
- scriptresult = "PASSED"
202
- resultdetails.comments.push(`${test.title} - passed`);
203
- console.log(`====> resultdetails comments: ${resultdetails.comments}`);
204
- }
205
- else if (!finalPassed || error) {
206
- scriptresult = "FAILED"
207
- console.log(`====> Failed or error while executing the test: ${error ? error.message : "Test failed"}`);
208
- if (!resultdetails.comments.some(comment => typeof comment === 'string' && comment.includes(test.title)))
209
- resultdetails.comments.push(`${test.title} - failed: ${error ? error.message : "Test failed"}`);
210
-
211
- }
212
-
213
- let scriptDetails = BUFFER.getItem("FROTHE_SUITE_DETAILS");
214
- if (typeof scriptDetails === "string") {
215
- scriptDetails = JSON.parse(scriptDetails);
216
- }
217
- const jwtScript = scriptDetails.find(s => s.scriptName === fileName.replace(".js", ""));
218
- console.log("jwtScript:", jwtScript);
219
-
220
- await exeDetails.updateScriptExecutionStatus(
221
- BUFFER.getItem("ORGANISATION_DOMAIN_URL"),
222
- BUFFER.getItem("FROTH_LOGIN_TOKEN"),
223
- jwtScript.scriptId,
224
- jwtScript.platform.toLowerCase(),
225
- scriptresult)
226
-
227
-
228
- },
229
- /**
230
- * Hook that gets executed after the suite has ended (in Mocha/Jasmine only).
231
- * @param {object} suite suite details
232
- */
233
- afterSuite: async function (suite) {
234
- console.log('==== AFTER SUITE HOOK ====');
235
- console.log(`====> Test suite has completed '${suite.title}'`);
236
- },
237
- /**
238
- * Gets executed after all tests are done. You still have access to all global variables from
239
- * the test.
240
- * @param {number} result 0 - test pass, 1 - test fail
241
- * @param {Array.<Object>} capabilities list of capabilities details
242
- * @param {Array.<String>} specs List of spec file paths that ran
243
- */
244
- after: async function (result, config, capabilities, specs) {
245
- console.log('==== AFTER HOOK ====');
246
- console.log('====> All tests are completed.' + result);
247
- BUFFER.setItem("RESULT_DATA", result);
248
- console.log("====> Result data :" + BUFFER.getItem("RESULT_DATA"))
249
- resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
250
- console.log("====> Total Duration taken for the suite:" + BUFFER.getItem("FROTH_TOTAL_DURATION"));
251
- console.log("====> Execution Status from results" + resultdetails.excution_status);
252
- // Capture WebDriver session errors
253
-
254
- if (result !== 0) {
255
- if (resultdetails.comments.length === 0) {
256
- resultdetails.comments.push("❌ WebDriver session failed or timed out.");
257
- }
258
- resultdetails.comments.push(`Execution failed with exit code: ${result}`);
259
-
260
- process.on('uncaughtException', (err) => {
261
- console.error("Uncaught Exception:", err);
262
- resultdetails.comments.push(`Execution failed : ${err}`);
263
- });
264
-
265
- }
266
-
267
- },
268
-
269
- onError: async function (error) {
270
- console.error('==== ON ERROR HOOK ====');
271
- console.error('====> Error occurred:', error.message);
272
- if (error.message.includes('Automate testing time expired')) {
273
- console.log('❌ Global error: Session timed out on BrowserStack.');
274
- resultdetails.excution_status = 'FAILED';
275
- resultdetails.comments.push(`Global error: Session timed out on BrowserStack.Please check ths session: ${result}`);
276
-
277
- await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
278
- process.exit(1); // Stop execution if session timed out
279
- }
280
- },
281
- afterSession: async function (config, capabilities, specs) {
282
- console.log('==== AFTER SESSION HOOK ====');
283
- console.log('====> This is the aftersession hook');
284
- // console.log("Capabilities:", capabilities);
285
- console.log("Specs:", specs);
286
- //console.log("Config:", config);
287
-
288
- process.on('uncaughtException', (err) => {
289
- console.error("Uncaught Exception:", err);
290
- resultdetails.comments.push(`Execution failed with exit code: ${err}`);
291
- });
292
-
293
- // Capture unhandled promise rejections
294
- process.on('unhandledRejection', (reason, promise) => {
295
- console.error("Unhandled Promise Rejection:", reason);
296
- resultdetails.comments.push(`Execution failed with exit code: ${reason}`);
297
- });
298
-
299
- endtime = new Date().getTime();
300
- let totalDuration = endtime - starttime;
301
- console.log("====> Total Duration taken for :" + BUFFER.getItem("FROTH_TOTAL_DURATION"));
302
- console.log("====> Total Duration in after session based on start time and end time:" + totalDuration);
303
- console.log("====> Total Duration in after session based on summing up the test execution times:" + duration_tests);
304
-
305
- resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
306
- const frothDuration = BUFFER.getItem("FROTH_TOTAL_DURATION");
307
-
308
- if (await isInvalidDuration(frothDuration)) {
309
- // console.log("inside froth duration");
310
- if (await isInvalidDuration(duration_tests)) {
311
- console.log("inside froth duration_tests");
312
- resultdetails.excution_time = await millisecondsToTime(totalDuration);
313
- } else {
314
- console.log("inside froth duration_tests comparision");
315
- if (totalDuration > duration_tests)
316
- resultdetails.excution_time = await millisecondsToTime(totalDuration);
317
- else
318
- resultdetails.excution_time = await millisecondsToTime(duration_tests);
319
- }
320
- } else {
321
- console.log("inside froth duration else");
322
- resultdetails.excution_time = await secondsToTime(frothDuration);
323
- }
324
-
325
- console.log("====> Total Duration calculation:" + resultdetails.excution_time);
326
-
327
- await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
328
-
329
- // Perform any cleanup or post-test actions here
330
- BUFFER.clear();
331
- },
332
-
333
- onComplete: async function (exitCode, config, capabilities, results) {
334
- console.log('==== ON COMPLETE HOOK ====');
335
- console.log('====> Results:', results);
336
- console.log('==== Test Results Summary ======');
337
- console.log('Total Tests:', results.total);
338
- console.log('Passed:', results.passed);
339
- console.log('Failed:', results.failed);
340
- console.log('Exit Code:', exitCode);
341
-
342
- console.log('==== ALL TESTS ARE COMPLETED ====');
343
- return exitCode;
344
- }
345
-
346
- };
347
- async function isInvalidDuration(val) {
348
- console.log("val in isValidDuration:" + val);
349
- // Check if the value is null, 0, or undefined
350
- let isValid;
351
- if (typeof val === 'string') {
352
- val = val.trim().toLowerCase();
353
- isValid = val === "null" || val === "0" || val === "undefined";
354
-
355
- } else
356
- isValid = val === null || val === 0 || val === undefined;
357
-
358
- console.log("isValid in isValidDuration:" + isValid);
359
-
360
- return isValid;
361
- }
362
- async function secondsToTime(secs) {
363
- console.log("secs in secondsToTime :" + secs);
364
- let hours = Math.floor(secs / 3600);
365
- let minutes = Math.floor((secs % 3600) / 60);
366
- let seconds = secs % 60;
367
-
368
- // Adding leading zeros if the value is less than 10
369
- if (hours < 10) hours = '0' + hours;
370
- if (minutes < 10) minutes = '0' + minutes;
371
- if (seconds < 10) seconds = '0' + seconds;
372
- console.log("Time:" + hours + ':' + minutes + ':' + seconds);
373
- return hours + ':' + minutes + ':' + seconds;
374
- }
375
- async function millisecondsToTime(ms) {
376
- console.log("ms in millisecondsToTime: " + ms);
377
-
378
- // Ensure input is a number
379
- ms = Number(ms);
380
- if (isNaN(ms)) {
381
- return '00:00:00';
382
- }
383
-
384
- let totalSeconds = Math.floor(ms / 1000);
385
- let hours = Math.floor(totalSeconds / 3600);
386
- let minutes = Math.floor((totalSeconds % 3600) / 60);
387
- let seconds = totalSeconds % 60;
388
-
389
- // Pad with leading zeros
390
- hours = hours < 10 ? '0' + hours : hours;
391
- minutes = minutes < 10 ? '0' + minutes : minutes;
392
- seconds = seconds < 10 ? '0' + seconds : seconds;
393
-
394
- const timeStr = `${hours}:${minutes}:${seconds}`;
395
- console.log("Formatted time:", timeStr);
396
- return timeStr;
397
- }
398
-
399
- async function convertTimetoHHMMSS(time) {
400
- const seconds = Math.floor((time / 1000) % 60);
401
- const minutes = Math.floor((time / (1000 * 60)) % 60);
402
- const hours = Math.floor((time / (1000 * 60 * 60)) % 24);
403
- const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
404
-
405
- console.log("Time:" + hours + ':' + minutes + ':' + seconds);
406
-
407
- return formattedTime;
408
- }
409
-
410
- module.exports = commonconfig;