froth-webdriverio-framework 1.0.91 → 1.0.93
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/commonMethods/Utils.js
CHANGED
|
@@ -7,7 +7,7 @@ let scrollToLeft = null;
|
|
|
7
7
|
let scrollToRight = null;
|
|
8
8
|
let scrollDownToView = null;
|
|
9
9
|
let scrollRightToView = null;
|
|
10
|
-
let
|
|
10
|
+
let assertText = null;
|
|
11
11
|
let connectToDB = null;
|
|
12
12
|
if (process.env.LOCATION == 'local') {
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ if (process.env.LOCATION == 'local') {
|
|
|
19
19
|
scrollToRight = require('./scrollToRight');
|
|
20
20
|
scrollDownToView = require('./scrollDownToView');
|
|
21
21
|
scrollRightToView = require('./scrollRightToView');
|
|
22
|
-
|
|
22
|
+
assertText = require('./assertText');
|
|
23
23
|
connectToDB = require('./connectToDB');
|
|
24
24
|
} else {
|
|
25
25
|
scrollToEnd = require('froth-webdriverio-framework/commonMethods/scrollToEnd');
|
|
@@ -30,7 +30,7 @@ if (process.env.LOCATION == 'local') {
|
|
|
30
30
|
scrollToRight = require('froth-webdriverio-framework/commonMethods/scrollToRight');
|
|
31
31
|
scrollDownToView = require('froth-webdriverio-framework/commonMethods/scrollDownToView');
|
|
32
32
|
scrollRightToView = require('froth-webdriverio-framework/commonMethods/scrollRightToView');
|
|
33
|
-
|
|
33
|
+
assertText = require('froth-webdriverio-framework/commonMethods/assertText');
|
|
34
34
|
connectToDB = require('froth-webdriverio-framework/commonMethods/connectToDB');
|
|
35
35
|
}
|
|
36
36
|
//export the variabels
|
|
@@ -43,6 +43,6 @@ module.exports = {
|
|
|
43
43
|
scrollToRight,
|
|
44
44
|
scrollDownToView,
|
|
45
45
|
scrollRightToView,
|
|
46
|
-
|
|
46
|
+
assertText,
|
|
47
47
|
connectToDB
|
|
48
48
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Function to verify text in Android app
|
|
2
|
-
async function
|
|
2
|
+
async function assertText(driver, elementSelector, expectedText) {
|
|
3
3
|
// try {
|
|
4
4
|
// Wait for the element to be visible
|
|
5
5
|
await driver.waitUntil(async () => {
|
|
@@ -25,6 +25,6 @@ async function verifyText(driver, elementSelector, expectedText) {
|
|
|
25
25
|
// }
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
module.exports =
|
|
28
|
+
module.exports = assertText;
|
|
29
29
|
|
|
30
30
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const dbinfo = require('../api/getDBdetails');
|
|
3
|
-
const
|
|
3
|
+
const mysqlconnect = require('../db/mysqlOperations');
|
|
4
|
+
const postgreSqlConnect = require('../db/postgresOperations');
|
|
4
5
|
const getLoginToken = require('../api/loginapi');
|
|
5
6
|
// const { LocalStorage } = require('node-localstorage');
|
|
6
7
|
// global.BUFFER = new LocalStorage('./storage');
|
|
@@ -8,22 +9,24 @@ const getLoginToken = require('../api/loginapi');
|
|
|
8
9
|
async function connectToDB(id, querytype, query) {
|
|
9
10
|
try {
|
|
10
11
|
const jsondata = await dbinfo.getDbDetails(BUFFER.getItem("ORGANISATION_DOMAIN_URL"), BUFFER.getItem("LOGIN_TOKEN"), id);
|
|
11
|
-
let connectionpool = await dbtype(jsondata
|
|
12
|
-
let result = await executeQuery(querytype, query, connectionpool);
|
|
12
|
+
let connectionpool = await dbtype(jsondata);
|
|
13
|
+
let result = await executeQuery(jsondata.database_type,querytype, query, connectionpool);
|
|
13
14
|
return result;
|
|
14
15
|
} catch (error) {
|
|
15
16
|
console.error('Error connectToDB', error);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
async function dbtype(
|
|
20
|
+
async function dbtype(jsondata) {
|
|
20
21
|
let connectionpool;
|
|
21
22
|
try {
|
|
22
|
-
switch (
|
|
23
|
+
switch (jsondata.database_type) {
|
|
23
24
|
case 'MySQL':
|
|
24
|
-
connectionpool =
|
|
25
|
+
connectionpool = mysqlconnect.connectToMySQL(jsondata.host, jsondata.username, jsondata.password, jsondata.schema_name, jsondata.port_number);
|
|
26
|
+
break;
|
|
27
|
+
case 'PostgreSQL':
|
|
28
|
+
connectionpool = postgreSqlConnect.connectToPostgreSQL(jsondata.database_type,jsondata.host, jsondata.username, jsondata.password, jsondata.schema_name, jsondata.port_number);
|
|
25
29
|
break;
|
|
26
|
-
|
|
27
30
|
default:
|
|
28
31
|
console.log('Unknown dbtype.');
|
|
29
32
|
|
|
@@ -34,18 +37,22 @@ async function dbtype(type, jsondata) {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
|
|
37
|
-
async function executeQuery(querytype, query, connectionpool) {
|
|
40
|
+
async function executeQuery(datatype,querytype, query, connectionpool) {
|
|
38
41
|
let finalResult;
|
|
39
42
|
try {
|
|
40
43
|
switch (querytype) {
|
|
41
44
|
case 'select':
|
|
42
|
-
|
|
45
|
+
if (datatype === 'MySQL') {
|
|
46
|
+
finalResult = mysqlconnect.fetchDataFromDB(connectionpool, query);
|
|
47
|
+
}else if(datatype === 'PostgreSQL'){
|
|
48
|
+
finalResult = postgreSqlConnect.fetchDataFromPostgresDB(connectionpool, query);
|
|
49
|
+
}
|
|
43
50
|
break;
|
|
44
51
|
case 'insert':
|
|
45
|
-
|
|
52
|
+
// connectionpool = mysqlconnect.connectTomysql(jsondata.hostname, jsondata.username, jsondata.password, jsondata.dbname, jsondata.portnumber);
|
|
46
53
|
break;
|
|
47
54
|
case 'update':
|
|
48
|
-
|
|
55
|
+
// connectionpool = postgreSqlConnect.fetchDataFromPostgresDB(jsondata.hostname, jsondata.username, jsondata.password, jsondata.dbname, jsondata.portnumber);
|
|
49
56
|
break;
|
|
50
57
|
default:
|
|
51
58
|
console.log('Unknown querytype.');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const mysql = require('mysql2/promise');
|
|
2
|
+
const { Pool } = require('pg');
|
|
3
|
+
|
|
4
|
+
// Function to establish connection to MySQL database
|
|
5
|
+
async function connectToMySQL(hostname, username, password, dbname, portnumber) {
|
|
6
|
+
try {
|
|
7
|
+
const poolConfig = {
|
|
8
|
+
host: hostname,
|
|
9
|
+
user: username,
|
|
10
|
+
password: password,
|
|
11
|
+
database: dbname,
|
|
12
|
+
port: portnumber,
|
|
13
|
+
waitForConnections: true,
|
|
14
|
+
connectionLimit: 10,
|
|
15
|
+
queueLimit: 0
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
let pool = mysql.createPool(poolConfig);
|
|
20
|
+
console.log('MySQL connection pool created.');
|
|
21
|
+
return pool;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error('Error creating MySQL connection pool:', error);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// Function to fetch data from the database
|
|
30
|
+
async function fetchDataFromDB(connectionpool, query) {
|
|
31
|
+
let connection = null;
|
|
32
|
+
let finalResult = null;
|
|
33
|
+
try {
|
|
34
|
+
console.log("connectionpool" + connectionpool)
|
|
35
|
+
connection = await connectionpool.getConnection();
|
|
36
|
+
|
|
37
|
+
console.log('Connected to the MySQL database.' + connection);
|
|
38
|
+
|
|
39
|
+
const [rows] = await connection.execute(query);
|
|
40
|
+
const dataArray = rows;
|
|
41
|
+
finalResult = {
|
|
42
|
+
totalNumberOfRecords: dataArray.length,
|
|
43
|
+
records: dataArray
|
|
44
|
+
};
|
|
45
|
+
console.log(JSON.stringify(finalResult, null, 2));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Error fetching data:', error);
|
|
48
|
+
} finally {
|
|
49
|
+
if (connection) {
|
|
50
|
+
connection.release();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return finalResult;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Main function to call the database connection and fetch data
|
|
57
|
+
// async function main() {
|
|
58
|
+
// try {
|
|
59
|
+
// const connection = await connectToMySQL('10.0.0.6', 'root', 'password123', 'power_seraya_step', 3406);
|
|
60
|
+
// console.log('Connection pool created.' + connection);
|
|
61
|
+
// const query = 'SELECT id,EventID,NoPlate FROM store_images limit 2';
|
|
62
|
+
// await fetchDataFromDB(connection, query);
|
|
63
|
+
// } catch (err) {
|
|
64
|
+
// console.log('Error connecting to database:', err.stack);
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
// main();
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
connectToMySQL,
|
|
72
|
+
fetchDataFromDB
|
|
73
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const { Pool } = require('pg');
|
|
2
|
+
|
|
3
|
+
// Function to establish connection to PostgreSQL database
|
|
4
|
+
async function connectToPostgreSQL(hostname, username, password, dbname, portnumber) {
|
|
5
|
+
const poolConfig = {
|
|
6
|
+
host: hostname,
|
|
7
|
+
user: username,
|
|
8
|
+
password: password,
|
|
9
|
+
database: dbname,
|
|
10
|
+
port: portnumber,
|
|
11
|
+
max: 10,
|
|
12
|
+
idleTimeoutMillis: 60000,
|
|
13
|
+
connectionTimeoutMillis: 60000,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const pool = new Pool(poolConfig);
|
|
18
|
+
console.log('PostgreSQL connection pool created.');
|
|
19
|
+
return pool;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('Error creating PostgreSQL connection pool:', error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Function to fetch data from the database
|
|
27
|
+
async function fetchDataFromPostgresDB(connectionpool, query) {
|
|
28
|
+
let connection = null;
|
|
29
|
+
let finalResult = null;
|
|
30
|
+
try {
|
|
31
|
+
|
|
32
|
+
connection = await connectionpool.connect();
|
|
33
|
+
console.log('Connected to the PostgreSQL database.' + connection);
|
|
34
|
+
const result = await connection.query(query);
|
|
35
|
+
const dataArray = result.rows; // Adjust for MySQL and PostgreSQL response formats
|
|
36
|
+
|
|
37
|
+
finalResult = {
|
|
38
|
+
totalNumberOfRecords: dataArray.length,
|
|
39
|
+
records: dataArray
|
|
40
|
+
};
|
|
41
|
+
console.log(JSON.stringify(finalResult, null, 2));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error fetching data:', error);
|
|
44
|
+
} finally {
|
|
45
|
+
if (connection) {
|
|
46
|
+
|
|
47
|
+
connection.release();
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return finalResult;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Main function to call the database connection and fetch data
|
|
55
|
+
// async function main() {
|
|
56
|
+
// try {
|
|
57
|
+
// const connection = await connectToPostgreSQL('10.0.222.36', 'postgres', 'A6b1b/b%V9', 'testops', 5432);
|
|
58
|
+
// console.log('Connection pool created.' + connection);
|
|
59
|
+
// const query = 'SELECT planned_effort,project_type,project_name FROM public.account_project_details';
|
|
60
|
+
// await fetchDataFromPostgresDB(connection, query);
|
|
61
|
+
// } catch (err) {
|
|
62
|
+
// console.log('Error connecting to database:', err.stack);
|
|
63
|
+
// }
|
|
64
|
+
// }
|
|
65
|
+
|
|
66
|
+
// main();
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
connectToPostgreSQL,
|
|
70
|
+
fetchDataFromPostgresDB
|
|
71
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froth-webdriverio-framework",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.93",
|
|
4
4
|
"readme": "WebdriverIO Integration",
|
|
5
5
|
"description": "WebdriverIO and BrowserStack App Automate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"mysql2": "^3.10.2",
|
|
40
40
|
"node-fetch": "^3.3.2",
|
|
41
41
|
"node-localstorage": "^3.0.5",
|
|
42
|
+
"pg": "^8.12.0",
|
|
42
43
|
"ts-node": "^10.9.2",
|
|
43
44
|
"typescript": "^5.4.5"
|
|
44
45
|
}
|
package/db/dbconnections.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
try {
|
|
6
|
-
const poolConfig = {
|
|
7
|
-
host: hostname, // Replace with your database host
|
|
8
|
-
user: username, // Replace with your database username
|
|
9
|
-
password: password, // Replace with your database password
|
|
10
|
-
database: dbname,
|
|
11
|
-
port: portnumber,
|
|
12
|
-
waitForConnections: true,
|
|
13
|
-
connectionLimit: 10, // Adjust the number of connections in the pool
|
|
14
|
-
queueLimit: 0 // Replace with your database name
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const pool = mysql.createPool(poolConfig);
|
|
19
|
-
console.log('Connection pool created.');
|
|
20
|
-
return pool;
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.error('Error creating connection pool:', error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
} catch (err) {
|
|
27
|
-
console.log('Error connecting to database:', err.stack);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function fetchDataFromDB(connectionpool, query) {
|
|
32
|
-
let connection = null;
|
|
33
|
-
let finalResult = null;
|
|
34
|
-
try {
|
|
35
|
-
connection = await connectionpool.getConnection();
|
|
36
|
-
console.log('Connected to the MySQL database.');
|
|
37
|
-
|
|
38
|
-
// Execute the query to fetch all data
|
|
39
|
-
const [rows] = await connection.execute(query);
|
|
40
|
-
|
|
41
|
-
// Store the data into an array
|
|
42
|
-
const dataArray = rows;
|
|
43
|
-
let recordsArray = [];
|
|
44
|
-
console.log("data is " + JSON.stringify(dataArray, null, 2));
|
|
45
|
-
// Print the values for each column in each row
|
|
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));
|
|
61
|
-
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.error('Error fetching data:', error);
|
|
64
|
-
} finally {
|
|
65
|
-
connection.release();
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return finalResult;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// write main method to call the functions
|
|
72
|
-
|
|
73
|
-
// async function main() {
|
|
74
|
-
// try {
|
|
75
|
-
// const connection = await connectTomysql('10.0.0.6', 'root', 'password123', 'power_seraya_step', 3406);
|
|
76
|
-
// const query = 'SELECT id,EventID,NoPlate FROM store_images limit 2';
|
|
77
|
-
// await fetchDataFromDB(connection, query);
|
|
78
|
-
// } catch (err) {
|
|
79
|
-
// console.log('Error connecting to database:', err.stack);
|
|
80
|
-
// }
|
|
81
|
-
// }
|
|
82
|
-
|
|
83
|
-
// main()
|
|
84
|
-
module.exports = {
|
|
85
|
-
connectTomysql,
|
|
86
|
-
fetchDataFromDB
|
|
87
|
-
};
|