froth-webdriverio-framework 1.0.85 → 1.0.87

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,12 +1,6 @@
1
1
 
2
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
- }
3
+
10
4
  async function getDbDetails(frothUrl,token,id) {
11
5
 
12
6
  let jsondata = {};
@@ -72,4 +66,4 @@ async function getDbDetails(frothUrl,token,id) {
72
66
  // }
73
67
 
74
68
  // main();
75
- module.exports = { connectToDB, getDbDetails }
69
+ module.exports = { getDbDetails }
@@ -55,7 +55,7 @@ async function getExecuitonDetails(frothUrl, token, id) {
55
55
 
56
56
  async function getExecuitonScriptDetails(frothUrl, token, execution_id, script_id) {
57
57
  let id;
58
- const url = `https://${frothUrl}/api/execution-script-mapping/?execution_id=${execution_id}&automation_script_id=${script_id}/`;
58
+ const url = `https://${frothUrl}/api/execution-script-mapping/?execution_id=${execution_id}&automation_script_id=${script_id}`;
59
59
 
60
60
  try {
61
61
  console.log("URL: " + url)
@@ -70,9 +70,9 @@ async function getExecuitonScriptDetails(frothUrl, token, execution_id, script_i
70
70
  });
71
71
  if (response.ok) {
72
72
  const data = await response.json();
73
- // console.log(data)
73
+ console.log(data)
74
74
  id = data[0].id;
75
-
75
+ console.log("ID is :" + id)
76
76
  // console.log("json data :" + JSON.stringify(jsondata));
77
77
 
78
78
  return id;
@@ -154,7 +154,7 @@ async function updateScriptExecutionStatus(frothUrl, token, scriptid, status) {
154
154
 
155
155
  if (scriptid != 0) {
156
156
  try {
157
- id = await getExecuitonScriptDetails(frothUrl, token, BUFFER.getItem("EXECUTION_ID"), scriptid)
157
+ const id = await getExecuitonScriptDetails(frothUrl, token, BUFFER.getItem("EXECUTION_ID"), scriptid)
158
158
  const url = `https://${frothUrl}/api/script-status-percentage/${id}/`;
159
159
  const formData = new FormData();
160
160
 
@@ -220,7 +220,7 @@ async function updateScriptExecutionStatus(frothUrl, token, scriptid, status) {
220
220
  // const duration = "31355ms"
221
221
  // resultdetails.excution_status = resultdata === 'Pass' ? 'PASSED' : 'FAILED'
222
222
  // //resultdetails.excution_time = convertMillisecondsToTime(duration)
223
- // await updateExecuitonDetails(frothUrl, token, id, resultdetails);
223
+ // await getExecuitonScriptDetails(frothUrl, token, 449, 130);
224
224
  // } catch (error) {
225
225
  // console.error('Error in main function:', error);
226
226
  // }
@@ -8,7 +8,7 @@ let scrollToRight = null;
8
8
  let scrollDownToView = null;
9
9
  let scrollRightToView = null;
10
10
  let verifyText = null;
11
-
11
+ let connectToDB=null;
12
12
  if (process.env.LOCATION == 'local') {
13
13
 
14
14
  scrollToEnd = require("./scrollToEnd");
@@ -20,16 +20,18 @@ if (process.env.LOCATION == 'local') {
20
20
  scrollDownToView = require('./scrollDownToView');
21
21
  scrollRightToView = require('./scrollRightToView');
22
22
  verifyText = require('./verifyText');
23
+ connectToDB=require('./connectToDB');
23
24
  } else {
24
- scrollToEnd = require('froth-webdriverio-framework/mobile/commonMethods/scrollToEnd');
25
- clickIfVisible = require('froth-webdriverio-framework/mobile/commonMethods/clickIfVisible');
26
- verifyTextInFieldAttribute = require('froth-webdriverio-framework/mobile/commonMethods/verifyTextInFieldAttribute');
27
- scrollToBeginning = require('froth-webdriverio-framework/mobile/commonMethods/scrollToBeginning');
28
- scrollToLeft = require('froth-webdriverio-framework/mobile/commonMethods/scrollToLeft');
29
- scrollToRight = require('froth-webdriverio-framework/mobile/commonMethods/scrollToRight');
30
- scrollDownToView = require('froth-webdriverio-framework/mobile/commonMethods/scrollDownToView');
31
- scrollRightToView = require('froth-webdriverio-framework/mobile/commonMethods/scrollRightToView');
32
- verifyText = require('froth-webdriverio-framework/mobile/commonMethods/verifyText');
25
+ scrollToEnd = require('froth-webdriverio-framework/commonMethods/scrollToEnd');
26
+ clickIfVisible = require('froth-webdriverio-framework/commonMethods/clickIfVisible');
27
+ verifyTextInFieldAttribute = require('froth-webdriverio-framework/commonMethods/verifyTextInFieldAttribute');
28
+ scrollToBeginning = require('froth-webdriverio-framework/commonMethods/scrollToBeginning');
29
+ scrollToLeft = require('froth-webdriverio-framework/commonMethods/scrollToLeft');
30
+ scrollToRight = require('froth-webdriverio-framework/commonMethods/scrollToRight');
31
+ scrollDownToView = require('froth-webdriverio-framework/commonMethods/scrollDownToView');
32
+ scrollRightToView = require('froth-webdriverio-framework/commonMethods/scrollRightToView');
33
+ verifyText = require('froth-webdriverio-framework/commonMethods/verifyText');
34
+ connectToDB=require('froth-webdriverio-framework/commonMethods/connectToDB');
33
35
  }
34
36
  //export the variabels
35
37
  module.exports= {
@@ -0,0 +1,54 @@
1
+
2
+ const dbinfo = require('../api/getDBdetails');
3
+ const dbconnect = require('../db/dbconnections');
4
+
5
+ async function connectToDB(id, querytype, query) {
6
+ try {
7
+ const jsondata = await dbinfo.getDbDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), id);
8
+ let connectionpool = await dbtype(jsondata.dbtype, jsondata);
9
+ let result = await executeQuery(querytype, query, connectionpool);
10
+ return result;
11
+ } catch (error) {
12
+ console.error('Error connectToDB', error);
13
+ }
14
+ }
15
+
16
+ async function dbtype(type, jsondata) {
17
+ let connectionpool;
18
+ try {
19
+ switch (type) {
20
+ case 'mysql':
21
+ connectionpool = dbconnect.connectTomysql(jsondata.hostname, jsondata.username, jsondata.password, jsondata.dbname, jsondata.portnumber);
22
+ break;
23
+
24
+ default:
25
+ console.log('Unknown dbtype.');
26
+
27
+ }
28
+ return connectionpool;
29
+
30
+ } catch (error) { console.error('Error dbtype', error); }
31
+ }
32
+
33
+
34
+ async function executeQuery(querytype, query, connectionpool) {
35
+ let finalResult;
36
+ try {
37
+ switch (querytype) {
38
+ case 'select':
39
+ finalResult = dbconnect.fetchDataFromDB(connectionpool, query);
40
+ break;
41
+ case 'insert':
42
+ connectionpool = dbconnect.connectTomysql(jsondata.hostname, jsondata.username, jsondata.password, jsondata.dbname, jsondata.portnumber);
43
+ break;
44
+ case 'update':
45
+ connectionpool = dbconnect.connectTomysql(jsondata.hostname, jsondata.username, jsondata.password, jsondata.dbname, jsondata.portnumber);
46
+ break;
47
+ default:
48
+ console.log('Unknown querytype.');
49
+ }
50
+ return finalResult;
51
+ } catch (error) { console.error('Error querytype', error); }
52
+ }
53
+
54
+ module.exports = connectToDB;
@@ -33,6 +33,6 @@ module.exports = getdata;
33
33
  // Example usage:
34
34
  // specify your file name
35
35
 
36
- console.log(getdata('data1.env'));
36
+ //console.log(getdata('data1.env'));
37
37
 
38
38
 
@@ -2,7 +2,6 @@ const mysql = require('mysql2/promise');
2
2
 
3
3
  // Function to establish connection to MySQL database
4
4
  async function connectTomysql(hostname, username, password, dbname, portnumber) {
5
- let connection = null;
6
5
  try {
7
6
  const poolConfig = {
8
7
  host: hostname, // Replace with your database host
@@ -27,11 +26,11 @@ async function connectTomysql(hostname, username, password, dbname, portnumber)
27
26
  } catch (err) {
28
27
  console.log('Error connecting to database:', err.stack);
29
28
  }
30
- return connection;
31
29
  }
32
30
 
33
- async function fetchDataFromSQLDB(connectionpool, query) {
31
+ async function fetchDataFromDB(connectionpool, query) {
34
32
  let connection = null;
33
+ let finalResult = null;
35
34
  try {
36
35
  connection = await connectionpool.getConnection();
37
36
  console.log('Connected to the MySQL database.');
@@ -41,15 +40,24 @@ async function fetchDataFromSQLDB(connectionpool, query) {
41
40
 
42
41
  // Store the data into an array
43
42
  const dataArray = rows;
44
-
43
+ let recordsArray = [];
44
+ console.log("data is " + JSON.stringify(dataArray, null, 2));
45
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
- });
46
+ // dataArray.forEach(row => {
47
+ // let record = {};
48
+ // Object.keys(row).forEach(columnName => {
49
+ // console.log(`${columnName}: ${row[columnName]}`);
50
+ // record[columnName] = row[columnName];
51
+ // // BUFFER.setItem(columnName, row[columnName]);
52
+ // });
53
+ // console.log('---'); // Separator for each row
54
+ // });
55
+
56
+ finalResult = {
57
+ totalNumberOfRecords: dataArray.length,
58
+ records: dataArray
59
+ };
60
+ console.log(JSON.stringify(finalResult, null, 2));
53
61
 
54
62
  } catch (error) {
55
63
  console.error('Error fetching data:', error);
@@ -57,7 +65,7 @@ async function fetchDataFromSQLDB(connectionpool, query) {
57
65
  connection.release();
58
66
 
59
67
  }
60
-
68
+ return finalResult;
61
69
  }
62
70
 
63
71
  // write main method to call the functions
@@ -65,15 +73,15 @@ async function fetchDataFromSQLDB(connectionpool, query) {
65
73
  async function main() {
66
74
  try {
67
75
  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);
76
+ const query = 'SELECT id,EventID,NoPlate FROM store_images limit 2';
77
+ await fetchDataFromDB(connection, query);
70
78
  } catch (err) {
71
79
  console.log('Error connecting to database:', err.stack);
72
80
  }
73
81
  }
74
82
 
75
83
  main()
76
- // module.exports = {
77
- // connectTomysql,
78
- // fetchDataFromSQLDB
79
- // };
84
+ module.exports = {
85
+ connectTomysql,
86
+ fetchDataFromDB
87
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",
File without changes