froth-webdriverio-framework 5.0.13 → 5.0.15

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.
@@ -9,8 +9,7 @@ const exeDetails = require("../froth_api_calls/getexecutionDetails")
9
9
  const { fail } = require("assert");
10
10
  const { error } = require('console');
11
11
  const HTMLReportGenerator = require('wdio-json-html-reporter').HTMLReportGenerator;
12
- global.Util = require('./globalUtilShim');
13
-
12
+ global.Util=require('../froth_common_actions/Utils');
14
13
 
15
14
  //const isBrowserStackEnabled = process.env.BROWSERSTACK;
16
15
  let starttime;
@@ -35,6 +34,7 @@ const commonconfig = {
35
34
  await setAllDetails.setSuiteDetails();
36
35
  await setAllDetails.setTestDataDetails();
37
36
  console.log("on prepare:", JSON.stringify(capabilities))
37
+
38
38
  // console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
39
39
  } catch (e) {
40
40
  console.log("====> Error in onPrepare:", e);
@@ -45,6 +45,8 @@ const commonconfig = {
45
45
 
46
46
  beforeSession: async function (config, capabilities, specs) {
47
47
  try {
48
+
49
+
48
50
  let syntaxFailed = false;
49
51
 
50
52
  console.log('==== BEFORE SESSION HOOK ====');
@@ -164,21 +166,7 @@ const commonconfig = {
164
166
  console.log('==== BEFORE HOOK FOR MOBILE ====');
165
167
  }
166
168
 
167
- const Module = require('module');
168
- const originalRequire = Module.prototype.require;
169
-
170
- Module.prototype.require = function (path) {
171
- // Intercept only for the Utils file
172
- if (path.includes('froth_common_actions/Utils')) {
173
- console.log('⚡ Overriding require for:', path);
174
- return require('./globalUtilShim'); // <-- path relative to wdio.conf.js
175
- }
176
-
177
- return originalRequire.apply(this, arguments);
178
- };
179
169
 
180
- // Optionally also expose globally
181
- global.Util = require('./globalUtilShim');
182
170
  },
183
171
 
184
172
  /**
@@ -0,0 +1,47 @@
1
+ /**
2
+ * wdio-require-patch.js
3
+ * This script patches Node's require() so that any test file requiring
4
+ * '../B/froth_common_actions/Utils' automatically gets the correct global Util object.
5
+ */
6
+
7
+ const path = require('path');
8
+ const fs = require('fs');
9
+ const Module = require('module');
10
+ console.log('🔧 Applying wdio-require-patch.js...');
11
+ // --- 1️⃣ Locate the correct Utils.js dynamically ---
12
+ const possiblePaths = [
13
+ // Local project structure
14
+ path.resolve(__dirname, '../B/froth_common_actions/Utils.js'),
15
+ path.resolve(__dirname, '../node_modules/froth-webdriverio-framework/froth_common_actions/Utils.js'),
16
+
17
+ // Cloud structure (when framework is inside node_modules)
18
+ path.resolve(__dirname, './node_modules/froth-webdriverio-framework/froth_common_actions/Utils.js'),
19
+
20
+ // Fallback (when running inside another workspace)
21
+ path.resolve(process.cwd(), 'node_modules/froth-webdriverio-framework/froth_common_actions/Utils.js'),
22
+ ];
23
+
24
+ const utilsPath = possiblePaths.find(p => fs.existsSync(p));
25
+
26
+ if (!utilsPath) {
27
+ console.warn('⚠️ Could not find Utils.js in expected paths. Global.Util not set.');
28
+ } else {
29
+ global.Util = require(utilsPath);
30
+ console.log(`✅ Global Util loaded from: ${utilsPath}`);
31
+ }
32
+
33
+ // --- 2️⃣ Patch Node's require() so that any require of Utils returns global.Util ---
34
+ const originalRequire = Module.prototype.require;
35
+
36
+ Module.prototype.require = function (request) {
37
+ // Catch any variation of the Utils import
38
+ if (
39
+ request.includes('froth_common_actions/Utils') ||
40
+ request.endsWith('/Utils') ||
41
+ request.endsWith('/Utils.js')
42
+ ) {
43
+ console.log(`⚡ Redirecting require('${request}') → global.Util`);
44
+ return global.Util;
45
+ }
46
+ return originalRequire.apply(this, arguments);
47
+ };
@@ -1,10 +1,12 @@
1
1
  const deepmerge = require('deepmerge')
2
+ //global.Util=require('./patch_require'); // Ensure this is imported first
2
3
  const fs = require('fs');
3
4
  const yaml = require('js-yaml');
4
5
  const path = require('path');
5
6
  const commonconfig = require('./commonconfig');
6
7
  console.log('=====wdios common config===== ');
7
8
  const { JSONReporter, HTMLReportGenerator } = require('wdio-json-html-reporter');
9
+ //require("./patch_require"); // Ensure this is imported first
8
10
 
9
11
  // Select platform at runtime
10
12
  const PLATFORM = process.env.PLATFORM || 'browserstack';
@@ -18,6 +20,8 @@ const resultdetails = {
18
20
  excution_time: null, // Execution time in milliseconds
19
21
  };
20
22
 
23
+
24
+
21
25
  // Load YAML file
22
26
  //const capabilities = yaml.load(fs.readFileSync(path.join(path.resolve(process.cwd(), configFile)), 'utf8'));
23
27
 
@@ -140,7 +144,7 @@ exports.config = deepmerge(commonconfig,
140
144
 
141
145
  framework: 'mocha',
142
146
  reporters: ['spec',
143
- [JSONReporter, { outputDir: reportDir,outputFile: `./reports/${process.env.EXECUTION_ID}/test-results-${timestamp}.json`, screenshotOption: 'OnFailure' }],
147
+ [JSONReporter, { outputDir: reportDir, outputFile: `./reports/${process.env.EXECUTION_ID}/test-results-${timestamp}.json`, screenshotOption: 'OnFailure' }],
144
148
  ],
145
149
 
146
150
  maxInstances: 10,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "5.0.13",
3
+ "version": "5.0.15",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",
@@ -1,36 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const possiblePaths = [
5
- path.resolve(process.cwd(), 'node_modules/froth-webdriverio-framework/froth_common_actions/Utils'),
6
- path.resolve(process.cwd(), '../DEPENDENCY/node_modules/froth-webdriverio-framework/froth_common_actions/Utils'),
7
- path.resolve(process.cwd(), '../../DEPENDENCY/node_modules/froth-webdriverio-framework/froth_common_actions/Utils'),
8
- ];
9
- let loaded = false;
10
-
11
-
12
- for (const filePath of possiblePaths) {
13
- if (fs.existsSync(filePath + '.js')) {
14
- global.Util = require(filePath);
15
- console.log(`✅ Global Util loaded from: ${filePath}`);
16
- loaded = true;
17
- break;
18
- }
19
- }
20
-
21
- if (!loaded) {
22
- try {
23
- // fallback to node_modules package (cloud CI)
24
- global.Util = require('froth-webdriverio-framework/froth_common_actions/Utils');
25
- console.log('✅ Global Util loaded from npm package');
26
- loaded = true;
27
- } catch (err) {
28
- console.error('❌ Could not load froth_common_actions/Utils from known paths or npm package');
29
- throw err;
30
- }
31
- }else
32
- console.log('✅ Global Util already defined');
33
-
34
- console.log("global Util loaded from:", global.Util);
35
-
36
- module.exports = global.Util;