I wanted to fetch the data from the database and use that data to verify from my application. I got code to connect DB and fetch it but this is with individual database.js file only. The problem here is how do I call connection.query from my test case
background Using webdriverIO/Mocha framework
my Test case look like this
it(" DB Testing", () => {
console.log("DB TEST STARTED")
//I want call DB query and fetch the data, but I don't know how to do it.
db.query ('SELECT email FROM <table name> WHERE user_id =40929',[], function(results){
if (results){
console.log("RESULT"+results[0].email);
}
else{
console.log(error);
}
})
console.log("DB TEST Ended")
}
database.js file
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT email from productSolution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].email);
});
connection.end();
I did try running database.js file it worked, i mean able to fetch data from Database. But the problem here is to call this query from my test case.