froth-webdriverio-framework 7.0.76 → 7.0.77

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.
@@ -93,7 +93,7 @@ async function pushComment(msg) {
93
93
  const commonHooks = {
94
94
 
95
95
  /* ========== ON PREPARE ========== */
96
- onPrepare: async (config, capabilities) => {
96
+ onPrepare: async (config) => {
97
97
 
98
98
  suiteStartTime = Date.now();
99
99
  registerGlobalErrorHandlers();
@@ -104,32 +104,7 @@ const commonHooks = {
104
104
  await setAllDetails.setExecutionDetails();
105
105
  await setAllDetails.setSuiteDetails();
106
106
  await setAllDetails.setTestDataDetails();
107
- /* 1️⃣ Print full capabilities */
108
- console.log('🟡 Full capabilities object:');
109
- console.log(JSON.stringify(capabilities, null, 2));
110
107
 
111
- /* 2️⃣ Ensure bstack:options exists */
112
- if (!capabilities['bstack:options']) {
113
- capabilities['bstack:options'] = {};
114
- }
115
-
116
- let bsOpts = capabilities['bstack:options'];
117
-
118
- /* 3️⃣ Print bstack:options as key–value pairs */
119
- console.log('🟢 bstack:options details:');
120
- Object.entries(bsOpts).forEach(([key, value]) => {
121
- console.log(` ${key} : ${JSON.stringify(value)}`);
122
- });
123
- /** 2️⃣ Setup BrowserStack */
124
- capabilities['bstack:options'].uploadMedia = [
125
- 'media://da43e04f8f5e9def566059a8c4138e3ae648f1b8'
126
- ];
127
- console.log('🟢 bstack:options after amending details:');
128
- Object.entries(bsOpts).forEach(([key, value]) => {
129
- console.log(` ${key} : ${JSON.stringify(value)}`);
130
- });
131
- /* 5️⃣ Re-assign (important) */
132
- capabilities['bstack:options'] = bsOpts;
133
108
  console.log('✅ All Environment Variables:');
134
109
  // for (const [key, value] of Object.entries(process.env)) {
135
110
  // console.log(`${key} = ${value}`);
@@ -160,23 +135,37 @@ const commonHooks = {
160
135
 
161
136
  /* ========== BEFORE SESSION ========== */
162
137
  beforeSession: async function (config, capabilities, specs) {
163
- console.log('==== BEFORE SESSION STARTED ====');
164
-
138
+ console.log('==== BEFORE SESSION ====');
165
139
  try {
166
- /* 1️⃣ Print full capabilities */
167
- console.log('🟡 Full capabilities object:');
168
- console.log(JSON.stringify(capabilities, null, 2));
169
- /** 1️⃣ Validate syntax */
170
- await validateTestSyntax(specs);
140
+ /** 1️⃣ Validate test syntax */
141
+ let syntaxFailed = false;
142
+
143
+ for (const fileUrl of specs) {
144
+ const filePath = url.fileURLToPath(fileUrl);
145
+ try {
146
+ new Function(fs.readFileSync(filePath, 'utf8'));
147
+ } catch (err) {
148
+ const msg = `❌ Syntax error in ${path.basename(filePath)}: ${err.message}`;
149
+ console.error(msg);
150
+ resultdetails.comments.push(msg);
151
+ syntaxFailed = true;
152
+ }
153
+ }
154
+
155
+ if (syntaxFailed) {
156
+ await failExecution('Syntax validation failed');
157
+ }
158
+ /** 2️⃣ BrowserStack capability normalization */
171
159
 
172
- // /** 2️⃣ Setup BrowserStack */
173
- await setupBrowserStackCapabilities(capabilities);
160
+ await getBrowserStackCapabilities(capabilities)
161
+ console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
162
+
163
+ // console.log("config details " + JSON.stringify(config))
174
164
 
175
- console.log('✅ beforeSession completed successfully');
176
165
 
177
166
  } catch (error) {
167
+ console.error('🚨 Error in beforeSession:', error);
178
168
  console.error('🚨 Error in beforeSession:', error.message);
179
- throw error;
180
169
  }
181
170
  },
182
171
  // beforeSession: async function (config, capabilities, specs) {
@@ -237,9 +226,6 @@ const commonHooks = {
237
226
  // }
238
227
  // }
239
228
  // capabilities['bstack:options'] = bsOpts;
240
- // /** 🔍 Print final BS options */
241
- // console.log('🔵 Final bstack:options (After Modification):');
242
- // console.log(JSON.stringify(capabilities['bstack:options'], null, 2));
243
229
 
244
230
  // }
245
231
  // console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
@@ -418,85 +404,72 @@ async function normalizeWdioError(error) {
418
404
  return `Automation framework error: ${msg}`;
419
405
  }
420
406
 
421
- async function setupBrowserStackCapabilities(capabilities) {
407
+ async function getBrowserStackCapabilities(baseCaps) {
422
408
  if (
423
409
  process.env.PLATFORM !== 'browserstack' &&
424
410
  process.env.PLATFORM !== 'browserstacklocal'
425
411
  ) {
426
- return;
427
- }
428
- /* 1️⃣ Print full capabilities */
429
- console.log('🟡 Full capabilities object:');
430
- console.log(JSON.stringify(capabilities, null, 2));
412
+ return baseCaps;
413
+ } /** 🔍 Print raw capabilities first */
431
414
 
432
- /* 2️⃣ Ensure bstack:options exists */
433
- if (!capabilities['bstack:options']) {
434
- capabilities['bstack:options'] = {};
435
- }
436
415
 
437
- let bsOpts = capabilities['bstack:options'];
416
+ console.log('🟡 Raw Capabilities (Before):');
417
+ console.log(JSON.stringify(baseCaps, null, 2));
418
+ return baseCaps.map(async (capabilities) => {
419
+ const bsOpts = capabilities['bstack:options'] || {};
438
420
 
439
- /* 3️⃣ Print bstack:options as key–value pairs */
440
- console.log('🟢 bstack:options details:');
441
- Object.entries(bsOpts).forEach(([key, value]) => {
442
- console.log(` ${key} : ${JSON.stringify(value)}`);
443
- });
421
+ /** 🔍 Print existing BS options */
422
+ console.log('🟢 Existing bstack:options (Before Modification):');
423
+ console.log(JSON.stringify(bsOpts, null, 2));
444
424
 
445
- /** 🔹 App Automate */
446
- if (process.env.BS_SESSION_TYPE === 'app-automate') {
447
- const appPath = process.env.BROWSERSTACK_APP_PATH;
425
+ if (process.env.BS_SESSION_TYPE === 'app-automate') {
426
+ const appPath = process.env.BROWSERSTACK_APP_PATH;
427
+ if (!appPath) {
428
+ await failExecution('BROWSERSTACK_APP_PATH is missing');
429
+ }
448
430
 
449
- if (!appPath) {
450
- throw new Error(' BROWSERSTACK_APP_PATH is missing');
451
- }
431
+ bsOpts.app = appPath;
432
+ capabilities['appium:app'] = appPath;
433
+ console.log('✅ App & media set in before session');
452
434
 
453
- //bsOpts.app = appPath;
454
- capabilities['appium:app'] = appPath;
455
- }
435
+ }
436
+ bsOpts.deviceName = "Samsung Galaxy S22 Ultra";
437
+ bsOpts.osVersion = "12.0"
438
+ bsOpts.networkLogs = 'false';
439
+ bsOpts.debug = 'false';
440
+ process.env.BS_UPLOAD_MEDIA="media://8440f686585de9b46e1c966ce764703836f918bc,media://2952ee7b9b7f0751624b0d4208d7c00b56d4e49b"
441
+
442
+ if (process.env.BS_UPLOAD_MEDIA) {
443
+ bsOpts.uploadMedia = process.env.BS_UPLOAD_MEDIA
444
+ .split(',')
445
+ .map(x => x.trim());
446
+ }
447
+ capabilities['bstack:options'] = bsOpts;
448
+ /** 🔍 Print existing BS options */
449
+ console.log('🟢 Existing bstack:options (Before Modification):');
450
+ console.log(JSON.stringify(bsOpts, null, 2));
456
451
 
457
- /* 4️⃣ Amend / add uploadMedia */
458
- // const uploadMediaList = [
459
- // 'media://da43e04f8f5e9def566059a8c4138e3ae648f1b8'
460
- // ];
461
- // bsOpts.uploadMedia = uploadMediaList;
462
- // capabilities['bstack:options'].uploadMedia = uploadMediaList
463
- // console.log('🟢 bstack:options after amending details:');
464
- // Object.entries(bsOpts).forEach(([key, value]) => {
465
- // console.log(` ${key} : ${JSON.stringify(value)}`);
466
- // });
467
- // /* 5️⃣ Re-assign (important) */
468
- // capabilities['bstack:options'] = bsOpts;
469
- /* 6️⃣ Print updated bstack:options */
470
- console.log('🔵 Updated bstack:options after adding uploadMedia:');
471
- Object.entries(capabilities['bstack:options']).forEach(([key, value]) => {
472
- console.log(` ${key} : ${JSON.stringify(value)}`);
452
+ return capabilities;
473
453
  });
474
454
 
475
- /* 7️⃣ Final capabilities print */
476
- console.log('🟣 Final capabilities sent forward:');
477
- console.log(JSON.stringify(capabilities, null, 2));
478
- return capabilities;
479
-
480
- }
481
-
482
- async function validateTestSyntax(specs) {
483
- let syntaxFailed = false;
484
455
 
485
- for (const fileUrl of specs) {
486
- const filePath = url.fileURLToPath(fileUrl);
456
+ /** Media upload */
457
+ /** 📦 Media upload (from DB → ENV → capabilities) */
458
+ if (process.env.MEDIA_FILES) {
487
459
  try {
488
- new Function(fs.readFileSync(filePath, 'utf8'));
460
+ const mediaList = JSON.parse(process.env.MEDIA_FILES);
461
+ console.log("media files are", mediaList)
462
+ if (Array.isArray(mediaList) && mediaList.length > 0) {
463
+ bsOpts.uploadMedia = mediaList;
464
+ console.log('✅ uploadMedia injected:', mediaList);
465
+ }
489
466
  } catch (err) {
490
- console.error(
491
- `❌ Syntax error in ${path.basename(filePath)}: ${err.message}`
492
- );
493
- syntaxFailed = true;
467
+ console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
494
468
  }
495
469
  }
470
+ baseCaps['bstack:options'] = bsOpts;
471
+
496
472
 
497
- if (syntaxFailed) {
498
- throw new Error('Syntax validation failed');
499
- }
500
473
  }
501
474
 
502
475
  module.exports = commonHooks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "7.0.76",
3
+ "version": "7.0.77",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",