CodeceptJS
CodeceptJS copied to clipboard
Database connectivity with codeceptjs
db_query(callback) {
db.connection.query('SELECT username FROM login WHERE _id=?',[ 1], function(err, result, fields) {
if(err) {
callback(err);
done();
return;
}
callback(null, result);
return;
});
},
logIn()
{
var that=this;
this.db_query(function(err, result) {
if(err) {
console.log(err);
}
var username = result[0].username;
I.fillField(that.fields.email, username);
console.log(username);
});
}
I am using this code to get username from database. The statement I.fillField(this.fields.email, username); executes after the complete execution of the script. i. e.
-
I am on page "/"
-
I move cursor to {"xpath":"//*[contains(@id, 'userSignInStri')]"}
-
I click "#signInBtn" Next line
-
I wait "3" √ OK in 38369ms
-
I fill field "#emailId", "[email protected]"
OK | 1 passed // 38s
Sorry I can barely understand what you try to do. I'd suggest making a custom helper for database interactions. By doing this you can synchronize your database methods with browser actions