froth-webdriverio-framework 6.0.74 → 6.0.75

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.
@@ -1,20 +1,16 @@
1
-
2
- async function getBSBuildDetails(sessiontype, bs_username, bs_pwd) {
1
+ async function getBSBuildDetails(sessionType, bsUsername, bsPassword) {
3
2
  try {
4
- // const sessionId = sessionIdd;
5
- console.log("sessiontype:" + sessiontype)
6
- const username = bs_username;
7
- const accessKey = bs_pwd;
8
- console.log("accessKey:" + accessKey)
9
- const basicAuth = btoa(`${username}:${accessKey}`);
3
+ console.log(`Session type: ${sessionType}`);
10
4
 
11
- let hashed_id = null;
5
+ const basicAuth = btoa(`${bsUsername}:${bsPassword}`);
6
+ const buildName = sessionType === 'app-automate'
7
+ ? `Mobile_Build-${process.env.FROTH_TESTOPS_BUILD_NAME}`
8
+ : `Web_Build-${process.env.FROTH_TESTOPS_BUILD_NAME}`;
12
9
 
13
- // const sessionid= BUFFER.getItem("SESSION_ID");
14
- console.log("Browsersatck build name :" + process.env.FROTH_TESTOPS_BUILD_NAME)
15
- const url = `https://api.browserstack.com/${sessiontype}/builds.json?name=${process.env.FROTH_TESTOPS_BUILD_NAME}`;
10
+ console.log(`BrowserStack build name: ${buildName}`);
16
11
 
17
- console.log("url:" + url)
12
+ const url = `https://api.browserstack.com/${sessionType}/builds.json?name=${buildName}`;
13
+ console.log(`URL: ${url}`);
18
14
 
19
15
  const response = await fetch(url, {
20
16
  method: 'GET',
@@ -25,47 +21,34 @@ async function getBSBuildDetails(sessiontype, bs_username, bs_pwd) {
25
21
 
26
22
  if (response.ok) {
27
23
  const data = await response.json();
28
- console.log("session build_data:" + JSON.stringify(data))
29
- // Accessing the public_url property
30
- hashed_id = data[0].automation_build.hashed_id;
31
-
32
- return hashed_id;
33
- } else if (response.status === 401) { //
34
- console.log("Unauthorized, token expired")
24
+ console.log(`Build data: ${JSON.stringify(data)}`);
35
25
 
26
+ return data[0].automation_build.hashed_id;
27
+ } else if (response.status === 401) {
28
+ console.error("Unauthorized: token expired");
36
29
  } else {
37
30
  const errorText = await response.text();
38
- console.error(`Data fetch failed response in getBSBuildDetails:${response.status}`);
39
- // console.error(`Data fetch failed response in getBSBuildDetails:${errorText}`);
40
- // throw new Error(`HTTP error! status: ${response.status}`);
31
+ console.error(`Failed to fetch build details: ${response.status}, ${errorText}`);
41
32
  }
42
33
 
43
-
44
-
45
34
  } catch (error) {
46
- console.error('Error fetching data:', error);
47
-
35
+ console.error('Error fetching build details:', error);
48
36
  }
49
-
50
-
51
37
  }
52
38
 
53
- async function getBSSessionDetails(sessiontype, bs_username, bs_pwd) {
39
+ async function getBSSessionDetails(sessionType, bsUsername, bsPassword) {
54
40
  try {
55
- // const sessionId = sessionIdd;
56
- const username = bs_username;
57
- // const accessKey = Buffer.from(bs_pwd, 'base64').toString('utf-8');
58
- const accessKey = bs_pwd;
41
+ const basicAuth = btoa(`${bsUsername}:${bsPassword}`);
42
+ const hashId = await getBSBuildDetails(sessionType, bsUsername, bsPassword);
59
43
 
60
- const basicAuth = btoa(`${username}:${accessKey}`);
44
+ if (!hashId) {
45
+ console.error("Build hash ID not found. Cannot fetch session details.");
46
+ return;
47
+ }
61
48
 
62
- const hash_id = await getBSBuildDetails(sessiontype, bs_username, accessKey)
63
- // const sessionid = BUFFER.getItem("SESSION_ID");
64
- console.log("hash_id" + hash_id)
49
+ const url = `https://api.browserstack.com/${sessionType}/builds/${hashId}/sessions.json`;
50
+ console.log(`URL: ${url}`);
65
51
 
66
- // const url = `https://api.browserstack.com/${sessiontype}/sessions/${sessionid}.json`;
67
- const url = `https://api.browserstack.com/${sessiontype}/builds/${hash_id}/sessions.json`;
68
- console.log("url:" + url)
69
52
  const response = await fetch(url, {
70
53
  method: 'GET',
71
54
  headers: {
@@ -75,71 +58,39 @@ async function getBSSessionDetails(sessiontype, bs_username, bs_pwd) {
75
58
 
76
59
  if (response.ok) {
77
60
  const data = await response.json();
78
-
79
- // Accessing the public_url property
80
61
  const publicUrl = data[0].automation_session.public_url;
81
62
  const duration = data[0].automation_session.duration;
82
- BUFFER.setItem("REPORT_URL", publicUrl)
83
- BUFFER.setItem("FROTH_TOTAL_DURATION", duration)
84
- console.log("public url:" + publicUrl)
85
- //return jsondata;
86
- } else if (response.status === 401) { //
87
- console.log("Unauthorized, token expired")
88
63
 
64
+ BUFFER.setItem("REPORT_URL", publicUrl);
65
+ BUFFER.setItem("FROTH_TOTAL_DURATION", duration);
66
+
67
+ console.log(`Public URL: ${publicUrl}`);
68
+ } else if (response.status === 401) {
69
+ console.error("Unauthorized: token expired");
89
70
  } else {
90
71
  const errorText = await response.text();
91
- console.error(`Data fetch failed response in getBSSessionDetails :${response.status}`);
92
- // throw new Error(`HTTP error! status: ${response.status}`);
72
+ console.error(`Failed to fetch session details: ${response.status}, ${errorText}`);
93
73
  }
94
74
 
95
-
96
-
97
75
  } catch (error) {
98
- console.error('Error fetching data:', error);
99
-
76
+ console.error('Error fetching session details:', error);
100
77
  }
101
-
102
-
103
78
  }
104
79
 
105
80
  async function amend2Browserstack(annotationMessage, level) {
106
81
  try {
107
-
108
- console.log("Annotation message inside amend2Browserstack:" + annotationMessage)
109
- if (process.env.PLATFORM === 'browserstack')
110
- await driver.execute('browserstack_executor: {"action": "annotate", "arguments": {"data":"' + annotationMessage + '","level": "' + level + '"}}');
111
-
82
+ console.log(`Annotation message: ${annotationMessage}`);
83
+ if (process.env.PLATFORM === 'browserstack') {
84
+ await driver.execute(`browserstack_executor: {"action": "annotate", "arguments": {"data":"${annotationMessage}","level": "${level}"}}`);
85
+ }
112
86
  } catch (error) {
113
- console.error('Error occurred while annoting to BS :', error);
87
+ console.error('Error annotating BrowserStack session:', error);
114
88
  throw error;
115
89
  }
116
90
  }
117
91
 
118
-
119
-
120
-
121
- // Execute the main function
122
-
123
- // Main function to execute the API call
124
- // async function main() {
125
- // try {
126
- // /// BUFFER.setItem("EXECUTION_SESSIONID","297666e2fd4195de98d7da3b359669072ff41a2a");
127
- // const login=0.30;
128
- // const landing=0.30;
129
- // const home=0.30;
130
- // const payment=0.30;
131
-
132
-
133
- // await amend2Browserstack("\n Page load time for login page:"+login+"\n Page load time for landing page:"+landing+"\n Page load time for home page:"+home+"\n Page load time for payment page:"+payment, "info");
134
- // } catch (error) {
135
- // console.error('Error in main function:', error);
136
- // }
137
- // }
138
-
139
- // main();
140
92
  module.exports = {
141
93
  getBSSessionDetails,
142
94
  getBSBuildDetails,
143
95
  amend2Browserstack,
144
96
  };
145
-
@@ -29,7 +29,7 @@ module.exports = (bsCaps) => {
29
29
  platformName: bsCaps.platformName || 'Android',
30
30
  'bstack:options': {
31
31
  // projectName: 'BrowserStack Samples',
32
- // buildName: 'Mobile_Build-',
32
+ buildName: 'Mobile_Build-',
33
33
  // sessionName: 'Mobile Test',
34
34
  deviceName: bsCaps.deviceName || 'Samsung Galaxy S22 Ultra',
35
35
  osVersion: bsCaps.platformVersion || '12.0',
@@ -3,7 +3,7 @@ const setAllDetails = require('./setallDatailinBuffer');
3
3
  const exeDetails = require('../froth_api_calls/getexecutionDetails');
4
4
  const { getBSSessionDetails } = require('../froth_api_calls/browsersatckSessionInfo');
5
5
  let globalErrorHandled = false;
6
- let suiteStartTime;
6
+ let suiteStartTime = 0;
7
7
  let totalTestDuration = 0;
8
8
  const url = require('url');
9
9
  const fs = require('fs');
@@ -59,7 +59,7 @@ async function safeUpdateExecution() {
59
59
  }
60
60
 
61
61
  /* ----------------- HELPER FUNCTIONS ----------------- */
62
- function msToTime(ms) {
62
+ async function msToTime(ms) {
63
63
  if (!ms || isNaN(ms)) return '00:00:00';
64
64
 
65
65
  let seconds = Math.floor(ms / 1000);
@@ -87,9 +87,11 @@ const commonHooks = {
87
87
 
88
88
  /* ========== ON PREPARE ========== */
89
89
  onPrepare: async () => {
90
+ suiteStartTime = Date.now();
90
91
  registerGlobalErrorHandlers();
91
92
 
92
93
  console.log('==== ON PREPARE HOOK ====');
94
+
93
95
  await setAllDetails.setEnvVariables();
94
96
  await setAllDetails.setExecutionDetails();
95
97
  await setAllDetails.setSuiteDetails();
@@ -184,6 +186,7 @@ const commonHooks = {
184
186
  /* ========== AFTER TEST ========== */
185
187
  afterTest: async (test, _, { error, duration, passed }) => {
186
188
  console.log(`==== AFTER TEST HOOK ===='${test.title}'`);
189
+ if (!totalTestDuration) totalTestDuration = 0;
187
190
  totalTestDuration += duration;
188
191
 
189
192
  const fileName = path.basename(test.file);
@@ -262,30 +265,21 @@ const commonHooks = {
262
265
  console.log('==== ON COMPLETE ====');
263
266
  console.log(`Total: ${results.total || 0}, Passed: ${results.passed || 0}, Failed: ${results.failed || 0}`);
264
267
 
265
- // Status
266
- resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
268
+ const endTime = Date.now();
269
+ const totalTime = endTime - suiteStartTime; // Full WDIO+CI elapsed time
267
270
 
268
- // Execution time using WDIO's internal duration (in ms)
269
- const totalDuration = results._duration || 0;
270
- resultdetails.excution_time = msToTime(totalDuration);
271
- console.log('⏱ Final execution time (ms):', totalDuration);
272
- console.log('⏱ Final execution time (hh:mm:ss):', resultdetails.excution_time);
271
+ resultdetails.excution_time = await msToTime(totalTime);
272
+ resultdetails.excution_status = exitCode === 0 ? 'PASSED' : 'FAILED';
273
273
 
274
- // Add generic failure comment if exitCode != 0 and no comments yet
275
274
  if (exitCode !== 0 && resultdetails.comments.length === 0) {
276
275
  resultdetails.comments.push(`Execution failed with exit code ${exitCode}`);
277
276
  }
278
277
 
279
- // Update DB
280
- console.log('📤 Updating DB with final execution details');
281
- console.log('Status:', resultdetails.excution_status);
282
- console.log('Duration:', resultdetails.excution_time);
283
- console.log('Comments:', resultdetails.comments.join('; '));
278
+ console.log('⏱ Final execution time (ms):', totalTime);
279
+ console.log(' Final execution time (hh:mm:ss):', resultdetails.excution_time);
284
280
 
285
281
  await safeUpdateExecution();
286
282
  BUFFER.clear();
287
-
288
-
289
283
  return exitCode;
290
284
  },
291
285
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "6.0.74",
3
+ "version": "6.0.75",
4
4
  "readme": "WendriverIO Integration with [BrowserStack](https://www.browserstack.com)",
5
5
  "description": "Selenium examples for WebdriverIO and BrowserStack App Automate",
6
6
  "scripts": {