froth-webdriverio-framework 7.0.84 → 7.0.85
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 +60 -73
- package/froth_configs/wdio.common.conf.js +11 -107
- package/package.json +1 -1
|
@@ -130,10 +130,10 @@ const commonHooks = {
|
|
|
130
130
|
|
|
131
131
|
await safeUpdateExecution();
|
|
132
132
|
},
|
|
133
|
-
/* ========== ON ERROR ========== */
|
|
134
133
|
|
|
135
134
|
|
|
136
135
|
/* ========== BEFORE SESSION ========== */
|
|
136
|
+
|
|
137
137
|
beforeSession: async function (config, capabilities, specs) {
|
|
138
138
|
console.log('==== BEFORE SESSION ====');
|
|
139
139
|
try {
|
|
@@ -157,7 +157,65 @@ const commonHooks = {
|
|
|
157
157
|
}
|
|
158
158
|
/** 2️⃣ BrowserStack capability normalization */
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
if (process.env.PLATFORM === 'browserstack' || process.env.PLATFORM === 'browserstacklocal') {
|
|
161
|
+
/** 🔍 Print raw capabilities first */
|
|
162
|
+
console.log('🟡 Raw Capabilities (Before):');
|
|
163
|
+
console.log(JSON.stringify(capabilities, null, 2));
|
|
164
|
+
const bsOpts = capabilities['bstack:options'] || {};
|
|
165
|
+
/** 🔍 Print existing BS options */
|
|
166
|
+
console.log('🟢 Existing bstack:options (Before Modification):');
|
|
167
|
+
console.log(JSON.stringify(bsOpts, null, 2));
|
|
168
|
+
|
|
169
|
+
if (process.env.BS_SESSION_TYPE === 'app-automate') {
|
|
170
|
+
const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
171
|
+
if (!appPath) {
|
|
172
|
+
await failExecution('BROWSERSTACK_APP_PATH is missing');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
bsOpts.app = appPath;
|
|
176
|
+
capabilities['appium:app'] = appPath;
|
|
177
|
+
console.log('✅ App & media set in before session');
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
// Ensure bstack:options exists
|
|
181
|
+
if (!capabilities['bstack:options']) {
|
|
182
|
+
capabilities['bstack:options'] = {};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const bstackOptions = capabilities['bstack:options'];
|
|
186
|
+
|
|
187
|
+
// Example: list of media IDs you want to inject
|
|
188
|
+
// Replace <MEDIA_ID_1>, <MEDIA_ID_2> with your actual BrowserStack media IDs
|
|
189
|
+
const mediaFiles = [
|
|
190
|
+
'media://8440f686585de9b46e1c966ce764703836f918bc',
|
|
191
|
+
'media://2952ee7b9b7f0751624b0d4208d7c00b56d4e49b',
|
|
192
|
+
// Add more if needed
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
// Inject media into capabilities
|
|
196
|
+
bstackOptions.uploadMedia = mediaFiles;
|
|
197
|
+
|
|
198
|
+
console.log('Injected BrowserStack media before session:', bstackOptions.uploadMedia);
|
|
199
|
+
|
|
200
|
+
// Always return capabilities (optional in WDIO, but safe)
|
|
201
|
+
return capabilities;
|
|
202
|
+
/** Media upload */
|
|
203
|
+
/** 📦 Media upload (from DB → ENV → capabilities) */
|
|
204
|
+
// if (process.env.MEDIA_FILES) {
|
|
205
|
+
// try {
|
|
206
|
+
// const mediaList = JSON.parse(process.env.MEDIA_FILES);
|
|
207
|
+
// console.log("media files are", mediaList)
|
|
208
|
+
// if (Array.isArray(mediaList) && mediaList.length > 0) {
|
|
209
|
+
// bsOpts.uploadMedia = mediaList;
|
|
210
|
+
// console.log('✅ uploadMedia injected:', mediaList);
|
|
211
|
+
// }
|
|
212
|
+
// } catch (err) {
|
|
213
|
+
// console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
|
|
214
|
+
// }
|
|
215
|
+
// }
|
|
216
|
+
// capabilities['bstack:options'] = bsOpts;
|
|
217
|
+
|
|
218
|
+
}
|
|
161
219
|
console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
|
|
162
220
|
|
|
163
221
|
// console.log("config details " + JSON.stringify(config))
|
|
@@ -168,76 +226,6 @@ const commonHooks = {
|
|
|
168
226
|
console.error('🚨 Error in beforeSession:', error.message);
|
|
169
227
|
}
|
|
170
228
|
},
|
|
171
|
-
// beforeSession: async function (config, capabilities, specs) {
|
|
172
|
-
// console.log('==== BEFORE SESSION ====');
|
|
173
|
-
// try {
|
|
174
|
-
// /** 1️⃣ Validate test syntax */
|
|
175
|
-
// let syntaxFailed = false;
|
|
176
|
-
|
|
177
|
-
// for (const fileUrl of specs) {
|
|
178
|
-
// const filePath = url.fileURLToPath(fileUrl);
|
|
179
|
-
// try {
|
|
180
|
-
// new Function(fs.readFileSync(filePath, 'utf8'));
|
|
181
|
-
// } catch (err) {
|
|
182
|
-
// const msg = `❌ Syntax error in ${path.basename(filePath)}: ${err.message}`;
|
|
183
|
-
// console.error(msg);
|
|
184
|
-
// resultdetails.comments.push(msg);
|
|
185
|
-
// syntaxFailed = true;
|
|
186
|
-
// }
|
|
187
|
-
// }
|
|
188
|
-
|
|
189
|
-
// if (syntaxFailed) {
|
|
190
|
-
// await failExecution('Syntax validation failed');
|
|
191
|
-
// }
|
|
192
|
-
// /** 2️⃣ BrowserStack capability normalization */
|
|
193
|
-
|
|
194
|
-
// if (process.env.PLATFORM === 'browserstack' || process.env.PLATFORM === 'browserstacklocal') {
|
|
195
|
-
// /** 🔍 Print raw capabilities first */
|
|
196
|
-
// console.log('🟡 Raw Capabilities (Before):');
|
|
197
|
-
// console.log(JSON.stringify(capabilities, null, 2));
|
|
198
|
-
// const bsOpts = capabilities['bstack:options'] || {};
|
|
199
|
-
// /** 🔍 Print existing BS options */
|
|
200
|
-
// console.log('🟢 Existing bstack:options (Before Modification):');
|
|
201
|
-
// console.log(JSON.stringify(bsOpts, null, 2));
|
|
202
|
-
|
|
203
|
-
// if (process.env.BS_SESSION_TYPE === 'app-automate') {
|
|
204
|
-
// const appPath = process.env.BROWSERSTACK_APP_PATH;
|
|
205
|
-
// if (!appPath) {
|
|
206
|
-
// await failExecution('BROWSERSTACK_APP_PATH is missing');
|
|
207
|
-
// }
|
|
208
|
-
|
|
209
|
-
// bsOpts.app = appPath;
|
|
210
|
-
// capabilities['appium:app'] = appPath;
|
|
211
|
-
// console.log('✅ App & media set in before session');
|
|
212
|
-
|
|
213
|
-
// }
|
|
214
|
-
// /** Media upload */
|
|
215
|
-
// /** 📦 Media upload (from DB → ENV → capabilities) */
|
|
216
|
-
// if (process.env.MEDIA_FILES) {
|
|
217
|
-
// try {
|
|
218
|
-
// const mediaList = JSON.parse(process.env.MEDIA_FILES);
|
|
219
|
-
// console.log("media files are", mediaList)
|
|
220
|
-
// if (Array.isArray(mediaList) && mediaList.length > 0) {
|
|
221
|
-
// bsOpts.uploadMedia = mediaList;
|
|
222
|
-
// console.log('✅ uploadMedia injected:', mediaList);
|
|
223
|
-
// }
|
|
224
|
-
// } catch (err) {
|
|
225
|
-
// console.warn('⚠️ MEDIA_FILES is not valid JSON', err);
|
|
226
|
-
// }
|
|
227
|
-
// }
|
|
228
|
-
// capabilities['bstack:options'] = bsOpts;
|
|
229
|
-
|
|
230
|
-
// }
|
|
231
|
-
// console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
|
|
232
|
-
|
|
233
|
-
// // console.log("config details " + JSON.stringify(config))
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// } catch (error) {
|
|
237
|
-
// console.error('🚨 Error in beforeSession:', error);
|
|
238
|
-
// console.error('🚨 Error in beforeSession:', error.message);
|
|
239
|
-
// }
|
|
240
|
-
// },
|
|
241
229
|
/* ========== BEFORE SUITE ========== */
|
|
242
230
|
beforeSuite: async (suite) => {
|
|
243
231
|
console.log(`==== BEFORE SUITE: ${suite.title} ====`);
|
|
@@ -405,5 +393,4 @@ async function normalizeWdioError(error) {
|
|
|
405
393
|
}
|
|
406
394
|
|
|
407
395
|
|
|
408
|
-
|
|
409
396
|
module.exports = commonHooks;
|
|
@@ -21,7 +21,6 @@ try {
|
|
|
21
21
|
process.env.BROWSERSTACK_USERNAME = bsCaps.userName
|
|
22
22
|
process.env.BROWSERSTACK_ACCESS_KEY = Buffer.from(bsCaps.accessKey, 'base64').toString('utf-8')
|
|
23
23
|
// Merge chrome-specific options if applicable
|
|
24
|
-
//await setAllDetails.setExecutionDetails()
|
|
25
24
|
|
|
26
25
|
} catch (e) {
|
|
27
26
|
console.error('❌ Failed to load capability YAML:', err.message);
|
|
@@ -47,117 +46,22 @@ console.log('====> PLATFORM NAME :', platformName);
|
|
|
47
46
|
console.log('====> BS SESSION TYPE :', process.env.BS_SESSION_TYPE);
|
|
48
47
|
|
|
49
48
|
|
|
49
|
+
|
|
50
50
|
// --------------------
|
|
51
|
-
// Load
|
|
51
|
+
// Load env-specific config
|
|
52
52
|
// --------------------
|
|
53
|
-
let envConfigFn;
|
|
54
53
|
if (PLATFORM === 'browserstack' || PLATFORM === 'browserstacklocal') {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
envConfig =
|
|
55
|
+
OS === 'web'
|
|
56
|
+
? require('./browserstack/web.config')
|
|
57
|
+
: require('./browserstack/mobile.config');
|
|
58
58
|
} else {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// --------------------
|
|
65
|
-
// Function to inject BrowserStack media files into capabilities
|
|
66
|
-
// --------------------
|
|
67
|
-
function getBrowserStackCapabilities(baseCaps) {
|
|
68
|
-
if (!baseCaps) return baseCaps;
|
|
69
|
-
|
|
70
|
-
const isArray = Array.isArray(baseCaps);
|
|
71
|
-
const capsArray = isArray ? baseCaps : [baseCaps];
|
|
72
|
-
|
|
73
|
-
const updatedCaps = capsArray.map((capability) => {
|
|
74
|
-
capability['bstack:options'] = capability['bstack:options'] || {};
|
|
75
|
-
const bsOpts = capability['bstack:options'];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// ✅ Inject media from ENV variable
|
|
80
|
-
const bsMediaEnv = process.env.MEDIA_FILES;
|
|
81
|
-
if (bsMediaEnv) {
|
|
82
|
-
try {
|
|
83
|
-
const mediaFiles = JSON.parse(bsMediaEnv);
|
|
84
|
-
if (Array.isArray(mediaFiles)) {
|
|
85
|
-
bsOpts.uploadMedia = mediaFiles;
|
|
86
|
-
console.log('🟢 Uploading media files from ENV:', bsOpts.uploadMedia);
|
|
87
|
-
}
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error('❌ Failed to parse BS_UPLOAD_MEDIA env variable:', err.message);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
capability['bstack:options'] = bsOpts;
|
|
94
|
-
return capability;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return isArray ? updatedCaps : updatedCaps[0];
|
|
59
|
+
envConfig =
|
|
60
|
+
OS === 'web'
|
|
61
|
+
? require('./local/web.config')
|
|
62
|
+
: require('./local/mobile.config');
|
|
98
63
|
}
|
|
99
64
|
|
|
100
|
-
// --------------------
|
|
101
|
-
// Export WDIO config as async promise (WDIO supports this)
|
|
102
|
-
// --------------------
|
|
103
|
-
exports.config = (async () => {
|
|
104
|
-
// Await your async setup
|
|
105
|
-
await setAllDetails.setExecutionDetails();
|
|
106
|
-
|
|
107
|
-
// Get environment-specific config object
|
|
108
|
-
const envConfigObj = envConfigFn(bsCaps);
|
|
109
|
-
|
|
110
|
-
// Ensure capabilities exist
|
|
111
|
-
envConfigObj.capabilities = getBrowserStackCapabilities(envConfigObj.capabilities, bsCaps);
|
|
112
|
-
|
|
113
|
-
// Merge with base config
|
|
114
|
-
const finalConfig = deepmerge(baseConfig, envConfigObj);
|
|
115
|
-
|
|
116
|
-
console.log('====> Final merged config ready for WDIO');
|
|
117
|
-
|
|
118
|
-
return finalConfig;
|
|
119
|
-
})();
|
|
120
|
-
// // --------------------
|
|
121
|
-
// // Inject media files into BrowserStack capabilities
|
|
122
|
-
// // --------------------
|
|
123
|
-
// async function getBrowserStackCapabilities(baseCaps) {
|
|
124
|
-
// if (
|
|
125
|
-
// process.env.PLATFORM !== 'browserstack' &&
|
|
126
|
-
// process.env.PLATFORM !== 'browserstacklocal'
|
|
127
|
-
// ) {
|
|
128
|
-
// return baseCaps;
|
|
129
|
-
// }
|
|
130
|
-
|
|
131
|
-
// console.log('🟡 Raw Capabilities (Before):');
|
|
132
|
-
// console.log(JSON.stringify(baseCaps, null, 2));
|
|
133
|
-
|
|
134
|
-
// const isArray = Array.isArray(baseCaps);
|
|
135
|
-
// const capsArray = isArray ? baseCaps : [baseCaps];
|
|
136
|
-
|
|
137
|
-
// const updatedCaps = capsArray.map(async (capability) => {
|
|
138
|
-
// capability['bstack:options'] = capability['bstack:options'] || {};
|
|
139
|
-
// const bsOpts = capability['bstack:options'];
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// const mediaFiles = JSON.parse(process.env.MEDIA_FILES);
|
|
143
|
-
|
|
144
|
-
// // ✅ Inject media files from YAML if present
|
|
145
|
-
// if (Array.isArray(mediaFiles) && mediaFiles.length > 0) {
|
|
146
|
-
// bsOpts.uploadMedia = mediaFiles;
|
|
147
|
-
// console.log('🟢 Uploading media files:', bsOpts.uploadMedia);
|
|
148
|
-
// }
|
|
149
|
-
|
|
150
|
-
// capability['bstack:options'] = bsOpts;
|
|
151
|
-
|
|
152
|
-
// return capability;
|
|
153
|
-
// });
|
|
154
|
-
|
|
155
|
-
// // return isArray ? updatedCaps : updatedCaps[0];
|
|
156
|
-
// }
|
|
157
|
-
|
|
158
|
-
// // Apply media injection
|
|
159
|
-
// envConfig = await getBrowserStackCapabilities(envConfig, bsCaps);
|
|
160
65
|
|
|
161
|
-
|
|
162
|
-
// exports.config = deepmerge(baseConfig, envConfig(bsCaps));
|
|
66
|
+
exports.config = deepmerge(baseConfig, envConfig(bsCaps));
|
|
163
67
|
|