froth-webdriverio-framework 1.0.61 → 1.0.63

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.
@@ -1,4 +1,53 @@
1
1
 
2
+ async function getBSBuildDetails(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= BUFFER.getItem("SESSION_ID");
12
+
13
+ const url = `https://api.browserstack.com/${sessiontype}/sessions/${sessionid}.json`;
14
+
15
+ const response = await fetch(url, {
16
+ method: 'GET',
17
+ headers: {
18
+ 'Authorization': `Basic ${basicAuth}`
19
+ }
20
+ });
21
+
22
+ if (response.ok) {
23
+ const data = await response.json();
24
+
25
+ // Accessing the public_url property
26
+ 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)
30
+
31
+ //return jsondata;
32
+ } else if (response.status === 401) { //
33
+ console.log("Unauthorized, token expired")
34
+
35
+ } else {
36
+ const errorText = await response.text();
37
+ console.error(`Data fetch failed response:${response.status}`);
38
+ // throw new Error(`HTTP error! status: ${response.status}`);
39
+ }
40
+
41
+
42
+
43
+ } catch (error) {
44
+ console.error('Error fetching data:', error);
45
+
46
+ }
47
+
48
+
49
+ }
50
+
2
51
  async function getBSSessionDetails(sessiontype,bs_username,bs_pwd) {
3
52
  // const sessionId = sessionIdd;
4
53
  const username = bs_username;
@@ -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,7 +59,8 @@ 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 != null) {
65
66
  formData.append('excution_status', resultdetails.excution_status);
@@ -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
- // async function main() {
54
- // try {
55
- // const frothUrl = "devapi.frothtestops.com";
56
- // const username = "subhra.subudhi@roboticodigital.com";
57
- // const password = "V2VsY29tZUAxMjM=";
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
- // const token = await getLoginToken(frothUrl, username, password);
60
- // if (!token) {
61
- // throw new Error('Login failed, no token obtained');
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
- // const id = 106;
65
- // const data = await getSuiteDetails(frothUrl, token, id);
66
- // console.log("Retrieved JSON Data:", data);
67
- // } catch (error) {
68
- // console.error('Error in main function:', error);
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
- // main();
79
+ main();
73
80
  module.exports = getSuiteDetails;
@@ -10,8 +10,8 @@ const androidConfig = deepmerge.all([commonmobileconfig, {
10
10
  'browserstack',
11
11
  {
12
12
  testObservability: true,
13
- buildName: "ANDROID BUILD",
14
- buildIdentifier: "ANDROID BUILD_" + process.env.BUILD_NUMBER,
13
+ // buildName: "ANDROID BUILD",
14
+ // buildIdentifier: "ANDROID BUILD_" + process.env.BUILD_NUMBER,
15
15
  browserstackLocal: false,
16
16
  opts: {
17
17
  forcelocal: false },
@@ -25,7 +25,9 @@ const androidConfig = deepmerge.all([commonmobileconfig, {
25
25
  deviceName: process.env.DEVICENAME,
26
26
  platformVersion: process.env.OSVERSION,
27
27
  platformName: 'android',
28
- interactiveDebugging: true
28
+ interactiveDebugging: true,
29
+ buildName: process.env.BROWSERSTACK_BUILD_NAME || 'default-build-name',
30
+
29
31
  }
30
32
  }],
31
33
  before: function (capabilities, specs) {
@@ -18,7 +18,8 @@ const commonconfig = {
18
18
  // await setAllDetails.setIntegrationsDetails();
19
19
  await setAllDetails.setSuiteDetails();
20
20
  await setAllDetails.setTestDataDetails();
21
- // console.log("ALL JSON DATA in env variable :" + JSON.stringify(process.env));
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
 
@@ -94,13 +95,18 @@ const commonconfig = {
94
95
  * @param {Array.<Object>} capabilities list of capabilities details
95
96
  * @param {Array.<String>} specs List of spec file paths that ran
96
97
  */
97
- after: function (result, capabilities, specs) {
98
+ after: async function (result, capabilities, specs) {
98
99
  console.log('All tests are done.');
99
100
  //const resultdata = result === 0 ? 'Pass' : 'Fail';
100
101
  //console.log(`Result: ${resultdata}`);
101
102
  // const resultdata = result === 0 ? 'PASSED' : 'FAILED'
102
103
  BUFFER.setItem("RESULT_DATA", result);
103
-
104
+ const resultdetails = {}
105
+ resultdetails.excution_status = BUFFER.getItem("RESULT_DATA") === 0 ? 'PASSED' : 'FAILED'
106
+ console.log("Total Duration:" + BUFFER.getItem("TOTAL_DURATION"));
107
+ resultdetails.excution_time = await secondsToTime(BUFFER.getItem("TOTAL_DURATION"))
108
+ await exeDetails.updateExecuitonDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), BUFFER.getItem("EXECUTION_ID"), resultdetails)
109
+
104
110
  },
105
111
 
106
112
  afterSession: async function (config, capabilities, specs) {
@@ -20,7 +20,7 @@ const webbsconfig = deepmerge.all([commonconfig, {
20
20
  // user: 'prabathkumar_qavxGX' || process.env.BROWSERSTACK_USERNAME,
21
21
  // key: 'RvqEi62rhwa5QwGJtweZ' || process.env.BROWSERSTACK_ACCESS_KEY,
22
22
  projectName: process.env.PROJECTNAME || "roboticodigital",
23
- buildName: 'WEB BUILD',
23
+ // buildName: 'WEB BUILD',
24
24
  buildTag: 'WEB BUILD',
25
25
  },
26
26
  }]
@@ -37,6 +37,8 @@ const webbsconfig = deepmerge.all([commonconfig, {
37
37
  resolution: '1920x1080', // Specify the screen resolution
38
38
  'browserstack.networkLogs': true, // Enable network logs
39
39
  'browserstack.video': true, // Enable video recording
40
+ buildName: process.env.BROWSERSTACK_BUILD_NAME || 'default-build-name',
41
+
40
42
  },
41
43
  // Add more capabilities for other browsers or devices as needed
42
44
  ],
@@ -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.61",
3
+ "version": "1.0.63",
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.36.1",
29
- "@wdio/browserstack-service": "^8.36.1",
30
- "@wdio/cli": "^8.36.1",
31
- "@wdio/local-runner": "^8.36.1",
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",