froth-webdriverio-framework 1.0.86 → 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.
- package/api/getDBdetails.js +2 -8
- package/{mobile/commonMethods → commonMethods}/Utils.js +12 -10
- package/commonMethods/connectToDB.js +54 -0
- package/{mobile/commonMethods → commonMethods}/getdata.js +1 -1
- package/db/dbconnections.js +26 -18
- package/package.json +1 -1
- /package/{mobile/commonMethods → commonMethods}/clickIfVisible.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/scrollDownToView.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/scrollRightToView.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/scrollToBeginning.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/scrollToEnd.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/scrollToLeft.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/scrollToRight.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/test.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/verifyText.js +0 -0
- /package/{mobile/commonMethods → commonMethods}/verifyTextInFieldAttribute.js +0 -0
package/api/getDBdetails.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
// Function to get data from the API using the Bearer token
|
|
3
|
-
|
|
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 = {
|
|
69
|
+
module.exports = { getDbDetails }
|
|
@@ -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/
|
|
25
|
-
clickIfVisible = require('froth-webdriverio-framework/
|
|
26
|
-
verifyTextInFieldAttribute = require('froth-webdriverio-framework/
|
|
27
|
-
scrollToBeginning = require('froth-webdriverio-framework/
|
|
28
|
-
scrollToLeft = require('froth-webdriverio-framework/
|
|
29
|
-
scrollToRight = require('froth-webdriverio-framework/
|
|
30
|
-
scrollDownToView = require('froth-webdriverio-framework/
|
|
31
|
-
scrollRightToView = require('froth-webdriverio-framework/
|
|
32
|
-
verifyText = require('froth-webdriverio-framework/
|
|
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;
|
package/db/dbconnections.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
69
|
-
await
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
module.exports = {
|
|
85
|
+
connectTomysql,
|
|
86
|
+
fetchDataFromDB
|
|
87
|
+
};
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|