froth-webdriverio-framework 4.0.37 → 4.0.39

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.
@@ -38,7 +38,9 @@ async function getExecuitonDetails(frothUrl, token, id) {
38
38
  // const newToken = await getLoginToken(BUFFER.getItem("SERVICE_USER"), BUFFER.getItem("SERVICE_PASSWORD")); // You need to implement the login function
39
39
  // Retry the request with the new token
40
40
  // return getExecuitonDetails(frothUrl, newToken, id);
41
- console.log("Unauthorized, token expired" + response.status)
41
+ // console.log("Unauthorized, token expired" + response.status)
42
+ console.error("Unauthorized, token expired" + response.status);
43
+
42
44
  } else {
43
45
  const errorText = await response.text();
44
46
  console.error(`Data fetch failed response in getExecuitonDetails: ${response.status}`);
@@ -103,8 +105,7 @@ async function getExecuitonScriptDetails(frothUrl, token, execution_id, script_i
103
105
 
104
106
  }
105
107
 
106
- async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
107
- // if (id != 0) {
108
+ async function update_CICDRUNID_ReportUrl(frothUrl, token, id) {
108
109
 
109
110
 
110
111
  const url = `${frothUrl}/api/test-execution-update/${id}/`;
@@ -112,26 +113,17 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
112
113
  try {
113
114
  console.log("URL" + url)
114
115
 
115
- if (resultdetails.excution_status != null) {
116
- formData.append('excution_status', resultdetails.excution_status);
117
- }
118
- if (resultdetails.excution_time != null) {
119
- formData.append('excution_time', resultdetails.excution_time);
120
- }
121
- formData.append('id', BUFFER.getItem("FROTH_EXECUTION_ID"))
122
- if (BUFFER.getItem("REPORT_URL") != null)
123
- formData.append('report_url', BUFFER.getItem("REPORT_URL"))
124
-
116
+ // formData.append('id', BUFFER.getItem("FROTH_EXECUTION_ID"))
125
117
  formData.append('updated_through_bot', true)
126
118
  formData.append('run_id', process.env.CICD_RUN_ID)
127
- if (resultdetails.comments != null)
128
- formData.append('comments', resultdetails.comments.join('<br>'))
129
-
130
- // formData.append('comments', JSON.stringify(resultdetails.comments))
131
-
132
- console.log("Report URL:" + BUFFER.getItem("REPORT_URL"))
133
119
 
134
120
 
121
+ if (BUFFER.getItem("REPORT_URL") === null)
122
+ console.log("Report URL is null")
123
+ else {
124
+ console.log("Report URL:" + BUFFER.getItem("REPORT_URL"))
125
+ formData.append('report_url', BUFFER.getItem("REPORT_URL"))
126
+ }
135
127
 
136
128
  const response = await fetch(url, {
137
129
  method: 'PUT',
@@ -144,33 +136,130 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
144
136
 
145
137
  if (response.ok) {
146
138
  const data = await response.json();
147
- // console.log("data is :"+data)
148
-
149
139
  } else if (response.status === 401) { // Unauthorized, token expired
150
- // Call login function to obtain a new token
151
- // const newToken = await getLoginToken(BUFFER.getItem("SERVICE_USER"), BUFFER.getItem("SERVICE_PASSWORD")); // You need to implement the login function
152
- // // Retry the request with the new token
153
- // return updateExecuitonDetails(frothUrl, newToken, id, resultdetails);
154
140
  console.log("Unauthorized, token expired" + response.status)
155
-
156
141
  } else {
157
142
  const errorText = await response.text();
158
143
  console.error(`error in updating the status into DB ${response.status}`);
159
- // throw new Error(`HTTP error! status: ${response.status}`);
160
144
  }
161
145
 
146
+ } catch (error) {
147
+ console.error('Error fetching data:', error);
148
+
149
+ }
150
+
151
+
152
+ }
153
+
154
+ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
155
+ try {
156
+ console.log("in update execution details UPDATE_EXECUTION: " + BUFFER.getItem("UPDATE_EXECUTION"))
157
+ if (BUFFER.getItem("FROTH_UPDATE_EXECUTION") === 'TRUE') {
158
+ console.log("Execution already updated.")
159
+ }
160
+ else {
161
+ const url = `${frothUrl}/api/test-execution-update/${id}/`;
162
+ const formData = new FormData();
163
+
164
+ console.log("URL" + url)
165
+ console.log("Execution details :" + resultdetails.excution_status + " == " + resultdetails.excution_time + " == " + resultdetails.comments)
166
+ formData.append('updated_through_bot', true)
167
+
168
+ if (resultdetails.excution_status === null) {
169
+ console.log("Execution status is null")
170
+ } else
171
+ formData.append('excution_status', resultdetails.excution_status);
172
+
173
+ if (resultdetails.excution_time === null || resultdetails.excution_time === "NaN:NaN:NaN") {
174
+ console.log("Execution time is null")
175
+ } else
176
+ formData.append('excution_time', resultdetails.excution_time);
177
+
178
+
179
+ if (resultdetails.comments === null)
180
+ console.log("Comments is null")
181
+ else if (resultdetails.comments.length === 0)
182
+ console.log("Comments is empty")
183
+ else
184
+ formData.append('comments', resultdetails.comments.join('<br>'))
185
+
186
+ // formData.append('comments', JSON.stringify(resultdetails.comments))
187
+
188
+ const response = await fetch(url, {
189
+ method: 'PUT',
190
+ headers: {
191
+ 'Authorization': `Bearer ${token}`
192
+ },
193
+ body: formData
194
+
195
+ });
196
+
197
+ if (response.ok) {
198
+ const data = await response.json();
199
+ BUFFER.setItem("FROTH_UPDATE_EXECUTION", 'TRUE')
200
+ } else if (response.status === 401) { // Unauthorized, token expired
201
+ console.log("Unauthorized, token expired" + response.status)
202
+ } else {
203
+ const errorText = await response.text();
204
+ console.error(`error in updating the status into DB ${response.status}`);
205
+ // throw new Error(`HTTP error! status: ${response.status}`);
206
+ }
162
207
 
163
208
 
209
+ }
164
210
  } catch (error) {
165
- console.error('Error fetching data:', error);
211
+ console.error('Error in updateExecuitonDetails :', error);
166
212
 
167
213
  }
168
- // } else {
169
- // console.error('Error fetching data: Invalid ID');
170
- // }
171
214
 
172
215
  }
173
216
 
217
+
218
+ async function updateScriptExecutionStatus(frothUrl, token, scriptid, script_platform, status) {
219
+
220
+ if (scriptid != 0) {
221
+ try {
222
+ console.log("script platform is " + script_platform)
223
+ const id = await getExecuitonScriptDetails(frothUrl, token, BUFFER.getItem("FROTH_EXECUTION_ID"), scriptid, script_platform)
224
+ console.log("ID is :" + id)
225
+ const url = `${frothUrl}/api/script-status-percentage/${id}/`;
226
+ const formData = new FormData();
227
+
228
+ console.log("URL" + url)
229
+ // formData.append('execution_id', BUFFER.getItem("EXECUTION_ID"))
230
+ formData.append('script_status', status)
231
+ formData.append('updated_through_bot', true)
232
+
233
+ const response = await fetch(url, {
234
+ method: 'PUT',
235
+ headers: {
236
+ 'Authorization': `Bearer ${token}`
237
+ },
238
+ body: formData
239
+
240
+ });
241
+
242
+ if (response.ok) {
243
+ const data = await response.json();
244
+ // console.log("data is :"+data)
245
+
246
+ } else if (response.status === 401) { // Unauthorized, token expired
247
+
248
+ console.log("Unauthorized, token expired" + response.status)
249
+
250
+ } else {
251
+ const errorText = await response.text();
252
+ console.error(`error in updating the status into DB ${response.status}`);
253
+ }
254
+ } catch (error) {
255
+ console.error('Error updating data for script status:', error);
256
+
257
+ }
258
+ } else {
259
+ console.error('Else: Error updating data for script status: Invalid ID');
260
+ }
261
+
262
+ }
174
263
  async function updateScriptExecutionStatus(frothUrl, token, scriptid, script_platform, status) {
175
264
 
176
265
  if (scriptid != 0) {
@@ -253,5 +342,5 @@ async function updateScriptExecutionStatus(frothUrl, token, scriptid, script_pla
253
342
  // }
254
343
 
255
344
  // main();
256
- module.exports = { getExecuitonDetails, updateExecuitonDetails, updateScriptExecutionStatus };
345
+ module.exports = { getExecuitonDetails, updateExecuitonDetails, updateScriptExecutionStatus, update_CICDRUNID_ReportUrl };
257
346
 
@@ -54,11 +54,11 @@ function main() {
54
54
  iat: currentTimestamp, // Issued at
55
55
  exp: currentTimestamp + 200, // Expiry time: 30 seconds from issuance
56
56
  user_agent: {
57
- id: "kartikaypriya.p@ytlcomms.my"
57
+ id: "janga.reddy@ytl.com"
58
58
  }
59
59
  };
60
60
 
61
61
  console.log('JWT signed token:', generateJWTToken(payload));
62
62
  }
63
- //main()
63
+ main()
64
64
  module.exports = { generateJWTToken}
@@ -126,7 +126,8 @@ const commonconfig = {
126
126
 
127
127
 
128
128
  // const resultdetails = {};
129
- await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
129
+ await exeDetails.update_CICDRUNID_ReportUrl(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"))
130
+ BUFFER.setItem("UPDATE_EXECUTION", 'FALSE')
130
131
 
131
132
  } catch (e) {
132
133
  console.log("Error in beforeSuite:", e);
@@ -218,7 +219,6 @@ const commonconfig = {
218
219
  console.log('====> All tests are completed.' + result);
219
220
  BUFFER.setItem("RESULT_DATA", result);
220
221
  console.log("====> Result data :" + BUFFER.getItem("RESULT_DATA"))
221
- /// const resultdetails = {}
222
222
  resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
223
223
  console.log("====> Total Duration taken for the suite:" + BUFFER.getItem("FROTH_TOTAL_DURATION"));
224
224
  console.log("====> Execution Status from results" + resultdetails.excution_status);
@@ -235,9 +235,7 @@ const commonconfig = {
235
235
  });
236
236
 
237
237
  }
238
- resultdetails.excution_time = await secondsToTime(BUFFER.getItem("FROTH_TOTAL_DURATION"))
239
- await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
240
-
238
+
241
239
  },
242
240
 
243
241
  afterSession: async function (config, capabilities, specs) {
@@ -246,12 +244,7 @@ const commonconfig = {
246
244
  // console.log("Capabilities:", capabilities);
247
245
  console.log("Specs:", specs);
248
246
  //console.log("Config:", config);
249
- endtime = new Date().getTime();
250
- let totalDuration = endtime - starttime;
251
- console.log("====> Total Duration in after session based on start time and end time:" + totalDuration);
252
- if (process.env.PLATFORM === 'browserstack')
253
- await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_ACCESS_KEY);
254
-
247
+
255
248
  process.on('uncaughtException', (err) => {
256
249
  console.error("Uncaught Exception:", err);
257
250
  resultdetails.comments.push(`Execution failed with exit code: ${err}`);
@@ -263,13 +256,6 @@ const commonconfig = {
263
256
  resultdetails.comments.push(`Execution failed with exit code: ${reason}`);
264
257
  });
265
258
 
266
- resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
267
- console.log("====> Total Duration calculation:" + BUFFER.getItem("FROTH_TOTAL_DURATION") === 0 ? await convertTimetoHHMMSS(totalDuration) : await secondsToTime(BUFFER.getItem("FROTH_TOTAL_DURATION")));
268
- resultdetails.excution_time = BUFFER.getItem("FROTH_TOTAL_DURATION") === 0 ? await convertTimetoHHMMSS(totalDuration) : await secondsToTime(BUFFER.getItem("FROTH_TOTAL_DURATION"))
269
- await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
270
- BUFFER.clear();
271
-
272
-
273
259
  // Perform any cleanup or post-test actions here
274
260
  },
275
261
 
@@ -283,9 +269,20 @@ const commonconfig = {
283
269
  console.log('Skipped:', results.skipped);
284
270
  console.log('Execution Time:', results.duration);
285
271
  console.log('Exit Code:', exitCode);
286
- console.log('==== ALL TESTS ARE COMPLETED ====');
287
-
288
272
 
273
+ endtime = new Date().getTime();
274
+ let totalDuration = endtime - starttime;
275
+ console.log("====> Total Duration in after session based on start time and end time:" + totalDuration);
276
+
277
+ resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
278
+ console.log("====> Total Duration calculation:" + BUFFER.getItem("FROTH_TOTAL_DURATION") === null || BUFFER.getItem("FROTH_TOTAL_DURATION") === 0 || BUFFER.getItem("FROTH_TOTAL_DURATION") === undefined
279
+ ? await convertTimetoHHMMSS(totalDuration) : await secondsToTime(BUFFER.getItem("FROTH_TOTAL_DURATION")));
280
+ resultdetails.excution_time = BUFFER.getItem("FROTH_TOTAL_DURATION") === null || BUFFER.getItem("FROTH_TOTAL_DURATION") === 0 || BUFFER.getItem("FROTH_TOTAL_DURATION") === undefined ? await convertTimetoHHMMSS(totalDuration) : await secondsToTime(BUFFER.getItem("FROTH_TOTAL_DURATION"))
281
+
282
+ await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("FROTH_LOGIN_TOKEN"), BUFFER.getItem("FROTH_EXECUTION_ID"), resultdetails)
283
+ BUFFER.clear();
284
+
285
+ console.log('==== ALL TESTS ARE COMPLETED ====');
289
286
  return exitCode;
290
287
  }
291
288
 
@@ -311,6 +308,7 @@ async function convertTimetoHHMMSS(time) {
311
308
  const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
312
309
 
313
310
  console.log("Time:" + hours + ':' + minutes + ':' + seconds);
311
+
314
312
  return formattedTime;
315
313
  }
316
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "4.0.37",
3
+ "version": "4.0.39",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",
File without changes
@@ -1,72 +0,0 @@
1
- const RandExp = require('randexp');
2
-
3
- async function RNDNUMBER(min, max) {
4
- return Math.floor(Math.random() * (max - min + 1)) + min;
5
- }
6
-
7
- async function RNDFLOAT() {
8
- return Math.random();
9
- }
10
-
11
- async function RNDINT() {
12
- return Math.floor(Math.random() * 100000); // You can choose any large multiplier for bigger ranges
13
- }
14
-
15
- async function RNDNUMBER(length) {
16
- if (length <= 0) return null; // Handle invalid length
17
-
18
- const min = Math.pow(10, length - 1); // Minimum value for the given length
19
- const max = Math.pow(10, length) - 1; // Maximum value for the given length
20
-
21
- return Math.floor(Math.random() * (max - min + 1)) + min; // Generate the random number
22
- }
23
- async function RANDOMTEXT(length) {
24
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
25
- let result = '';
26
- for (let i = 0; i < length; i++) {
27
- result += characters.charAt(Math.floor(Math.random() * characters.length));
28
- }
29
- return result;
30
- }
31
-
32
- async function RNDALPHANUM(length) {
33
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
34
- let result = '';
35
- for (let i = 0; i < length; i++) {
36
- result += chars.charAt(Math.floor(Math.random() * chars.length));
37
- }
38
- return result;
39
- }
40
-
41
- async function RNDDECIMAL(min, max, decimalPlaces) {
42
- let randomNum = Math.random() * (max - min) + min; // Generates a number between min and max
43
- return parseFloat(randomNum.toFixed(decimalPlaces));
44
- }
45
-
46
- async function RNDDECIMAL(decimalPlaces) {
47
- let randomNum = Math.random(); // Generates a number between 0 and 1
48
- return parseFloat(randomNum.toFixed(decimalPlaces));
49
- }
50
-
51
- async function RNDREGEX(regex) {
52
- return new RandExp(regex).gen();
53
- }
54
-
55
- module.exports = {
56
- RNDNUMBER,
57
- RNDFLOAT,
58
- RNDINT,
59
- RANDOMTEXT,
60
- RNDALPHANUM,
61
- RNDDECIMAL,
62
- RNDREGEX
63
- };
64
-
65
- // console.log(RNDNUMBER(1, 100));
66
- // console.log(RNDFLOAT());
67
- // console.log(RNDINT());
68
- // console.log(RANDOMTEXT(10));
69
- // console.log(RNDALPHANUM(10));
70
- // console.log(RNDDECIMAL(100, 10000, 4));
71
- // console.log(RNDDECIMAL(2));
72
- // console.log(RNDREGEX(/[a-z]{4}\d{4}/));
@@ -1,56 +0,0 @@
1
- const express = require('express');
2
- const app = express();
3
-
4
- // Middleware to parse JSON payloads
5
- app.use(express.json());
6
-
7
- // Define the webhook path (match the path used in smee or GitHub webhook)
8
- app.post('/webhook', (request, response) => {
9
- // Respond early so GitHub doesn't time out
10
- response.status(202).send('Accepted');
11
-
12
- // Get event type from header
13
- const githubEvent = request.headers['x-github-event'];
14
- console.log(`Received event: ${githubEvent}`);
15
-
16
- const data = request.body;
17
-
18
- // Handle specific GitHub events
19
- if (githubEvent === 'issues') {
20
- const action = data.action;
21
- console.log(`Received action: ${action}`);
22
-
23
- if (action === 'opened') {
24
- console.log(`An issue was opened with this title: ${data.issue.title}`);
25
- } else if (action === 'closed') {
26
- console.log(`An issue was closed by ${data.issue.user.login}`);
27
- } else {
28
- console.log(`Unhandled action for the issue event: ${action}`);
29
- }
30
-
31
- } else if (githubEvent === 'ping') {
32
- console.log('GitHub sent the ping event');
33
-
34
- } else {
35
- // For all other events
36
- console.log(`Unhandled event: ${githubEvent}`);
37
- console.log(`Payload: ${JSON.stringify(data, null, 2)}`);
38
-
39
- if (data.action) {
40
- console.log(`Received action: ${data.action}`);
41
- }
42
-
43
- if (data.workflow_run) {
44
- console.log(`Workflow run ID: ${data.workflow_run.id}`);
45
- console.log(`Workflow name: ${data.workflow_run.name}`);
46
- console.log(`Status: ${data.workflow_run.status}`);
47
- console.log(`Conclusion: ${data.workflow_run.conclusion}`);
48
- }
49
- }
50
- });
51
-
52
- // Start server on port 3000
53
- const port = 3000;
54
- app.listen(port, () => {
55
- console.log(`Server is running on port ${port}`);
56
- });