froth-webdriverio-framework 7.0.67 → 7.0.68
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 +173 -65
- package/package.json +1 -1
|
@@ -134,80 +134,96 @@ const commonHooks = {
|
|
|
134
134
|
|
|
135
135
|
|
|
136
136
|
/* ========== BEFORE SESSION ========== */
|
|
137
|
-
|
|
138
137
|
beforeSession: async function (config, capabilities, specs) {
|
|
139
|
-
console.log('==== BEFORE SESSION ====');
|
|
140
|
-
try {
|
|
141
|
-
/** 1️⃣ Validate test syntax */
|
|
142
|
-
let syntaxFailed = false;
|
|
143
|
-
|
|
144
|
-
for (const fileUrl of specs) {
|
|
145
|
-
const filePath = url.fileURLToPath(fileUrl);
|
|
146
|
-
try {
|
|
147
|
-
new Function(fs.readFileSync(filePath, 'utf8'));
|
|
148
|
-
} catch (err) {
|
|
149
|
-
const msg = `❌ Syntax error in ${path.basename(filePath)}: ${err.message}`;
|
|
150
|
-
console.error(msg);
|
|
151
|
-
resultdetails.comments.push(msg);
|
|
152
|
-
syntaxFailed = true;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (syntaxFailed) {
|
|
157
|
-
await failExecution('Syntax validation failed');
|
|
158
|
-
}
|
|
159
|
-
/** 2️⃣ BrowserStack capability normalization */
|
|
160
|
-
|
|
161
|
-
if (process.env.PLATFORM === 'browserstack' || process.env.PLATFORM === 'browserstacklocal') {
|
|
162
|
-
/** 🔍 Print raw capabilities first */
|
|
163
|
-
console.log('🟡 Raw Capabilities (Before):');
|
|
164
|
-
console.log(JSON.stringify(capabilities, null, 2));
|
|
165
|
-
const bsOpts = capabilities['bstack:options'] || {};
|
|
166
|
-
/** 🔍 Print existing BS options */
|
|
167
|
-
console.log('🟢 Existing bstack:options (Before Modification):');
|
|
168
|
-
console.log(JSON.stringify(bsOpts, null, 2));
|
|
169
|
-
|
|
170
|
-
if (process.env.BS_SESSION_TYPE === 'app-automate') {
|
|
171
|
-
const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
172
|
-
if (!appPath) {
|
|
173
|
-
await failExecution('BROWSERSTACK_APP_PATH is missing');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
bsOpts.app = appPath;
|
|
177
|
-
capabilities['appium:app'] = appPath;
|
|
178
|
-
console.log('✅ App & media set in before session');
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
/** Media upload */
|
|
182
|
-
/** 📦 Media upload (from DB → ENV → capabilities) */
|
|
183
|
-
if (process.env.MEDIA_FILES) {
|
|
184
|
-
try {
|
|
185
|
-
const mediaList = JSON.parse(process.env.MEDIA_FILES);
|
|
186
|
-
console.log("media files are", mediaList)
|
|
187
|
-
if (Array.isArray(mediaList) && mediaList.length > 0) {
|
|
188
|
-
bsOpts.uploadMedia = mediaList;
|
|
189
|
-
console.log('✅ uploadMedia injected:', mediaList);
|
|
190
|
-
}
|
|
191
|
-
} catch (err) {
|
|
192
|
-
console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
capabilities['bstack:options'] = bsOpts;
|
|
196
|
-
/** 🔍 Print final BS options */
|
|
197
|
-
console.log('🔵 Final bstack:options (After Modification):');
|
|
198
|
-
console.log(JSON.stringify(capabilities['bstack:options'], null, 2));
|
|
138
|
+
console.log('==== BEFORE SESSION STARTED ====');
|
|
199
139
|
|
|
200
|
-
|
|
201
|
-
|
|
140
|
+
try {
|
|
141
|
+
/** 1️⃣ Validate syntax */
|
|
142
|
+
await validateTestSyntax(specs);
|
|
202
143
|
|
|
203
|
-
|
|
144
|
+
/** 2️⃣ Setup BrowserStack */
|
|
145
|
+
await setupBrowserStackCapabilities(capabilities);
|
|
204
146
|
|
|
147
|
+
console.log('✅ beforeSession completed successfully');
|
|
205
148
|
|
|
206
149
|
} catch (error) {
|
|
207
|
-
console.error('🚨 Error in beforeSession:', error);
|
|
208
150
|
console.error('🚨 Error in beforeSession:', error.message);
|
|
151
|
+
throw error;
|
|
209
152
|
}
|
|
210
153
|
},
|
|
154
|
+
// beforeSession: async function (config, capabilities, specs) {
|
|
155
|
+
// console.log('==== BEFORE SESSION ====');
|
|
156
|
+
// try {
|
|
157
|
+
// /** 1️⃣ Validate test syntax */
|
|
158
|
+
// let syntaxFailed = false;
|
|
159
|
+
|
|
160
|
+
// for (const fileUrl of specs) {
|
|
161
|
+
// const filePath = url.fileURLToPath(fileUrl);
|
|
162
|
+
// try {
|
|
163
|
+
// new Function(fs.readFileSync(filePath, 'utf8'));
|
|
164
|
+
// } catch (err) {
|
|
165
|
+
// const msg = `❌ Syntax error in ${path.basename(filePath)}: ${err.message}`;
|
|
166
|
+
// console.error(msg);
|
|
167
|
+
// resultdetails.comments.push(msg);
|
|
168
|
+
// syntaxFailed = true;
|
|
169
|
+
// }
|
|
170
|
+
// }
|
|
171
|
+
|
|
172
|
+
// if (syntaxFailed) {
|
|
173
|
+
// await failExecution('Syntax validation failed');
|
|
174
|
+
// }
|
|
175
|
+
// /** 2️⃣ BrowserStack capability normalization */
|
|
176
|
+
|
|
177
|
+
// if (process.env.PLATFORM === 'browserstack' || process.env.PLATFORM === 'browserstacklocal') {
|
|
178
|
+
// /** 🔍 Print raw capabilities first */
|
|
179
|
+
// console.log('🟡 Raw Capabilities (Before):');
|
|
180
|
+
// console.log(JSON.stringify(capabilities, null, 2));
|
|
181
|
+
// const bsOpts = capabilities['bstack:options'] || {};
|
|
182
|
+
// /** 🔍 Print existing BS options */
|
|
183
|
+
// console.log('🟢 Existing bstack:options (Before Modification):');
|
|
184
|
+
// console.log(JSON.stringify(bsOpts, null, 2));
|
|
185
|
+
|
|
186
|
+
// if (process.env.BS_SESSION_TYPE === 'app-automate') {
|
|
187
|
+
// const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
188
|
+
// if (!appPath) {
|
|
189
|
+
// await failExecution('BROWSERSTACK_APP_PATH is missing');
|
|
190
|
+
// }
|
|
191
|
+
|
|
192
|
+
// bsOpts.app = appPath;
|
|
193
|
+
// capabilities['appium:app'] = appPath;
|
|
194
|
+
// console.log('✅ App & media set in before session');
|
|
195
|
+
|
|
196
|
+
// }
|
|
197
|
+
// /** Media upload */
|
|
198
|
+
// /** 📦 Media upload (from DB → ENV → capabilities) */
|
|
199
|
+
// if (process.env.MEDIA_FILES) {
|
|
200
|
+
// try {
|
|
201
|
+
// const mediaList = JSON.parse(process.env.MEDIA_FILES);
|
|
202
|
+
// console.log("media files are", mediaList)
|
|
203
|
+
// if (Array.isArray(mediaList) && mediaList.length > 0) {
|
|
204
|
+
// bsOpts.uploadMedia = mediaList;
|
|
205
|
+
// console.log('✅ uploadMedia injected:', mediaList);
|
|
206
|
+
// }
|
|
207
|
+
// } catch (err) {
|
|
208
|
+
// console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
|
|
209
|
+
// }
|
|
210
|
+
// }
|
|
211
|
+
// capabilities['bstack:options'] = bsOpts;
|
|
212
|
+
// /** 🔍 Print final BS options */
|
|
213
|
+
// console.log('🔵 Final bstack:options (After Modification):');
|
|
214
|
+
// console.log(JSON.stringify(capabilities['bstack:options'], null, 2));
|
|
215
|
+
|
|
216
|
+
// }
|
|
217
|
+
// console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
|
|
218
|
+
|
|
219
|
+
// // console.log("config details " + JSON.stringify(config))
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
// } catch (error) {
|
|
223
|
+
// console.error('🚨 Error in beforeSession:', error);
|
|
224
|
+
// console.error('🚨 Error in beforeSession:', error.message);
|
|
225
|
+
// }
|
|
226
|
+
// },
|
|
211
227
|
/* ========== BEFORE SUITE ========== */
|
|
212
228
|
beforeSuite: async (suite) => {
|
|
213
229
|
console.log(`==== BEFORE SUITE: ${suite.title} ====`);
|
|
@@ -374,5 +390,97 @@ async function normalizeWdioError(error) {
|
|
|
374
390
|
return `Automation framework error: ${msg}`;
|
|
375
391
|
}
|
|
376
392
|
|
|
393
|
+
async function setupBrowserStackCapabilities(capabilities) {
|
|
394
|
+
if (
|
|
395
|
+
process.env.PLATFORM !== 'browserstack' &&
|
|
396
|
+
process.env.PLATFORM !== 'browserstacklocal'
|
|
397
|
+
) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const bsOpts = capabilities['bstack:options'] || {};
|
|
402
|
+
|
|
403
|
+
/** 🔹 Build metadata */
|
|
404
|
+
bsOpts.buildIdentifier =
|
|
405
|
+
process.env.BROWSERSTACK_BUILD_NAME || 'local-build';
|
|
406
|
+
|
|
407
|
+
bsOpts.buildName =
|
|
408
|
+
process.env.BROWSERSTACK_BUILD_DISPLAY_NAME ||
|
|
409
|
+
bsOpts.buildName
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
bsOpts.projectName = bsOpts.projectName || 'BrowserStack Samples';
|
|
413
|
+
|
|
414
|
+
bsOpts.sessionName =
|
|
415
|
+
process.env.BROWSERSTACK_SESSION_NAME ||
|
|
416
|
+
'BStack WDIO Appium Session';
|
|
417
|
+
|
|
418
|
+
/** 🔹 Device consistency */
|
|
419
|
+
bsOpts.deviceName = bsOpts.deviceName || capabilities.deviceName;
|
|
420
|
+
bsOpts.osVersion = bsOpts.osVersion || capabilities.osVersion;
|
|
421
|
+
|
|
422
|
+
/** 🔹 Logs */
|
|
423
|
+
bsOpts.debug = bsOpts.debug ?? true;
|
|
424
|
+
bsOpts.networkLogs = bsOpts.networkLogs ?? false;
|
|
425
|
+
|
|
426
|
+
/** 🔹 Local testing */
|
|
427
|
+
if (process.env.PLATFORM === 'browserstacklocal') {
|
|
428
|
+
bsOpts.local = true;
|
|
429
|
+
bsOpts.localIdentifier =
|
|
430
|
+
process.env.BROWSERSTACK_LOCAL_IDENTIFIER ||
|
|
431
|
+
`wdio-${process.pid}`;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** 🔹 App Automate */
|
|
435
|
+
if (process.env.BS_SESSION_TYPE === 'app-automate') {
|
|
436
|
+
const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
437
|
+
|
|
438
|
+
if (!appPath) {
|
|
439
|
+
throw new Error('❌ BROWSERSTACK_APP_PATH is missing');
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
bsOpts.app = appPath;
|
|
443
|
+
capabilities['appium:app'] = appPath;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** 🔹 Media upload */
|
|
447
|
+
if (process.env.MEDIA_FILES) {
|
|
448
|
+
try {
|
|
449
|
+
const mediaList = JSON.parse(process.env.MEDIA_FILES);
|
|
450
|
+
if (Array.isArray(mediaList) && mediaList.length > 0) {
|
|
451
|
+
bsOpts.uploadMedia = mediaList;
|
|
452
|
+
}
|
|
453
|
+
} catch (err) {
|
|
454
|
+
console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** 🔹 Re-assign */
|
|
459
|
+
capabilities['bstack:options'] = bsOpts;
|
|
460
|
+
|
|
461
|
+
/** 🔹 Final BS log */
|
|
462
|
+
console.log('🚀 BrowserStack final options:');
|
|
463
|
+
console.log(JSON.stringify(bsOpts, null, 2));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async function validateTestSyntax(specs) {
|
|
467
|
+
let syntaxFailed = false;
|
|
468
|
+
|
|
469
|
+
for (const fileUrl of specs) {
|
|
470
|
+
const filePath = url.fileURLToPath(fileUrl);
|
|
471
|
+
try {
|
|
472
|
+
new Function(fs.readFileSync(filePath, 'utf8'));
|
|
473
|
+
} catch (err) {
|
|
474
|
+
console.error(
|
|
475
|
+
`❌ Syntax error in ${path.basename(filePath)}: ${err.message}`
|
|
476
|
+
);
|
|
477
|
+
syntaxFailed = true;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (syntaxFailed) {
|
|
482
|
+
throw new Error('Syntax validation failed');
|
|
483
|
+
}
|
|
484
|
+
}
|
|
377
485
|
|
|
378
486
|
module.exports = commonHooks;
|