froth-webdriverio-framework 1.0.79 → 1.0.81

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.
@@ -20,14 +20,14 @@ async function getExecuitonDetails(frothUrl, token, id) {
20
20
  });
21
21
  if (response.ok) {
22
22
  const data = await response.json();
23
- // console.log(data)
23
+ // console.log(data)
24
24
  jsondata.automation_suite_id = data.automation_suite_id;
25
25
  jsondata.test_cycle_id = data.test_cycle_id;
26
26
  if (data.testcycle_type === "Android" || data.testcycle_type === "Ios") {
27
27
  jsondata.device_name = data.device_name
28
28
  jsondata.version = data.version
29
29
  }
30
- // console.log("json data :" + JSON.stringify(jsondata));
30
+ // console.log("json data :" + JSON.stringify(jsondata));
31
31
 
32
32
  return jsondata;
33
33
  } else if (response.status === 401) { // Unauthorized, token expired
@@ -80,7 +80,7 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
80
80
 
81
81
  if (response.ok) {
82
82
  const data = await response.json();
83
- // console.log("data is :"+data)
83
+ // console.log("data is :"+data)
84
84
 
85
85
  } else if (response.status === 401) { // Unauthorized, token expired
86
86
  // Call login function to obtain a new token
@@ -90,7 +90,7 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
90
90
  } else {
91
91
  const errorText = await response.text();
92
92
  console.error(`error in updating the status into DB ${response.status}`);
93
- // throw new Error(`HTTP error! status: ${response.status}`);
93
+ // throw new Error(`HTTP error! status: ${response.status}`);
94
94
  }
95
95
 
96
96
 
@@ -104,6 +104,54 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
104
104
  }
105
105
 
106
106
  }
107
+
108
+ async function updateScriptExecutionStatus(frothUrl, token, id, status) {
109
+ if (id != 0) {
110
+ const url = `https://${frothUrl}/api/script-status-percentage/${id}/`;
111
+ const formData = new FormData();
112
+ try {
113
+ console.log("URL" + url)
114
+
115
+
116
+ // formData.append('execution_id', BUFFER.getItem("EXECUTION_ID"))
117
+ formData.append('scrpit_status', status)
118
+
119
+ const response = await fetch(url, {
120
+ method: 'PUT',
121
+ headers: {
122
+ 'Authorization': `Bearer ${token}`
123
+ },
124
+ body: formData
125
+
126
+ });
127
+
128
+ if (response.ok) {
129
+ const data = await response.json();
130
+ // console.log("data is :"+data)
131
+
132
+ } else if (response.status === 401) { // Unauthorized, token expired
133
+ // Call login function to obtain a new token
134
+ const newToken = await getLoginToken(BUFFER.getItem("SERVICE_USER"), BUFFER.getItem("SERVICE_PASSWORD")); // You need to implement the login function
135
+ // Retry the request with the new token
136
+ return updateScriptExecutionStatus(frothUrl, newToken, id, status);
137
+ } else {
138
+ const errorText = await response.text();
139
+ console.error(`error in updating the status into DB ${response.status}`);
140
+ // throw new Error(`HTTP error! status: ${response.status}`);
141
+ }
142
+
143
+
144
+
145
+ } catch (error) {
146
+ console.error('Error updating data for script status:', error);
147
+
148
+ }
149
+ } else {
150
+ console.error('Else: Error updating data for script status: Invalid ID');
151
+ }
152
+
153
+ }
154
+
107
155
  //Execute the main function
108
156
 
109
157
  //Main function to execute the API call
@@ -133,5 +181,5 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
133
181
  // }
134
182
 
135
183
  // main();
136
- module.exports = { getExecuitonDetails, updateExecuitonDetails };
184
+ module.exports = { getExecuitonDetails, updateExecuitonDetails, updateScriptExecutionStatus };
137
185
 
