froth-webdriverio-framework 7.0.100 → 7.0.102

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.
@@ -139,82 +139,13 @@ const commonHooks = {
139
139
  beforeSession: async function (config, capabilities, specs) {
140
140
  console.log('==== BEFORE SESSION ====');
141
141
  try {
142
- /** 1️⃣ Validate test syntax */
143
- // let syntaxFailed = false;
144
-
145
- // for (const fileUrl of specs) {
146
- // const filePath = url.fileURLToPath(fileUrl);
147
- // try {
148
- // new Function(fs.readFileSync(filePath, 'utf8'));
149
- // } catch (err) {
150
- // const msg = `❌ Syntax error in ${path.basename(filePath)}: ${err.message}`;
151
- // console.error(msg);
152
- // resultdetails.comments.push(msg);
153
- // syntaxFailed = true;
154
- // }
155
- // }
156
-
157
- // if (syntaxFailed) {
158
- // await failExecution('Syntax validation failed');
159
- // }
160
-
161
-
162
- /** 1️⃣ Validate test syntax */
163
- let syntaxFailed = false;
164
-
165
- for (const fileUrl of specs) {
166
- const filePath = url.fileURLToPath(fileUrl);
167
- const code = fs.readFileSync(filePath, 'utf8');
168
-
169
- try {
170
- new vm.Script(code, { filename: filePath });
171
- } catch (err) {
172
- const { line, column } = await extractLineColumn(err);
173
-
174
- const msg = `❌ Syntax error in ${path.basename(filePath)} at line ${line}, column ${column}: ${err.message}`;
175
-
176
- console.error(msg);
177
- resultdetails.comments.push(msg);
178
- syntaxFailed = true;
179
- }
180
- }
181
142
 
182
- if (syntaxFailed) {
183
- await failExecution('Syntax validation failed');
184
- }
143
+ await validateSyntax(specs)
144
+ /** 🔍 Print raw capabilities first */
145
+ console.log('🟡 Raw Capabilities (Before):');
146
+ console.log(JSON.stringify(capabilities, null, 2));
185
147
  /** 2️⃣ BrowserStack capability normalization */
186
-
187
- if (process.env.PLATFORM === 'browserstack' || process.env.PLATFORM === 'browserstacklocal') {
188
- /** 🔍 Print raw capabilities first */
189
- console.log('🟡 Raw Capabilities (Before):');
190
- console.log(JSON.stringify(capabilities, null, 2));
191
- const bsOpts = capabilities['bstack:options'] || {};
192
- /** 🔍 Print existing BS options */
193
- console.log('🟢 Existing bstack:options (Before Modification):');
194
- console.log(JSON.stringify(bsOpts, null, 2));
195
-
196
- if (process.env.BS_SESSION_TYPE === 'app-automate') {
197
- const appPath = process.env.BROWSERSTACK_APP_PATH;
198
- if (!appPath) {
199
- await failExecution('BROWSERSTACK_APP_PATH is missing');
200
- }
201
-
202
- bsOpts.app = appPath;
203
- capabilities['appium:app'] = appPath;
204
-
205
- console.log('✅ App & media set in before session');
206
-
207
- if (capabilities.platformName === 'android') {
208
- capabilities['appium:autoGrantPermissions'] = true;
209
- // capabilities['appium:autoGrantPermissions'] = bsCaps.autoGrantPermissions;
210
- }
211
- else
212
- capabilities['autoAcceptAlerts'] = true;
213
-
214
- }
215
- // console.log("Config deatils :" + JSON.stringify(config, null, 2));
216
-
217
- }
148
+ capabilities = await setBrowseratckSession(capabilities)
218
149
  console.log('🔎 Final capabilities:', JSON.stringify(capabilities, null, 2));
219
150
 
220
151
  } catch (error) {
@@ -404,4 +335,68 @@ async function extractLineColumn(error) {
404
335
  return { line: 'unknown', column: 'unknown' };
405
336
  }
406
337
 
338
+
339
+ async function validateSyntax(specs) {
340
+ try {
341
+ let syntaxFailed = false;
342
+
343
+ for (const fileUrl of specs) {
344
+ const filePath = url.fileURLToPath(fileUrl);
345
+ const code = fs.readFileSync(filePath, 'utf8');
346
+
347
+ try {
348
+ new vm.Script(code, { filename: filePath });
349
+ } catch (err) {
350
+ const { line, column } = await extractLineColumn(err);
351
+
352
+ const msg = `❌ Syntax error in ${path.basename(filePath)} at line ${line}, column ${column}: ${err.message}`;
353
+
354
+ console.error(msg);
355
+ resultdetails.comments.push(msg);
356
+ syntaxFailed = true;
357
+ }
358
+ }
359
+
360
+ if (syntaxFailed) {
361
+ await failExecution('Syntax validation failed');
362
+ }
363
+ } catch (e) {
364
+ console.error("failed in validate syntax method:", e)
365
+ }
366
+ }
367
+
368
+ async function setBrowseratckSession(capabilities) {
369
+
370
+
371
+ if (process.env.PLATFORM !== 'browserstack' || process.env.PLATFORM !== 'browserstacklocal') {
372
+ return capabilities;
373
+ }
374
+
375
+ const bsOpts = capabilities['bstack:options'] || {};
376
+ /** 🔍 Print existing BS options */
377
+ console.log('🟢 Existing bstack:options (Before Modification):');
378
+ console.log(JSON.stringify(bsOpts, null, 2));
379
+
380
+ if (process.env.BS_SESSION_TYPE === 'app-automate') {
381
+ const appPath = process.env.BROWSERSTACK_APP_PATH;
382
+ if (!appPath) {
383
+ await failExecution('BROWSERSTACK_APP_PATH is missing');
384
+ }
385
+
386
+ bsOpts.app = appPath;
387
+ capabilities['appium:app'] = appPath;
388
+
389
+ console.log('✅ App & media set in before session');
390
+
391
+ if (capabilities.platformName === 'android') {
392
+ capabilities['appium:autoGrantPermissions'] = true;
393
+ // capabilities['appium:autoGrantPermissions'] = bsCaps.autoGrantPermissions;
394
+ }
395
+ else
396
+ capabilities['autoAcceptAlerts'] = true;
397
+
398
+ return capabilities
399
+ // console.log("Config deatils :" + JSON.stringify(config, null, 2));
400
+ }
401
+ }
407
402
  module.exports = commonHooks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "7.0.100",
3
+ "version": "7.0.102",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",