froth-webdriverio-framework 7.0.75 → 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.
- package/froth_configs/commonhook.js +74 -79
- 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,10 +104,7 @@ const commonHooks = {
|
|
|
104
104
|
await setAllDetails.setExecutionDetails();
|
|
105
105
|
await setAllDetails.setSuiteDetails();
|
|
106
106
|
await setAllDetails.setTestDataDetails();
|
|
107
|
-
|
|
108
|
-
capabilities['bstack:options'].uploadMedia = [
|
|
109
|
-
'media://da43e04f8f5e9def566059a8c4138e3ae648f1b8'
|
|
110
|
-
];
|
|
107
|
+
|
|
111
108
|
console.log('✅ All Environment Variables:');
|
|
112
109
|
// for (const [key, value] of Object.entries(process.env)) {
|
|
113
110
|
// console.log(`${key} = ${value}`);
|
|
@@ -138,23 +135,37 @@ const commonHooks = {
|
|
|
138
135
|
|
|
139
136
|
/* ========== BEFORE SESSION ========== */
|
|
140
137
|
beforeSession: async function (config, capabilities, specs) {
|
|
141
|
-
console.log('==== BEFORE SESSION
|
|
142
|
-
|
|
138
|
+
console.log('==== BEFORE SESSION ====');
|
|
143
139
|
try {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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 */
|
|
159
|
+
|
|
160
|
+
await getBrowserStackCapabilities(capabilities)
|
|
161
|
+
console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
|
|
149
162
|
|
|
150
|
-
//
|
|
151
|
-
await setupBrowserStackCapabilities(capabilities);
|
|
163
|
+
// console.log("config details " + JSON.stringify(config))
|
|
152
164
|
|
|
153
|
-
console.log('✅ beforeSession completed successfully');
|
|
154
165
|
|
|
155
166
|
} catch (error) {
|
|
167
|
+
console.error('🚨 Error in beforeSession:', error);
|
|
156
168
|
console.error('🚨 Error in beforeSession:', error.message);
|
|
157
|
-
throw error;
|
|
158
169
|
}
|
|
159
170
|
},
|
|
160
171
|
// beforeSession: async function (config, capabilities, specs) {
|
|
@@ -215,9 +226,6 @@ const commonHooks = {
|
|
|
215
226
|
// }
|
|
216
227
|
// }
|
|
217
228
|
// capabilities['bstack:options'] = bsOpts;
|
|
218
|
-
// /** 🔍 Print final BS options */
|
|
219
|
-
// console.log('🔵 Final bstack:options (After Modification):');
|
|
220
|
-
// console.log(JSON.stringify(capabilities['bstack:options'], null, 2));
|
|
221
229
|
|
|
222
230
|
// }
|
|
223
231
|
// console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
|
|
@@ -396,85 +404,72 @@ async function normalizeWdioError(error) {
|
|
|
396
404
|
return `Automation framework error: ${msg}`;
|
|
397
405
|
}
|
|
398
406
|
|
|
399
|
-
async function
|
|
407
|
+
async function getBrowserStackCapabilities(baseCaps) {
|
|
400
408
|
if (
|
|
401
409
|
process.env.PLATFORM !== 'browserstack' &&
|
|
402
410
|
process.env.PLATFORM !== 'browserstacklocal'
|
|
403
411
|
) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
/* 1️⃣ Print full capabilities */
|
|
407
|
-
console.log('🟡 Full capabilities object:');
|
|
408
|
-
console.log(JSON.stringify(capabilities, null, 2));
|
|
412
|
+
return baseCaps;
|
|
413
|
+
} /** 🔍 Print raw capabilities first */
|
|
409
414
|
|
|
410
|
-
/* 2️⃣ Ensure bstack:options exists */
|
|
411
|
-
if (!capabilities['bstack:options']) {
|
|
412
|
-
capabilities['bstack:options'] = {};
|
|
413
|
-
}
|
|
414
415
|
|
|
415
|
-
|
|
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'] || {};
|
|
416
420
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
console.log(` ${key} : ${JSON.stringify(value)}`);
|
|
421
|
-
});
|
|
421
|
+
/** 🔍 Print existing BS options */
|
|
422
|
+
console.log('🟢 Existing bstack:options (Before Modification):');
|
|
423
|
+
console.log(JSON.stringify(bsOpts, null, 2));
|
|
422
424
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
+
}
|
|
426
430
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
431
|
+
bsOpts.app = appPath;
|
|
432
|
+
capabilities['appium:app'] = appPath;
|
|
433
|
+
console.log('✅ App & media set in before session');
|
|
430
434
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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));
|
|
434
451
|
|
|
435
|
-
|
|
436
|
-
const uploadMediaList = [
|
|
437
|
-
'media://da43e04f8f5e9def566059a8c4138e3ae648f1b8'
|
|
438
|
-
];
|
|
439
|
-
bsOpts.uploadMedia = uploadMediaList;
|
|
440
|
-
capabilities['bstack:options'].uploadMedia = uploadMediaList
|
|
441
|
-
console.log('🟢 bstack:options after amending details:');
|
|
442
|
-
Object.entries(bsOpts).forEach(([key, value]) => {
|
|
443
|
-
console.log(` ${key} : ${JSON.stringify(value)}`);
|
|
444
|
-
});
|
|
445
|
-
/* 5️⃣ Re-assign (important) */
|
|
446
|
-
capabilities['bstack:options'] = bsOpts;
|
|
447
|
-
/* 6️⃣ Print updated bstack:options */
|
|
448
|
-
console.log('🔵 Updated bstack:options after adding uploadMedia:');
|
|
449
|
-
Object.entries(capabilities['bstack:options']).forEach(([key, value]) => {
|
|
450
|
-
console.log(` ${key} : ${JSON.stringify(value)}`);
|
|
452
|
+
return capabilities;
|
|
451
453
|
});
|
|
452
454
|
|
|
453
|
-
/* 7️⃣ Final capabilities print */
|
|
454
|
-
console.log('🟣 Final capabilities sent forward:');
|
|
455
|
-
console.log(JSON.stringify(capabilities, null, 2));
|
|
456
|
-
return capabilities;
|
|
457
|
-
|
|
458
|
-
}
|
|
459
455
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
for (const fileUrl of specs) {
|
|
464
|
-
const filePath = url.fileURLToPath(fileUrl);
|
|
456
|
+
/** Media upload */
|
|
457
|
+
/** 📦 Media upload (from DB → ENV → capabilities) */
|
|
458
|
+
if (process.env.MEDIA_FILES) {
|
|
465
459
|
try {
|
|
466
|
-
|
|
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
|
+
}
|
|
467
466
|
} catch (err) {
|
|
468
|
-
console.
|
|
469
|
-
`❌ Syntax error in ${path.basename(filePath)}: ${err.message}`
|
|
470
|
-
);
|
|
471
|
-
syntaxFailed = true;
|
|
467
|
+
console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
|
|
472
468
|
}
|
|
473
469
|
}
|
|
470
|
+
baseCaps['bstack:options'] = bsOpts;
|
|
471
|
+
|
|
474
472
|
|
|
475
|
-
if (syntaxFailed) {
|
|
476
|
-
throw new Error('Syntax validation failed');
|
|
477
|
-
}
|
|
478
473
|
}
|
|
479
474
|
|
|
480
475
|
module.exports = commonHooks;
|