froth-webdriverio-framework 5.0.8 → 5.0.10

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.
@@ -108,7 +108,7 @@ async function amend2Browserstack(annotationMessage, level) {
108
108
  console.log("Annotation message inside amend2Browserstack:" + annotationMessage)
109
109
  if (process.env.PLATFORM === 'browserstack')
110
110
  await driver.execute('browserstack_executor: {"action": "annotate", "arguments": {"data":"' + annotationMessage + '","level": "' + level + '"}}');
111
-
111
+
112
112
  } catch (error) {
113
113
  console.error('Error occurred while annoting to BS :', error);
114
114
  throw error;
@@ -34,7 +34,7 @@ async function getExecuitonDetails(frothUrl, token, id) {
34
34
 
35
35
  return jsondata;
36
36
  } else if (response.status === 401) { // Unauthorized, token expired
37
-
37
+
38
38
  console.error("Unauthorized, token expired" + response.status);
39
39
 
40
40
  } else {
@@ -107,7 +107,10 @@ async function update_CICDRUNID_ReportUrl(frothUrl, token, id) {
107
107
 
108
108
  // formData.append('id', BUFFER.getItem("FROTH_EXECUTION_ID"))
109
109
  formData.append('updated_through_bot', true)
110
- formData.append('run_id', process.env.CICD_RUN_ID)
110
+ if (process.env.CICD_RUN_ID === null)
111
+ console.log("CICD_RUN_ID is null")
112
+ else
113
+ formData.append('run_id', process.env.CICD_RUN_ID)
111
114
 
112
115
 
113
116
  if (BUFFER.getItem("REPORT_URL") === null)
@@ -1,5 +1,6 @@
1
1
  const amendToBrowserstack = require("../froth_api_calls/browsersatckSessionInfo").amend2Browserstack;
2
2
 
3
+
3
4
  async function logJsonData2Table(jsonData) {
4
5
  try {
5
6
  console.log("Logging JSON data to table format in BrowserStack:");
@@ -56,19 +57,15 @@ module.exports = {
56
57
  // async function main() {
57
58
  // try {
58
59
  // /// BUFFER.setItem("EXECUTION_SESSIONID","297666e2fd4195de98d7da3b359669072ff41a2a");
59
- // const pageTimes = [
60
- // { name: "Homepage", time: 120 },
61
- // { name: "Service Account Page", time: 250 },
62
- // { name: "Search Results", time: 180 }
63
- // ];
60
+ // const pageTimes = "[{ name: 'Homepage', time: 120 },{ name: 'Service Account Page', time: 250 },{ name: 'Search Results', time: 180 }]";
64
61
 
65
62
  // await logJsonData2Table(pageTimes, "info");
66
- // const data = [
67
- // { id: 1, score: 95.5, passed: true },
68
- // { id: 2, score: 67.2, passed: false },
69
- // { id: 3, score: null, passed: "N/A" }
70
- // ];
71
- // await logJsonData2Table(data, "info");
63
+ // // const data = [
64
+ // // { id: 1, score: 95.5, passed: true },
65
+ // // { id: 2, score: 67.2, passed: false },
66
+ // // { id: 3, score: null, passed: "N/A" }
67
+ // // ];
68
+ // // await logJsonData2Table(data, "info");
72
69
  // } catch (error) {
73
70
  // console.error('Error in main function:', error);
74
71
  // }
@@ -5,9 +5,12 @@ const { LocalStorage } = require('node-localstorage');
5
5
  global.BUFFER = new LocalStorage('./storage');
6
6
  const setAllDetails = require("./setallDatailinBuffer")
7
7
  const exeDetails = require("../froth_api_calls/getexecutionDetails")
8
- const getBSSessionDetails = require("../froth_api_calls/browsersatckSessionInfo").getBSSessionDetails;
8
+ //const getBSSessionDetails = require("../froth_api_calls/browsersatckSessionInfo").getBSSessionDetails;
9
9
  const { fail } = require("assert");
10
10
  const { error } = require('console');
11
+ const HTMLReportGenerator = require('wdio-json-html-reporter').HTMLReportGenerator;
12
+ let Util;
13
+
11
14
  //const isBrowserStackEnabled = process.env.BROWSERSTACK;
12
15
  let starttime;
13
16
  let endtime;
@@ -31,7 +34,6 @@ const commonconfig = {
31
34
  await setAllDetails.setSuiteDetails();
32
35
  await setAllDetails.setTestDataDetails();
33
36
  console.log("on prepare:", JSON.stringify(capabilities))
34
-
35
37
  // console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
36
38
  } catch (e) {
37
39
  console.log("====> Error in onPrepare:", e);
@@ -135,7 +137,13 @@ const commonconfig = {
135
137
 
136
138
  if (process.env.PLATFORM === 'browserstack')
137
139
  await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_ACCESS_KEY);
140
+ else {
141
+ console.log("Local execution - no BrowserStack session details to fetch.");
142
+ // BUFFER.setItem("SESSION_ID", "local-session");
143
+ BUFFER.setItem("REPORT_URL", `./reports/${process.env.EXECUTION_ID}/test-report.html`);
144
+ //BUFFER.setItem("FROTH_TOTAL_DURATION", 0);
138
145
 
146
+ }
139
147
 
140
148
  // const resultdetails = {};
141
149
  await exeDetails.update_CICDRUNID_ReportUrl(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"))
@@ -155,6 +163,36 @@ const commonconfig = {
155
163
  console.log('==== BEFORE HOOK FOR MOBILE ====');
156
164
  }
157
165
 
166
+ console.log("🔧 Initializing environment setup...");
167
+
168
+ // Define all possible locations of Utils.js
169
+ const possiblePaths = [
170
+ // 🟢 Cloud setup — npm installed inside project
171
+ path.resolve(process.cwd(), 'node_modules/froth-webdriverio-framework/froth_common_actions/Utils'),
172
+
173
+ // 🟢 Local setup — dependency folder outside project
174
+ path.resolve(process.cwd(), '../DEPENDENCY/node_modules/froth-webdriverio-framework/froth_common_actions/Utils'),
175
+
176
+ // 🟢 Another possible relative structure (if nested differently)
177
+ path.resolve(process.cwd(), '../../DEPENDENCY/node_modules/froth-webdriverio-framework/froth_common_actions/Utils'),
178
+ ];
179
+
180
+ // Try to locate and load the Utils module
181
+ for (const filePath of possiblePaths) {
182
+ if (fs.existsSync(filePath + '.js')) {
183
+ Util = require(filePath);
184
+ global.Util = Util;
185
+ console.log(`✅ Utils loaded successfully from: ${filePath}`);
186
+ break;
187
+ }
188
+ }
189
+
190
+ if (!global.Util) {
191
+ console.error('❌ Could not find froth_common_actions/Utils in expected paths:');
192
+ possiblePaths.forEach(p => console.error(' - ' + p));
193
+ throw new Error('Failed to load Utils. Check dependency installation path.');
194
+ }
195
+
158
196
  },
159
197
 
160
198
  /**
@@ -339,7 +377,48 @@ const commonconfig = {
339
377
  console.log('Exit Code:', exitCode);
340
378
 
341
379
  console.log('==== ALL TESTS ARE COMPLETED ====');
342
- return exitCode;
380
+
381
+ const outputFilePath = `./reports/${process.env.EXECUTION_ID}/test-report.html`;
382
+ const jsonFolder = `./reports/${process.env.EXECUTION_ID}/`; // Directory where JSON reports are saved
383
+ // Find latest JSON file (if multiple exist)
384
+ // const jsonFiles = fs
385
+ // .readdirSync(jsonFolder)
386
+ // .filter(file => file.endsWith('.json'))
387
+ // .map(file => ({
388
+ // name: file,
389
+ // time: fs.statSync(path.join(jsonFolder, file)).mtime.getTime(),
390
+ // }))
391
+ // .sort((a, b) => b.time - a.time);
392
+
393
+ // if (jsonFiles.length === 0) {
394
+ // console.warn('⚠️ No JSON file found, HTML not generated.');
395
+ // return;
396
+ // }
397
+
398
+ // const latestJson = path.join(jsonFolder, jsonFiles[0].name);
399
+ //console.log(`🧩 Using JSON report: ${latestJson}`);
400
+
401
+ // const reportGenerator = new HTMLReportGenerator(outputFilePath, jsonFolder);
402
+
403
+ // Call your method (you can rename "generate" to whatever method your class exposes)
404
+ // reportGenerator.generate({
405
+ // jsonFile: latestJson,
406
+ // reportPath: jsonFolder,
407
+ // reportName: `Execution Report - ${process.env.EXECUTION_ID}`,
408
+ // outputFile: outputFilePath,
409
+ // });
410
+
411
+
412
+ console.log(`✅ HTML report generated: ${outputFilePath}`);
413
+ // If you want to include historical data, specify the history JSON file path here.
414
+ const historyFile = `./reports/${process.env.EXECUTION_ID}/history.json`; // Optional
415
+
416
+ // Optionally, generate aggregated history data before generating the HTML report.
417
+ // JSONReporter.generateAggregateHistory({ reportPaths: jsonFolder, historyPath: historyFile });
418
+
419
+ const reportGenerator = new HTMLReportGenerator(outputFilePath, historyFile);
420
+ await reportGenerator.convertJSONFolderToHTML(jsonFolder);
421
+ // return exitCode;
343
422
  }
344
423
 
345
424
  };
@@ -4,13 +4,14 @@ const yaml = require('js-yaml');
4
4
  const path = require('path');
5
5
  const commonconfig = require('./commonconfig');
6
6
  console.log('=====wdios common config===== ');
7
+ const { JSONReporter, HTMLReportGenerator } = require('wdio-json-html-reporter');
7
8
 
8
9
  // Select platform at runtime
9
10
  const PLATFORM = process.env.PLATFORM || 'browserstack';
10
11
  console.log('====>PLATFORM:', PLATFORM);
11
12
 
12
13
  const configFile = process.env.YML_NAME;
13
-
14
+ const timestamp = new Date().toISOString().replace(/[-:.TZ]/g, '').slice(0, 14); // e.g., 20251014_121532
14
15
  const resultdetails = {
15
16
  comments: [],
16
17
  excution_status: null, // Pass/Fail
@@ -25,7 +26,7 @@ let capabilities;
25
26
  try {
26
27
  capabilities = yaml.load(fs.readFileSync(path.join(path.resolve(process.cwd(), configFile)), 'utf8'));
27
28
  // Merge chrome-specific options if applicable
28
-
29
+
29
30
  } catch (e) {
30
31
  const errorMsg = `The capability file does not exist in the currently configured repository at path: ${path.resolve(process.cwd(), configFile)}: ${e.message},Please update the Capability by editing the file`;
31
32
  console.error(errorMsg);
@@ -92,27 +93,37 @@ function setupPrerequisites() {
92
93
  process.env.BS_SESSION_TYPE = capabilities.platformName === 'android' || capabilities.platformName === 'ios' ? 'app-automate' : 'automate';
93
94
  capabilities.buildName = process.env.FROTH_TESTOPS_BUILD_NAME;
94
95
 
96
+ } else {
97
+ console.log("inside this fuction for local setup ");
98
+ console.log('capabilities.platformName:', capabilities.platformName ?? 'web');
99
+ capabilities.buildName = process.env.FROTH_TESTOPS_BUILD_NAME;
100
+
95
101
  }
96
102
 
97
103
  }
98
104
 
99
105
  const specificConfig = setupPrerequisites();
100
106
 
107
+ // Create per-execution report folder
108
+ const reportDir = path.resolve(process.cwd(), `./reports/${process.env.EXECUTION_ID}`);
109
+ if (!fs.existsSync(reportDir)) {
110
+ fs.mkdirSync(reportDir, { recursive: true });
111
+ }
101
112
 
102
113
  exports.config = deepmerge(commonconfig,
103
114
 
104
115
  {
105
- user: process.env.BROWSERSTACK_USERNAME,
106
- key: process.env.BROWSERSTACK_ACCESS_KEY,
116
+ // user: process.env.BROWSERSTACK_USERNAME,
117
+ // key: process.env.BROWSERSTACK_ACCESS_KEY,
107
118
  // debug: true,
108
119
  // execArgv: ['--inspect-brk'],
109
- services: PLATFORM === 'browserstack'
110
- ? ['browserstack']
111
- : PLATFORM === 'saucelabs'
112
- ? ['sauce']
113
- : [],
120
+ // services: PLATFORM === 'browserstack'
121
+ // ? ['browserstack']
122
+ // : PLATFORM === 'saucelabs'
123
+ // ? ['sauce']
124
+ // : [''],
114
125
 
115
- //runner: 'local',
126
+ runner: 'local',
116
127
  specs: require(SUITE_FILE).tests,
117
128
 
118
129
  maxInstances: 1,
@@ -128,11 +139,15 @@ exports.config = deepmerge(commonconfig,
128
139
  connectionRetryCount: 3,
129
140
 
130
141
  framework: 'mocha',
131
- reporters: ['spec'],
142
+ reporters: ['spec',
143
+ [JSONReporter, { outputDir: reportDir,outputFile: `./reports/${process.env.EXECUTION_ID}/test-results-${timestamp}.json`, screenshotOption: 'OnFailure' }],
144
+ ],
145
+
132
146
  maxInstances: 10,
133
147
  updateJob: false,
134
148
  mochaOpts: {
135
149
  ui: 'bdd',
136
150
  timeout: 300000
137
151
  }
152
+
138
153
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "5.0.8",
3
+ "version": "5.0.10",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",
@@ -25,12 +25,14 @@
25
25
  "appium"
26
26
  ],
27
27
  "dependencies": {
28
+ "@wdio/allure-reporter": "^9.20.0",
28
29
  "@wdio/appium-service": "^9.0.9",
29
30
  "@wdio/browserstack-service": "^9.0.9",
30
31
  "@wdio/cli": "^9.0.9",
31
32
  "@wdio/local-runner": "^9.0.9",
32
33
  "@wdio/mocha-framework": "^8.36.1",
33
34
  "@wdio/spec-reporter": "^8.36.1",
35
+ "allure-commandline": "^2.34.1",
34
36
  "appium": "^2.15.0",
35
37
  "appium-uiautomator2-driver": "^4.0.1",
36
38
  "assert": "^2.1.0",
@@ -41,6 +43,7 @@
41
43
  "deepmerge": "^4.3.1",
42
44
  "express": "^5.1.0",
43
45
  "form-data": "^4.0.0",
46
+ "froth-webdriverio-framework": "^5.0.9",
44
47
  "fs": "^0.0.1-security",
45
48
  "js-yaml": "^4.1.0",
46
49
  "mysql2": "^3.10.2",
@@ -48,6 +51,7 @@
48
51
  "node-localstorage": "^3.0.5",
49
52
  "randexp": "^0.5.3",
50
53
  "ts-node": "^10.9.2",
51
- "typescript": "^5.4.5"
54
+ "typescript": "^5.4.5",
55
+ "wdio-json-html-reporter": "^1.5.14"
52
56
  }
53
57
  }