froth-webdriverio-framework 1.0.62 → 1.0.64
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 +60 -12
- package/api/getDBdetails.js +75 -0
- package/api/getexecutionDetails.js +4 -3
- package/api/getsuiteDetails.js +24 -17
- package/config/commonconfig.js +13 -10
- package/db/dbconnections.js +79 -0
- package/package.json +7 -5
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
async function
|
|
3
|
-
|
|
2
|
+
async function getBSBuildDetails(sessiontype, bs_username, bs_pwd) {
|
|
3
|
+
// const sessionId = sessionIdd;
|
|
4
4
|
const username = bs_username;
|
|
5
5
|
const accessKey = bs_pwd;
|
|
6
6
|
|
|
7
7
|
const basicAuth = btoa(`${username}:${accessKey}`);
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let hashed_id = null;
|
|
10
10
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const url = `https://api.browserstack.com/${sessiontype}/
|
|
11
|
+
// const sessionid= BUFFER.getItem("SESSION_ID");
|
|
12
|
+
|
|
13
|
+
const url = `https://api.browserstack.com/${sessiontype}/builds.json?name=${process.env.BROWSERSTACK_BUILD_NAME}`;
|
|
14
14
|
|
|
15
15
|
const response = await fetch(url, {
|
|
16
16
|
method: 'GET',
|
|
@@ -21,21 +21,69 @@ async function getBSSessionDetails(sessiontype,bs_username,bs_pwd) {
|
|
|
21
21
|
|
|
22
22
|
if (response.ok) {
|
|
23
23
|
const data = await response.json();
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// Accessing the public_url property
|
|
26
|
+
hashed_id = data.automation_build.hashed_id;
|
|
27
|
+
|
|
28
|
+
//return jsondata;
|
|
29
|
+
} else if (response.status === 401) { //
|
|
30
|
+
console.log("Unauthorized, token expired")
|
|
31
|
+
|
|
32
|
+
} else {
|
|
33
|
+
const errorText = await response.text();
|
|
34
|
+
console.error(`Data fetch failed response:${response.status}`);
|
|
35
|
+
// throw new Error(`HTTP error! status: ${response.status}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error('Error fetching data:', error);
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function getBSSessionDetails(sessiontype, bs_username, bs_pwd) {
|
|
49
|
+
// const sessionId = sessionIdd;
|
|
50
|
+
const username = bs_username;
|
|
51
|
+
const accessKey = bs_pwd;
|
|
52
|
+
const basicAuth = btoa(`${username}:${accessKey}`);
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
|
|
57
|
+
const hash_id=await getBSBuildDetails(sessiontype, bs_username, bs_pwd)
|
|
58
|
+
// const sessionid = BUFFER.getItem("SESSION_ID");
|
|
59
|
+
|
|
60
|
+
// const url = `https://api.browserstack.com/${sessiontype}/sessions/${sessionid}.json`;
|
|
61
|
+
const url = `https://api.browserstack.com/${sessiontype}/builds/${hash_id}/sessions.json`;
|
|
62
|
+
|
|
63
|
+
const response = await fetch(url, {
|
|
64
|
+
method: 'GET',
|
|
65
|
+
headers: {
|
|
66
|
+
'Authorization': `Basic ${basicAuth}`
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (response.ok) {
|
|
71
|
+
const data = await response.json();
|
|
72
|
+
|
|
25
73
|
// Accessing the public_url property
|
|
26
74
|
const publicUrl = data.automation_session.public_url;
|
|
27
|
-
const duration=data.automation_session.duration;
|
|
28
|
-
BUFFER.setItem("REPORT_URL",publicUrl)
|
|
29
|
-
BUFFER.setItem("TOTAL_DURATION",duration)
|
|
75
|
+
const duration = data.automation_session.duration;
|
|
76
|
+
BUFFER.setItem("REPORT_URL", publicUrl)
|
|
77
|
+
BUFFER.setItem("TOTAL_DURATION", duration)
|
|
30
78
|
|
|
31
79
|
//return jsondata;
|
|
32
80
|
} else if (response.status === 401) { //
|
|
33
81
|
console.log("Unauthorized, token expired")
|
|
34
|
-
|
|
82
|
+
|
|
35
83
|
} else {
|
|
36
84
|
const errorText = await response.text();
|
|
37
85
|
console.error(`Data fetch failed response:${response.status}`);
|
|
38
|
-
|
|
86
|
+
// throw new Error(`HTTP error! status: ${response.status}`);
|
|
39
87
|
}
|
|
40
88
|
|
|
41
89
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
// Function to get data from the API using the Bearer token
|
|
3
|
+
async function connectToDB(id, querytype, query) {
|
|
4
|
+
try {
|
|
5
|
+
const jsondata = await getDbDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"),BUFFER.getItem("LOGIN_TOKEN"),id);
|
|
6
|
+
} catch (error) {
|
|
7
|
+
console.error('Error connectToDB', error);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
async function getDbDetails(frothUrl,token,id) {
|
|
11
|
+
|
|
12
|
+
let jsondata = {};
|
|
13
|
+
if (id != 0 || id != null || id != undefined) {
|
|
14
|
+
const url = `https://${frothUrl}/api/automationsuite-retrieve/${id}/`;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
console.log("URL: " + url)
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
method: 'GET',
|
|
20
|
+
headers: {
|
|
21
|
+
'Authorization': `Bearer ${token}`,
|
|
22
|
+
'Content-Type': 'application/json'
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (response.ok) {
|
|
27
|
+
jsondata = await response.json();
|
|
28
|
+
|
|
29
|
+
return jsondata;
|
|
30
|
+
|
|
31
|
+
} else if (response.status === 401) { // Unauthorized, token expired
|
|
32
|
+
// Call login function to obtain a new token
|
|
33
|
+
const newToken = await getLoginToken(BUFFER.getItem("SERVICE_USER"), BUFFER.getItem("SERVICE_PASSWORD")); // You need to implement the login function
|
|
34
|
+
// Retry the request with the new token
|
|
35
|
+
return getDbDetails(frothUrl, newToken, id);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const errorText = await response.text();
|
|
39
|
+
console.error(`Data fetch failed response: ${response.status}`);
|
|
40
|
+
// throw new Error(`HTTP error! status: ${response.status}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('Error fetching data:', error);
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
console.error('Error fetching data: Invalid ID or no suite id is linked to execution');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// async function main() {
|
|
56
|
+
// try {
|
|
57
|
+
// const frothUrl = "devapi.frothtestops.com";
|
|
58
|
+
// const username = "subhra.subudhi@roboticodigital.com";
|
|
59
|
+
// const password = "V2VsY29tZUAxMjM=";
|
|
60
|
+
|
|
61
|
+
// const token = await getLoginToken(frothUrl, username, password);
|
|
62
|
+
// if (!token) {
|
|
63
|
+
// throw new Error('Login failed, no token obtained');
|
|
64
|
+
// }
|
|
65
|
+
|
|
66
|
+
// const id = 106;
|
|
67
|
+
// const data = await getSuiteDetails(frothUrl, token, id);
|
|
68
|
+
// console.log("Retrieved JSON Data:", data);
|
|
69
|
+
// } catch (error) {
|
|
70
|
+
// console.error('Error in main function:', error);
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
// main();
|
|
75
|
+
module.exports = { connectToDB, getDbDetails }
|
|
@@ -59,9 +59,10 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
|
|
|
59
59
|
const formData = new FormData();
|
|
60
60
|
try {
|
|
61
61
|
console.log("URL" + url)
|
|
62
|
-
|
|
62
|
+
console.log("resultdetails" + JSON.stringify(resultdetails))
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
if (resultdetails.excution_status != null) {
|
|
65
66
|
formData.append('excution_status', resultdetails.excution_status);
|
|
66
67
|
}
|
|
67
68
|
if (resultdetails.excution_time != null) {
|
|
@@ -90,7 +91,7 @@ async function updateExecuitonDetails(frothUrl, token, id, resultdetails) {
|
|
|
90
91
|
return updateExecuitonDetails(frothUrl, newToken, id, resultdetails);
|
|
91
92
|
} else {
|
|
92
93
|
const errorText = await response.text();
|
|
93
|
-
console.error(`
|
|
94
|
+
console.error(`error in updating the status into DB ${response.status}`);
|
|
94
95
|
// throw new Error(`HTTP error! status: ${response.status}`);
|
|
95
96
|
}
|
|
96
97
|
|
package/api/getsuiteDetails.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
const getLoginToken=require('./loginapi')
|
|
2
3
|
// Function to get data from the API using the Bearer token
|
|
3
4
|
async function getSuiteDetails(frothUrl, token, id) {
|
|
4
5
|
let jsondata = {};
|
|
@@ -22,6 +23,11 @@ async function getSuiteDetails(frothUrl, token, id) {
|
|
|
22
23
|
jsondata.automation_suite_name = data.automation_suite_name;
|
|
23
24
|
jsondata.test_data_id = data.test_data_id;
|
|
24
25
|
jsondata.browser_stack_urls = data.browser_stack_urls;
|
|
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)
|
|
30
|
+
|
|
25
31
|
// console.log("json data :" + JSON.stringify(jsondata));
|
|
26
32
|
|
|
27
33
|
return jsondata;
|
|
@@ -50,24 +56,25 @@ async function getSuiteDetails(frothUrl, token, id) {
|
|
|
50
56
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
async function main() {
|
|
60
|
+
try {
|
|
61
|
+
const frothUrl = "devapi.frothtestops.com";
|
|
62
|
+
const username = "subhra.subudhi@roboticodigital.com";
|
|
63
|
+
const password = "V2VsY29tZUAxMjM=";
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
const token = await getLoginToken(frothUrl, username, password);
|
|
66
|
+
if (!token) {
|
|
67
|
+
throw new Error('Login failed, no token obtained');
|
|
68
|
+
}
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const id = 147;
|
|
71
|
+
const data = await getSuiteDetails(frothUrl, token, id);
|
|
72
|
+
console.log("Retrieved JSON Data:", data);
|
|
73
|
+
console.log(data.automation_script_id[0].automation_script_id)
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Error in main function:', error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
71
78
|
|
|
72
|
-
|
|
79
|
+
main();
|
|
73
80
|
module.exports = getSuiteDetails;
|
package/config/commonconfig.js
CHANGED
|
@@ -18,7 +18,8 @@ const commonconfig = {
|
|
|
18
18
|
// await setAllDetails.setIntegrationsDetails();
|
|
19
19
|
await setAllDetails.setSuiteDetails();
|
|
20
20
|
await setAllDetails.setTestDataDetails();
|
|
21
|
-
|
|
21
|
+
console.log(JSON.stringify(capabilities))
|
|
22
|
+
// console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
|
|
22
23
|
},
|
|
23
24
|
|
|
24
25
|
|
|
@@ -29,10 +30,9 @@ const commonconfig = {
|
|
|
29
30
|
beforeSuite: async function (suite) {
|
|
30
31
|
try {
|
|
31
32
|
console.log("Running suite:", suite.title);
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
// const sessionId = browser.sessionId;
|
|
34
|
+
// BUFFER.setItem("SESSION_ID", sessionId)
|
|
34
35
|
await getBSSessionDetails(process.env.BS_SESSION_TYPE, process.env.BROWSERSTACK_USERNAME, Buffer.from(process.env.BROWSERSTACK_ACCESS_KEY, 'base64').toString('utf-8'));
|
|
35
|
-
// console.log("ALL JSON DATA IN BUFFER:" + JSON.stringify(BUFFER));
|
|
36
36
|
const resultdetails = {};
|
|
37
37
|
exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), BUFFER.getItem("EXECUTION_ID"), resultdetails)
|
|
38
38
|
|
|
@@ -70,7 +70,7 @@ const commonconfig = {
|
|
|
70
70
|
*/
|
|
71
71
|
afterTest: function (test, context, { error, result, duration, passed, retries }) {
|
|
72
72
|
console.log(`Test '${test.title}' finished.`);
|
|
73
|
-
|
|
73
|
+
// BUFFER.setItem("TOTAL_DURATION", Number(BUFFER.getItem("TOTAL_DURATION")) + duration)
|
|
74
74
|
console.log(`Duration: ${duration}ms`);
|
|
75
75
|
console.log(`Passed: ${passed}`);
|
|
76
76
|
if (passed)
|
|
@@ -94,13 +94,16 @@ const commonconfig = {
|
|
|
94
94
|
* @param {Array.<Object>} capabilities list of capabilities details
|
|
95
95
|
* @param {Array.<String>} specs List of spec file paths that ran
|
|
96
96
|
*/
|
|
97
|
-
after: function (result, capabilities, specs) {
|
|
97
|
+
after: async function (result, capabilities, specs) {
|
|
98
98
|
console.log('All tests are done.');
|
|
99
|
-
//const resultdata = result === 0 ? 'Pass' : 'Fail';
|
|
100
|
-
//console.log(`Result: ${resultdata}`);
|
|
101
|
-
// const resultdata = result === 0 ? 'PASSED' : 'FAILED'
|
|
102
99
|
BUFFER.setItem("RESULT_DATA", result);
|
|
103
|
-
|
|
100
|
+
const resultdetails = {}
|
|
101
|
+
resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") === 0 ? 'PASSED' : 'FAILED'
|
|
102
|
+
console.log("Total Duration:" + BUFFER.getItem("TOTAL_DURATION"));
|
|
103
|
+
console.log("Results" + resultdetails.excution_status);
|
|
104
|
+
resultdetails.excution_time = await secondsToTime(BUFFER.getItem("TOTAL_DURATION"))
|
|
105
|
+
await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), BUFFER.getItem("EXECUTION_ID"), resultdetails)
|
|
106
|
+
|
|
104
107
|
},
|
|
105
108
|
|
|
106
109
|
afterSession: async function (config, capabilities, specs) {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const mysql = require('mysql2/promise');
|
|
2
|
+
|
|
3
|
+
// Function to establish connection to MySQL database
|
|
4
|
+
async function connectTomysql(hostname, username, password, dbname, portnumber) {
|
|
5
|
+
let connection = null;
|
|
6
|
+
try {
|
|
7
|
+
const poolConfig = {
|
|
8
|
+
host: hostname, // Replace with your database host
|
|
9
|
+
user: username, // Replace with your database username
|
|
10
|
+
password: password, // Replace with your database password
|
|
11
|
+
database: dbname,
|
|
12
|
+
port: portnumber,
|
|
13
|
+
waitForConnections: true,
|
|
14
|
+
connectionLimit: 10, // Adjust the number of connections in the pool
|
|
15
|
+
queueLimit: 0 // Replace with your database name
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const pool = mysql.createPool(poolConfig);
|
|
20
|
+
console.log('Connection pool created.');
|
|
21
|
+
return pool;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error('Error creating connection pool:', error);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.log('Error connecting to database:', err.stack);
|
|
29
|
+
}
|
|
30
|
+
return connection;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function fetchDataFromSQLDB(connectionpool, query) {
|
|
34
|
+
let connection = null;
|
|
35
|
+
try {
|
|
36
|
+
connection = await connectionpool.getConnection();
|
|
37
|
+
console.log('Connected to the MySQL database.');
|
|
38
|
+
|
|
39
|
+
// Execute the query to fetch all data
|
|
40
|
+
const [rows] = await connection.execute(query);
|
|
41
|
+
|
|
42
|
+
// Store the data into an array
|
|
43
|
+
const dataArray = rows;
|
|
44
|
+
|
|
45
|
+
// Print the values for each column in each row
|
|
46
|
+
dataArray.forEach(row => {
|
|
47
|
+
Object.keys(row).forEach(columnName => {
|
|
48
|
+
console.log(`${columnName}: ${row[columnName]}`);
|
|
49
|
+
// BUFFER.setItem(columnName, row[columnName]);
|
|
50
|
+
});
|
|
51
|
+
console.log('---'); // Separator for each row
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error fetching data:', error);
|
|
56
|
+
} finally {
|
|
57
|
+
connection.release();
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// write main method to call the functions
|
|
64
|
+
|
|
65
|
+
async function main() {
|
|
66
|
+
try {
|
|
67
|
+
const connection = await connectTomysql('10.0.0.6', 'root', 'password123', 'power_seraya_step', 3406);
|
|
68
|
+
const query = 'SELECT EventID,NoPlate FROM store_images limit 1';
|
|
69
|
+
await fetchDataFromSQLDB(connection, query);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log('Error connecting to database:', err.stack);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
main()
|
|
76
|
+
// module.exports = {
|
|
77
|
+
// connectTomysql,
|
|
78
|
+
// fetchDataFromSQLDB
|
|
79
|
+
// };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froth-webdriverio-framework",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.64",
|
|
4
4
|
"readme": "WebdriverIO Integration",
|
|
5
5
|
"description": "WebdriverIO and BrowserStack App Automate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"appium"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@wdio/appium-service": "^8.
|
|
29
|
-
"@wdio/browserstack-service": "^
|
|
30
|
-
"@wdio/cli": "^
|
|
31
|
-
"@wdio/local-runner": "^
|
|
28
|
+
"@wdio/appium-service": "^8.0.9",
|
|
29
|
+
"@wdio/browserstack-service": "^7.16.4",
|
|
30
|
+
"@wdio/cli": "^7.16.4",
|
|
31
|
+
"@wdio/local-runner": "^7.16.4",
|
|
32
32
|
"@wdio/mocha-framework": "^8.36.1",
|
|
33
33
|
"@wdio/spec-reporter": "^8.36.1",
|
|
34
34
|
"appium": "^2.5.4",
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"browserstack-local": "^1.5.5",
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
38
|
"form-data": "^4.0.0",
|
|
39
|
+
"mysql": "^2.18.1",
|
|
40
|
+
"mysql2": "^3.10.2",
|
|
39
41
|
"node-fetch": "^3.3.2",
|
|
40
42
|
"node-localstorage": "^3.0.5",
|
|
41
43
|
"ts-node": "^10.9.2",
|