froth-webdriverio-framework 0.1.56 → 0.1.58
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.
- package/api/browsersatckSessionInfo.js +76 -0
- package/config/commonconfig.js +14 -10
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
async function getBSSessionDetails(sessiontype,bs_username,bs_pwd) {
|
|
3
|
+
// const sessionId = sessionIdd;
|
|
4
|
+
const username = bs_username;
|
|
5
|
+
const accessKey = bs_pwd;
|
|
6
|
+
|
|
7
|
+
const basicAuth = btoa(`${username}:${accessKey}`);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const sessionId = browser.sessionId;
|
|
12
|
+
console.log(`Session ID: ${sessionId}`);
|
|
13
|
+
|
|
14
|
+
const sessionInfo = await browser.execute(() => {
|
|
15
|
+
return window._browserstack_executor({
|
|
16
|
+
action: 'getSessionDetails'
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
console.log('BrowserStack session info:', sessionInfo);
|
|
21
|
+
|
|
22
|
+
const url = `https://api.browserstack.com/${sessiontype}/sessions/${sessionId}.json`;
|
|
23
|
+
|
|
24
|
+
const response = await fetch(url, {
|
|
25
|
+
method: 'GET',
|
|
26
|
+
headers: {
|
|
27
|
+
'Authorization': `Basic ${basicAuth}`
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (response.ok) {
|
|
32
|
+
const data = await response.json();
|
|
33
|
+
//console.log('Session Info:', data);
|
|
34
|
+
// const details = JSON.parse(data);
|
|
35
|
+
|
|
36
|
+
// Accessing the public_url property
|
|
37
|
+
const publicUrl = data.automation_session.public_url;
|
|
38
|
+
|
|
39
|
+
console.log("public url : " + publicUrl);
|
|
40
|
+
// return jsondata;
|
|
41
|
+
} else if (response.status === 401) { // Unauthorized, token expired
|
|
42
|
+
// Call login function to obtain a new token
|
|
43
|
+
// const newToken = await getLoginToken(localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD")); // You need to implement the login function
|
|
44
|
+
// Retry the request with the new token
|
|
45
|
+
// return getExecuitonDetails(frothUrl, newToken, id);
|
|
46
|
+
} else {
|
|
47
|
+
const errorText = await response.text();
|
|
48
|
+
console.error('Data fetch failed response:', errorText);
|
|
49
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error fetching data:', error);
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//Execute the main function
|
|
63
|
+
|
|
64
|
+
//Main function to execute the API call
|
|
65
|
+
// async function main() {
|
|
66
|
+
// try {
|
|
67
|
+
// localStorage.setItem("EXECUTION_SESSIONID","297666e2fd4195de98d7da3b359669072ff41a2a");
|
|
68
|
+
// await getBrowserstackDetails();
|
|
69
|
+
// } catch (error) {
|
|
70
|
+
// console.error('Error in main function:', error);
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
// main();
|
|
75
|
+
module.exports = getBSSessionDetails;
|
|
76
|
+
|
package/config/commonconfig.js
CHANGED
|
@@ -4,20 +4,22 @@ const getLoginToken = require("../api/loginapi");
|
|
|
4
4
|
const getSuiteDetails = require("../api/getsuiteDetails");
|
|
5
5
|
const { LocalStorage } = require('node-localstorage');
|
|
6
6
|
global.localStorage = new LocalStorage('./storage');
|
|
7
|
-
|
|
7
|
+
const getBSSessionDetails = require("../api/browsersatckSessionInfo")
|
|
8
8
|
// Description: This file contains the common configuration for the webdriverio framework.
|
|
9
9
|
const commonconfig = {
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
onPrepare: async function (capabilities, specs) {
|
|
13
|
-
localStorage.setItem("TOTAL_DURATION",0);
|
|
13
|
+
localStorage.setItem("TOTAL_DURATION", 0);
|
|
14
14
|
// This code runs before the test suite starts
|
|
15
15
|
// console.log("organisation url" + process.env.organisation_url);
|
|
16
16
|
// console.log("test data id" + process.env.testdata_id);
|
|
17
|
-
localStorage.setItem("EXECUTION_ID", process.env.EXECUTION_ID)
|
|
18
|
-
localStorage.setItem("organisation_url", process.env.organisation_url)
|
|
19
|
-
localStorage.setItem("SERVICE_USER", "subhra.subudhi@roboticodigital.com")
|
|
20
|
-
localStorage.setItem("SERVICE_PASSWORD", "V2VsY29tZUAxMjM=")
|
|
17
|
+
localStorage.setItem("EXECUTION_ID", process.env.EXECUTION_ID);
|
|
18
|
+
localStorage.setItem("organisation_url", process.env.organisation_url);
|
|
19
|
+
localStorage.setItem("SERVICE_USER", "subhra.subudhi@roboticodigital.com");
|
|
20
|
+
localStorage.setItem("SERVICE_PASSWORD", "V2VsY29tZUAxMjM=");
|
|
21
|
+
localStorage.setItem("BROWSERSTACK_USERNAME", "naveen_OSt3P");
|
|
22
|
+
localStorage.setItem("BROWSERSTACK_ACCESS_KEY", "V2VsY29tZUAxMjM=");
|
|
21
23
|
|
|
22
24
|
const getToken = await getLoginToken(localStorage.getItem("organisation_url"), localStorage.getItem("SERVICE_USER"), localStorage.getItem("SERVICE_PASSWORD"));
|
|
23
25
|
process.env.LOGIN_TOKEN = getToken;
|
|
@@ -26,9 +28,8 @@ const commonconfig = {
|
|
|
26
28
|
const getExeDetails = await exeDetails.getExecuitonDetails(localStorage.getItem("organisation_url"), getToken, localStorage.getItem("EXECUTION_ID"));
|
|
27
29
|
if (getExeDetails.automation_suite_id != null) {
|
|
28
30
|
const getSuiteDetail = await getSuiteDetails(localStorage.getItem("organisation_url"), getToken, getExeDetails.automation_suite_id);
|
|
29
|
-
if (getSuiteDetail.test_data_id != null)
|
|
30
|
-
|
|
31
|
-
const jsonobject = await getDataById(localStorage.getItem("organisation_url"),getToken, getSuiteDetail.test_data_id);
|
|
31
|
+
if (getSuiteDetail.test_data_id != null) {
|
|
32
|
+
const jsonobject = await getDataById(localStorage.getItem("organisation_url"), getToken, getSuiteDetail.test_data_id);
|
|
32
33
|
if (jsonobject == null) {
|
|
33
34
|
console.log("Test data is not available");
|
|
34
35
|
}
|
|
@@ -56,6 +57,9 @@ const commonconfig = {
|
|
|
56
57
|
console.log("Running suite:", suite.title);
|
|
57
58
|
console.log("Reading test data from the API");
|
|
58
59
|
|
|
60
|
+
getBSSessionDetails("app-automate", localStorage.getItem("BROWSERSTACK_USERNAME"),
|
|
61
|
+
localStorage.getItem("BROWSERSTACK_ACCESS_KEY"));
|
|
62
|
+
|
|
59
63
|
} catch (e) {
|
|
60
64
|
console.log("Error in beforeSuite:", e);
|
|
61
65
|
}
|
|
@@ -90,7 +94,7 @@ const commonconfig = {
|
|
|
90
94
|
*/
|
|
91
95
|
afterTest: function (test, context, { error, result, duration, passed, retries }) {
|
|
92
96
|
console.log(`Test '${test.title}' finished.`);
|
|
93
|
-
localStorage.setItem("TOTAL_DURATION",Number(localStorage.getItem("TOTAL_DURATION"))+duration)
|
|
97
|
+
localStorage.setItem("TOTAL_DURATION", Number(localStorage.getItem("TOTAL_DURATION")) + duration)
|
|
94
98
|
console.log(`Duration: ${duration}ms`);
|
|
95
99
|
console.log(`Passed: ${passed}`);
|
|
96
100
|
if (passed)
|