CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Database connectivity with codeceptjs

Open PoojaMittal27 opened this issue 9 years ago • 1 comments

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

PoojaMittal27 avatar May 04 '17 12:05 PoojaMittal27

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

DavertMik avatar May 17 '17 23:05 DavertMik