froth-webdriverio-framework 0.1.48 → 0.1.50

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.
@@ -0,0 +1,130 @@
1
+
2
+ const getLoginToken = require("../api/loginapi.js")
3
+ // Function to get data from the API using the Bearer token
4
+
5
+ async function getExecuitonDetails(frothUrl, token, id) {
6
+ let jsondata = {};
7
+ if (id != 0) {
8
+ const url = `https://${frothUrl}/api/test-execution-retrieve/${id}`;
9
+
10
+ try {
11
+ // const token = await login(service_username, Buffer.from(service_password, 'base64').toString('utf-8')); // Wait for the login function to resolve and get the token
12
+ // if (!token) {
13
+ // throw new Error('Login failed, no token obtained');
14
+ // }
15
+ const response = await fetch(url, {
16
+ method: 'GET',
17
+ headers: {
18
+ 'Authorization': `Bearer ${token}`,
19
+ 'Content-Type': 'application/json'
20
+
21
+ }
22
+ });
23
+ if (response.ok) {
24
+ const data = await response.json();
25
+ console.log(data)
26
+ jsondata.automation_suite_id = data.automation_suite_id;
27
+ jsondata.test_cycle_id = data.test_cycle_id;
28
+ console.log("json data :" + JSON.stringify(jsondata));
29
+
30
+ return jsondata;
31
+ } else if (response.status === 401) { // Unauthorized, token expired
32
+ // Call login function to obtain a new token
33
+ const newToken = await getLoginToken(localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD")); // You need to implement the login function
34
+ // Retry the request with the new token
35
+ return getExecuitonDetails(frothUrl, newToken, id);
36
+ } else {
37
+ const errorText = await response.text();
38
+ console.error('Data fetch failed response:', errorText);
39
+ throw new Error(`HTTP error! status: ${response.status}`);
40
+ }
41
+
42
+
43
+
44
+ } catch (error) {
45
+ console.error('Error fetching data:', error);
46
+
47
+ }
48
+ } else {
49
+ console.error('Error fetching data: Invalid ID');
50
+ }
51
+
52
+ }
53
+
54
+ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
55
+ if (id != 0) {
56
+ const url = `https://${frothUrl}/api/test-execution-update/${id}/`;
57
+
58
+ try {
59
+ console.log("resultdetails" + JSON.stringify(resultdetails))
60
+ const formData = new FormData();
61
+ formData.append('excution_status', resultdetails.excution_status);
62
+ formData.append('excution_time', resultdetails.excution_time);
63
+ formData.append('id', localStorage.getItem("EXECUTION_ID"))
64
+
65
+ const response = await fetch(url, {
66
+ method: 'PUT',
67
+ headers: {
68
+ 'Authorization': `Bearer ${token}`
69
+ },
70
+ body: formData
71
+
72
+ });
73
+
74
+ if (response.ok) {
75
+ const data = await response.json();
76
+ console.log(data)
77
+
78
+ } else if (response.status === 401) { // Unauthorized, token expired
79
+ // Call login function to obtain a new token
80
+ const newToken = await getLoginToken(localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD")); // You need to implement the login function
81
+ // Retry the request with the new token
82
+ return updateExecuitonDetails(frothUrl, newToken, id,resultdetails);
83
+ } else {
84
+ const errorText = await response.text();
85
+ console.error('Data fetch failed response:', errorText);
86
+ throw new Error(`HTTP error! status: ${response.status}`);
87
+ }
88
+
89
+
90
+
91
+ } catch (error) {
92
+ console.error('Error fetching data:', error);
93
+
94
+ }
95
+ } else {
96
+ console.error('Error fetching data: Invalid ID');
97
+ }
98
+
99
+ }
100
+ //Execute the main function
101
+
102
+ //Main function to execute the API call
103
+ // async function main() {
104
+ // try {
105
+ // const frothUrl = "devapi.frothtestops.com";
106
+ // const username = "subhra.subudhi@roboticodigital.com";
107
+ // const password = "V2VsY29tZUAxMjM=";
108
+
109
+ // const token = await getLoginToken(frothUrl, username, password);
110
+ // if (!token) {
111
+ // throw new Error('Login failed, no token obtained');
112
+ // }
113
+
114
+ // const id = 208;
115
+ // // const data = await getExecuitonDetails(frothUrl, token, id);
116
+ // // console.log("Retrieved JSON Data:", data);
117
+ // const resultdetails = {}
118
+ // const resultdata = "Pass"
119
+ // const duration = "31355ms"
120
+ // resultdetails.excution_status = resultdata === 'Pass' ? 'PASSED' : 'FAILED'
121
+ // //resultdetails.excution_time = convertMillisecondsToTime(duration)
122
+ // await updateExecuitonDetails(frothUrl, token, id, resultdetails);
123
+ // } catch (error) {
124
+ // console.error('Error in main function:', error);
125
+ // }
126
+ // }
127
+
128
+ // main();
129
+ module.exports = { getExecuitonDetails, updateExecuitonDetails };
130
+
@@ -0,0 +1,72 @@
1
+
2
+ const getLoginToken = require("../api/loginapi");
3
+
4
+ // Function to get data from the API using the Bearer token
5
+ async function getSuiteDetails(frothUrl, token, id) {
6
+ let jsondata = {};
7
+ if (id = null || id != 0) {
8
+ const url = `https://${frothUrl}/api/automationsuite-retrieve/${id}`;
9
+
10
+ try {
11
+
12
+ const response = await fetch(url, {
13
+ method: 'GET',
14
+ headers: {
15
+ 'Authorization': `Bearer ${token}`,
16
+ }
17
+ });
18
+ if (response.ok) {
19
+ const data = await response.json();
20
+ console.log(data)
21
+ jsondata.automation_suite_id = data.id;
22
+ jsondata.automation_suite_name = data.automation_suite_name;
23
+ jsondata.test_data_id = data.test_data_id;
24
+ console.log("json data :" + JSON.stringify(jsondata));
25
+
26
+ return jsondata;
27
+
28
+ } else if (response.status === 401) { // Unauthorized, token expired
29
+ // Call login function to obtain a new token
30
+ const newToken = await getLoginToken(localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD")); // You need to implement the login function
31
+ // Retry the request with the new token
32
+ return getSuiteDetails(frothUrl, newToken, id);
33
+ }
34
+ else {
35
+ const errorText = await response.text();
36
+ console.error('Data fetch failed response:', errorText);
37
+ throw new Error(`HTTP error! status: ${response.status}`);
38
+ }
39
+
40
+
41
+
42
+ } catch (error) {
43
+ console.error('Error fetching data:', error);
44
+
45
+ }
46
+ } else {
47
+ console.error('Error fetching data: Invalid ID');
48
+ }
49
+
50
+ }
51
+
52
+ // async function main() {
53
+ // try {
54
+ // const frothUrl = "devapi.frothtestops.com";
55
+ // const username = "subhra.subudhi@roboticodigital.com";
56
+ // const password = "V2VsY29tZUAxMjM=";
57
+
58
+ // const token = await getLoginToken(frothUrl, username, password);
59
+ // if (!token) {
60
+ // throw new Error('Login failed, no token obtained');
61
+ // }
62
+
63
+ // const id = 106;
64
+ // const data = await getSuiteDetails(frothUrl, token, id);
65
+ // console.log("Retrieved JSON Data:", data);
66
+ // } catch (error) {
67
+ // console.error('Error in main function:', error);
68
+ // }
69
+ // }
70
+
71
+ // main();
72
+ module.exports = getSuiteDetails;
package/api/loginapi.js CHANGED
@@ -2,11 +2,11 @@
2
2
  //const FormData = require('form-data'); // Import the FormData constructor
3
3
 
4
4
 
5
- async function login(email,password) {
6
- const url = 'https://devapi.frothtestops.com/api/login/';
5
+ async function getLoginToken(frothUrl,email,password) {
6
+ const url = `https://${frothUrl}/api/login/`;
7
7
  const formData = new FormData();
8
8
  formData.append('email', email);
9
- formData.append('password', password);
9
+ formData.append('password', Buffer.from(password, 'base64').toString('utf-8'));
10
10
 
11
11
  const response = await fetch(url, {
12
12
  method: 'POST',
@@ -19,7 +19,7 @@ async function login(email,password) {
19
19
 
20
20
  if (response.ok) {
21
21
  const data = await response.json();
22
- // console.log('Token:', data.access_token);
22
+ console.log('Token:', data.access_token);
23
23
  return data.access_token;
24
24
  } else {
25
25
  console.error('Login failed:', response.statusText);
@@ -28,7 +28,27 @@ async function login(email,password) {
28
28
 
29
29
  }
30
30
 
31
- module.exports = login;
31
+ // async function main() {
32
+ // try {
33
+ // const frothUrl = "devapi.frothtestops.com";
34
+ // const username = "subhra.subudhi@roboticodigital.com";
35
+ // const password = "V2VsY29tZUAxMjM=";
36
+
37
+ // const token = await getLoginToken(frothUrl, username, password);
38
+ // if (!token) {
39
+ // throw new Error('Login failed, no token obtained');
40
+ // }
41
+
42
+
43
+
44
+ // } catch (error) {
45
+ // console.error('Error in main function:', error);
46
+ // }
47
+ // }
48
+
49
+ // main();
50
+
51
+ module.exports = getLoginToken;
32
52
 
33
53
 
34
54
 
@@ -1,16 +1,13 @@
1
1
  const login = require('./loginapi.js');
2
2
 
3
3
  // Function to get data from the API using the Bearer token
4
- async function getDataById(frothUrl, id) {
4
+ async function getDataById(frothUrl, token, id) {
5
5
 
6
6
  if (id != 0) {
7
7
  const url = `https://${frothUrl}/api/testdata-retrieve/${id}`;
8
8
 
9
9
  try {
10
- const token = await login('subhra.subudhi@roboticodigital.com', Buffer.from('V2VsY29tZUAxMjM=', 'base64').toString('utf-8')); // Wait for the login function to resolve and get the token
11
- if (!token) {
12
- throw new Error('Login failed, no token obtained');
13
- }
10
+
14
11
  const response = await fetch(url, {
15
12
  method: 'GET',
16
13
  headers: {
@@ -18,23 +15,32 @@ async function getDataById(frothUrl, id) {
18
15
  }
19
16
  });
20
17
 
21
- if (!response.ok) {
18
+ if (response.ok) {
19
+ const data = await response.json();
20
+ // Convert the key-value data to a JSON string
21
+ const jsonData = data.key_value_data;
22
+ // Convert the array into an object with keys as property names
23
+ const buffer = jsonData.reduce((obj, item) => {
24
+ obj[item.key] = item.value;
25
+ return obj;
26
+ }, {});
27
+ // Set the buffer as an environment variable
28
+ // const stringData = JSON.stringify(buffer);
29
+ // console.log('JSON DATA : ', stringData);
30
+ return buffer;
31
+ }
32
+ else if (response.status === 401) { // Unauthorized, token expired
33
+ // Call login function to obtain a new token
34
+ const newToken = await getLoginToken(localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD")); // You need to implement the login function
35
+ // Retry the request with the new token
36
+ return getDataById(frothUrl, newToken, id);
37
+ }
38
+ else {
22
39
  const errorText = await response.text();
23
40
  console.error('Data fetch failed response:', errorText);
24
41
  throw new Error(`HTTP error! status: ${response.status}`);
25
42
  }
26
- const data = await response.json();
27
- // Convert the key-value data to a JSON string
28
- const jsonData = data.key_value_data;
29
- // Convert the array into an object with keys as property names
30
- const buffer = jsonData.reduce((obj, item) => {
31
- obj[item.key] = item.value;
32
- return obj;
33
- }, {});
34
- // Set the buffer as an environment variable
35
- const stringData = JSON.stringify(buffer);
36
- // console.log('JSON DATA : ', stringData);
37
- return buffer;
43
+
38
44
 
39
45
 
40
46
  } catch (error) {
@@ -10,7 +10,7 @@ const androidConfig = deepmerge.all([commonmobileconfig, {
10
10
  testObservability: true,
11
11
  buildName: "ANDROID BUILD 1",
12
12
  buildIdentifier: process.env.BUILD_NUMBER || "default_build_identifier",
13
- browserstackLocal: true,
13
+ browserstackLocal: false,
14
14
  opts: { forcelocal: false },
15
15
  app: process.env.BROWSERSTACK_APP_PATH || 'bs://a224145c09eb22e67c21ef65b29d32ae7aa78bb0'
16
16
  }
@@ -1,22 +1,42 @@
1
1
  const getDataById = require("../api/readTestdata");
2
+ const exeDetails = require("../api/getexecutionDetails")
3
+ const getLoginToken = require("../api/loginapi");
4
+ const getSuiteDetails = require("../api/getsuiteDetails");
5
+ const { LocalStorage } = require('node-localstorage');
6
+ global.localStorage = new LocalStorage('./scratch');
7
+
2
8
  // Description: This file contains the common configuration for the webdriverio framework.
3
9
  const commonconfig = {
4
10
 
5
-
11
+
6
12
  onPrepare: async function (capabilities, specs) {
7
13
  // This code runs before the test suite starts
8
14
  // console.log("organisation url" + process.env.organisation_url);
9
15
  // console.log("test data id" + process.env.testdata_id);
10
- process.env.BUFFER = null;
11
- // console.log("process.env.BUFFER in before " + process.env.BUFFER);
12
- const jsonobject = await getDataById(process.env.organisation_url, process.env.testdata_id);
13
- if (jsonobject == null) {
14
- console.log("Test data is not available");
15
- }
16
- else {
17
- process.env.BUFFER = JSON.stringify(jsonobject);
18
- }
16
+ localStorage.setItem("EXECUTION_ID", process.env.EXECUTION_ID)
17
+ localStorage.setItem("organisation_url", process.env.organisation_url)
18
+ localStorage.setItem("SERVICE_USER", "subhra.subudhi@roboticodigital.com")
19
+ localStorage.setItem("SERVICE_PASSWORD", "V2VsY29tZUAxMjM=")
20
+
21
+ const getToken = await getLoginToken(localStorage.getItem("organisation_url"), localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD"));
22
+ process.env.LOGIN_TOKEN = getToken;
23
+ localStorage.setItem("LOGIN_TOKEN", getToken)
19
24
 
25
+ const getExeDetails = await exeDetails.getExecuitonDetails(localStorage.getItem("organisation_url"), getToken, localStorage.getItem("EXECUTION_ID"));
26
+ if (getExeDetails.automation_suite_id != null) {
27
+ const getSuiteDetail = await getSuiteDetails(localStorage.getItem("organisation_url"), getToken, getExeDetails.automation_suite_id);
28
+ if (getSuiteDetail.test_data_id != null)
29
+ {
30
+ const jsonobject = await getDataById(localStorage.getItem("organisation_url"), getSuiteDetail.test_data_id);
31
+ if (jsonobject == null) {
32
+ console.log("Test data is not available");
33
+ }
34
+ else {
35
+ localStorage.setItem("BUFFER", JSON.stringify(jsonobject))
36
+
37
+ }
38
+ }
39
+ }
20
40
  },
21
41
 
22
42
  before: function (capabilities, specs) {
@@ -57,7 +77,7 @@ const commonconfig = {
57
77
  // browser.takeScreenshot();
58
78
  // }
59
79
  },
60
-
80
+
61
81
  /**
62
82
  * Function to be executed after a test (in Mocha/Jasmine only)
63
83
  * @param {object} test test object
@@ -72,8 +92,8 @@ const commonconfig = {
72
92
  console.log(`Test '${test.title}' finished.`);
73
93
  console.log(`Duration: ${duration}ms`);
74
94
  console.log(`Passed: ${passed}`);
75
- if(passed)
76
- console.log(`Result for '${test.title}' : ${result}`);
95
+ if (passed)
96
+ console.log(`Result for '${test.title}' : ${result}`);
77
97
  if (error) {
78
98
  console.error(`Error: ${error.message}`);
79
99
  }
@@ -93,15 +113,67 @@ const commonconfig = {
93
113
  * @param {Array.<Object>} capabilities list of capabilities details
94
114
  * @param {Array.<String>} specs List of spec file paths that ran
95
115
  */
96
- after: function (result, capabilities, specs) {
116
+ after: function (result, capabilities, specs, { duration }) {
97
117
  console.log('All tests are done.');
98
- console.log(`Result: ${result === 0 ? 'Pass' : 'Fail'}`);
99
- // console.log('Capabilities:');
100
- // console.log(capabilities);
101
- // console.log('Specs:');
102
- // console.log(specs);
118
+ const resultdata = result === 0 ? 'Pass' : 'Fail';
119
+ console.log(`Result: ${resultdata}`);
120
+ console.log(`Duartion suite : ${duration}`)
121
+ const resultdetails = {}
122
+ resultdetails.excution_status = resultdata === 'Pass' ? 'PASSED' : 'FAILED'
123
+ resultdetails.excution_time = convertMillisecondsToTime(duration)
124
+ exeDetails.updateExecuitonDetails(localStorage.getItem(organisation_url), localStorage.getItem("LOGIN_TOKEN"), localStorage.getItem(EXECUTION_ID), resultdetails)
125
+
126
+ // console.log('Capabilities:');
127
+ // console.log(capabilities);
128
+ // console.log('Specs:');
129
+ // console.log(specs);
103
130
  },
104
131
 
105
132
  };
106
133
 
134
+ function convertMillisecondsToTime(msdata) {
135
+ const ms = parseInt(msdata.replace('ms', '').trim());
136
+
137
+ let seconds = Math.floor(ms / 1000);
138
+ let minutes = Math.floor(seconds / 60);
139
+ let hours = Math.floor(minutes / 60);
140
+
141
+ seconds = seconds % 60;
142
+ minutes = minutes % 60;
143
+
144
+ // Pad the values with leading zeros if they are less than 10
145
+ hours = String(hours).padStart(2, '0');
146
+ minutes = String(minutes).padStart(2, '0');
147
+ seconds = String(seconds).padStart(2, '0');
148
+
149
+ return `${hours}:${minutes}:${seconds}`;
150
+ }
151
+
152
+ // async function main() {
153
+ // try {
154
+ // const frothUrl = "devapi.frothtestops.com";
155
+ // const username = "subhra.subudhi@roboticodigital.com";
156
+ // const password = "V2VsY29tZUAxMjM=";
157
+
158
+ // const token = await getLoginToken(frothUrl, username, password);
159
+ // if (!token) {
160
+ // throw new Error('Login failed, no token obtained');
161
+ // }
162
+
163
+ // const id = 208;
164
+ // // const data = await getExecuitonDetails(frothUrl, token, id);
165
+ // // console.log("Retrieved JSON Data:", data);
166
+ // const resultdetails = {};
167
+ // const resultdata="Pass";
168
+ // const duration ="31355ms";
169
+ // resultdetails.excution_status = resultdata === 'Pass' ? 'PASSED' : 'FAILED'
170
+ // resultdetails.excution_time = convertMillisecondsToTime(duration)
171
+ // localStorage.setItem("EXECUTION_ID",208);
172
+ // await exeDetails.updateExecuitonDetails(frothUrl, token, id,resultdetails);
173
+ // } catch (error) {
174
+ // console.error('Error in main function:', error);
175
+ // }
176
+ // }
177
+
178
+ // main();
107
179
  module.exports = commonconfig;
@@ -9,7 +9,7 @@ const iosconfig = deepmerge.all([commonmobileconfig, {
9
9
  testObservability: true,
10
10
  buildName: "IOS",
11
11
  buildIdentifier: 'BUILD',
12
- browserstackLocal: true,
12
+ browserstackLocal: false,
13
13
  opts: {
14
14
  forcelocal: false,
15
15
  localIdentifier: "webdriverio-appium" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "readme": "WendriverIO Integration with [BrowserStack]",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",
@@ -35,9 +35,9 @@
35
35
  "appium-uiautomator2-driver": "^3.2.0",
36
36
  "browserstack-local": "^1.5.5",
37
37
  "deepmerge": "^4.3.1",
38
-
39
38
  "form-data": "^4.0.0",
40
39
  "node-fetch": "^3.3.2",
40
+ "node-localstorage": "^3.0.5",
41
41
  "ts-node": "^10.9.2",
42
42
  "typescript": "^5.4.5"
43
43
  }