froth-webdriverio-framework 7.0.76 → 7.0.78
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/froth_configs/commonhook.js +67 -102
- package/package.json +1 -1
|
@@ -93,7 +93,7 @@ async function pushComment(msg) {
|
|
|
93
93
|
const commonHooks = {
|
|
94
94
|
|
|
95
95
|
/* ========== ON PREPARE ========== */
|
|
96
|
-
onPrepare: async (config
|
|
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
|
|
164
|
-
|
|
138
|
+
console.log('==== BEFORE SESSION ====');
|
|
165
139
|
try {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
173
|
-
|
|
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,64 @@ async function normalizeWdioError(error) {
|
|
|
418
404
|
return `Automation framework error: ${msg}`;
|
|
419
405
|
}
|
|
420
406
|
|
|
421
|
-
async function
|
|
407
|
+
async function getBrowserStackCapabilities(baseCaps) {
|
|
422
408
|
if (
|
|
423
409
|
process.env.PLATFORM !== 'browserstack' &&
|
|
424
410
|
process.env.PLATFORM !== 'browserstacklocal'
|
|
425
411
|
) {
|
|
426
|
-
return;
|
|
412
|
+
return baseCaps;
|
|
427
413
|
}
|
|
428
|
-
/* 1️⃣ Print full capabilities */
|
|
429
|
-
console.log('🟡 Full capabilities object:');
|
|
430
|
-
console.log(JSON.stringify(capabilities, null, 2));
|
|
431
414
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
capabilities['bstack:options'] = {};
|
|
435
|
-
}
|
|
415
|
+
console.log('🟡 Raw Capabilities (Before):');
|
|
416
|
+
console.log(JSON.stringify(baseCaps, null, 2));
|
|
436
417
|
|
|
437
|
-
|
|
418
|
+
// ✅ Normalize to array
|
|
419
|
+
const isArray = Array.isArray(baseCaps);
|
|
420
|
+
const capsArray = isArray ? baseCaps : [baseCaps];
|
|
438
421
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
console.log(` ${key} : ${JSON.stringify(value)}`);
|
|
443
|
-
});
|
|
422
|
+
const updatedCaps = await Promise.all(
|
|
423
|
+
capsArray.map(async (capabilities) => {
|
|
424
|
+
const bsOpts = capabilities['bstack:options'] || {};
|
|
444
425
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
426
|
+
console.log('🟢 Existing bstack:options (Before Modification):');
|
|
427
|
+
console.log(JSON.stringify(bsOpts, null, 2));
|
|
448
428
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
429
|
+
if (process.env.BS_SESSION_TYPE === 'app-automate') {
|
|
430
|
+
const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
431
|
+
if (!appPath) {
|
|
432
|
+
await failExecution('BROWSERSTACK_APP_PATH is missing');
|
|
433
|
+
}
|
|
452
434
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
435
|
+
bsOpts.app = appPath;
|
|
436
|
+
capabilities['appium:app'] = appPath;
|
|
437
|
+
}
|
|
456
438
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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)}`);
|
|
473
|
-
});
|
|
439
|
+
bsOpts.deviceName = 'Samsung Galaxy S22 Ultra';
|
|
440
|
+
bsOpts.osVersion = '12.0';
|
|
441
|
+
bsOpts.networkLogs = false;
|
|
442
|
+
bsOpts.debug = false;
|
|
474
443
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
444
|
+
// ⚠️ NEVER assign env vars like this inside code
|
|
445
|
+
// process.env.BS_UPLOAD_MEDIA = "..."
|
|
446
|
+
process.env.BS_UPLOAD_MEDIA = "media://8440f686585de9b46e1c966ce764703836f918bc,media://2952ee7b9b7f0751624b0d4208d7c00b56d4e49b"
|
|
447
|
+
if (process.env.BS_UPLOAD_MEDIA) {
|
|
448
|
+
bsOpts.uploadMedia = process.env.BS_UPLOAD_MEDIA
|
|
449
|
+
.split(',')
|
|
450
|
+
.map(x => x.trim());
|
|
451
|
+
}
|
|
479
452
|
|
|
480
|
-
|
|
453
|
+
capabilities['bstack:options'] = bsOpts;
|
|
481
454
|
|
|
482
|
-
|
|
483
|
-
|
|
455
|
+
console.log('🟢 Existing bstack:options (After Modification):');
|
|
456
|
+
console.log(JSON.stringify(bsOpts, null, 2));
|
|
484
457
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
new Function(fs.readFileSync(filePath, 'utf8'));
|
|
489
|
-
} catch (err) {
|
|
490
|
-
console.error(
|
|
491
|
-
`❌ Syntax error in ${path.basename(filePath)}: ${err.message}`
|
|
492
|
-
);
|
|
493
|
-
syntaxFailed = true;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
458
|
+
return capabilities;
|
|
459
|
+
})
|
|
460
|
+
);
|
|
496
461
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
462
|
+
// ✅ Return in original shape
|
|
463
|
+
return isArray ? updatedCaps : updatedCaps[0];
|
|
500
464
|
}
|
|
501
465
|
|
|
466
|
+
|
|
502
467
|
module.exports = commonHooks;
|