@@ -24,9 +24,14 @@ async function getSuiteDetails(frothUrl, token, id) {
24
24
  jsondata.test_data_id = data.test_data_id;
25
25
  jsondata.browser_stack_urls = data.browser_stack_urls;
26
26
  jsondata.automation_script_id=data.automation_script_id;
27
- console.log("automation_script_id:"+jsondata.automation_script_id)
28
- jsondata.test_sequence=data.test_sequence;
29
- console.log("test_sequence:"+jsondata.test_sequence)
27
+ console.log("automation_script_id:" + JSON.stringify(jsondata.automation_script_id))
28
+ const automationScripts = jsondata.automation_script_id.reduce((obj, item) => {
29
+ obj[item.automation_script_id] = item.automation_script_id;
30
+ BUFFER.setItem(item.automation_script_name, item.id);
31
+ return obj;
32
+ }, {});
33
+ jsondata.test_sequence = data.test_sequence;
34
+ console.log("automation_script_ details:" + JSON.stringify(BUFFER))
30
35
 
31
36
  // console.log("json data :" + JSON.stringify(jsondata));
32
37
 
@@ -1,6 +1,7 @@
1
1
  const setAllDetails = require("./setallDatailinBuffer")
2
2
  const { LocalStorage } = require('node-localstorage');
3
3
  global.BUFFER = new LocalStorage('./storage');
4
+
4
5
  const exeDetails = require("../api/getexecutionDetails")
5
6
  const getBSSessionDetails = require("../api/browsersatckSessionInfo")
6
7
 
@@ -18,8 +19,8 @@ const commonconfig = {
18
19
  // await setAllDetails.setIntegrationsDetails();
19
20
  await setAllDetails.setSuiteDetails();
20
21
  await setAllDetails.setTestDataDetails();
21
- // console.log(JSON.stringify(capabilities))
22
- // console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
22
+ // console.log(JSON.stringify(capabilities))
23
+ // console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
23
24
  },
24
25
 
25
26
 
@@ -30,8 +31,8 @@ const commonconfig = {
30
31
  beforeSuite: async function (suite) {
31
32
  try {
32
33
  console.log("Running suite:", suite.title);
33
- // const sessionId = browser.sessionId;
34
- // BUFFER.setItem("SESSION_ID", sessionId)
34
+ // const sessionId = browser.sessionId;
35
+ // BUFFER.setItem("SESSION_ID", sessionId)
35
36
  await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_ACCESS_KEY);
36
37
  const resultdetails = {};
37
38
  exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), BUFFER.getItem("EXECUTION_ID"), resultdetails)
@@ -48,7 +49,7 @@ const commonconfig = {
48
49
  */
49
50
  beforeTest: function (test, context) {
50
51
  console.log("Test Name:", test.title);
51
- // console.log("File Name:", test.file);
52
+ // console.log("File Name:", test.file);
52
53
 
53
54
  },
54
55
 
@@ -68,18 +69,30 @@ const commonconfig = {
68
69
  * @param {boolean} result.passed true if test has passed, otherwise false
69
70
  * @param {object} result.retries information about spec related retries, e.g. `{ attempts: 0, limit: 0 }`
70
71
  */
71
- afterTest: function (test, context, { error, result, duration, passed, retries }) {
72
+ afterTest: async function (test, context, { error, result, duration, passed, retries }) {
72
73
  console.log(`Test '${test.title}' finished.`);
73
74
  console.log('Test file name:', test.file);
74
- // BUFFER.setItem("TOTAL_DURATION", Number(BUFFER.getItem("TOTAL_DURATION")) + duration)
75
+ const fileName = path.basename(test.file);
76
+ console.log('Test File Name:', fileName);
77
+ // BUFFER.setItem("TOTAL_DURATION", Number(BUFFER.getItem("TOTAL_DURATION")) + duration)
75
78
  console.log(`Duration: ${duration}ms`);
76
79
  console.log(`Passed: ${passed}`);
77
- if (passed)
78
- console.log(`Result for '${test.title}' : ${result}`);
80
+ let scriptresult;
81
+ let scriptid = BUFFER.getItem(fileName)
82
+
83
+ if (passed) {
84
+ scriptresult = "PASSED"
85
+ }
86
+ else {
87
+ scriptresult = "FAILED"
88
+ }
79
89
  if (error) {
80
90
  console.error(`Error: ${error.message}`);
91
+ scriptresult = "FAILED"
81
92
  }
82
93
  console.log('---------------------------------------');
94
+ await exeDetails.updateScriptExecutionStatus(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), scriptid,scriptresult)
95
+
83
96
  },
84
97
  /**
85
98
  * Hook that gets executed after the suite has ended (in Mocha/Jasmine only).
@@ -96,22 +109,22 @@ const commonconfig = {
96
109
  * @param {Array.<String>} specs List of spec file paths that ran
97
110
  */
98
111
  after: async function (result, capabilities, specs) {
99
- console.log('All tests are done.'+result);
112
+ console.log('All tests are done.' + result);
100
113
  BUFFER.setItem("RESULT_DATA", result);
101
- console.log("result data :"+BUFFER.getItem("RESULT_DATA"))
114
+ console.log("result data :" + BUFFER.getItem("RESULT_DATA"))
102
115
  const resultdetails = {}
103
116
  resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
104
117
  console.log("Total Duration:" + BUFFER.getItem("TOTAL_DURATION"));
105
118
  console.log("Results" + resultdetails.excution_status);
106
119
  resultdetails.excution_time = await secondsToTime(BUFFER.getItem("TOTAL_DURATION"))
107
120
  await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), BUFFER.getItem("EXECUTION_ID"), resultdetails)
108
-
121
+
109
122
  },
110
123
 
111
124
  afterSession: async function (config, capabilities, specs) {
112
125
 
113
126
  console.log('This is the aftersession hook');
114
- // await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, Buffer.from(process.env.BROWSERSTACK_ACCESS_KEY, 'base64').toString('utf-8'));
127
+ // await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, Buffer.from(process.env.BROWSERSTACK_ACCESS_KEY, 'base64').toString('utf-8'));
115
128
  await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, process.env.BROWSERSTACK_ACCESS_KEY);
116
129
  const resultdetails = {}
117
130
  resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") == 0 ? 'PASSED' : 'FAILED'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",