Transractor: webdriverjs commands inside sql query do not see elements

This is so strange. I have a sql query in my it () function. If I put my normal browser clicks in my it () function, but outside the sql query function, the clicks are processed without problems. But when I cut / pasted these commands and placed inside the sql query, I get the ElementNotVisibleError: element not visible. Why?

it('test1',function(){ webElem.click(); //if I put out here, I dont get error sql = "UPDATE table users set users = 1"; db.connection.query(sql, function(err, rows, fields) { if (!err) { //if I put webElem.click();in here, I get ElementNotVisibleError: element not visible } else { console.log('ERROR ' + err); } }); }); 
+4
source share
1 answer

Remember that while the protractor makes it look like the test code is synchronous, everything is asynchronous under the hood.

It is unlikely that it waiting for db.connection.query complete (this is an asynchronous interface). That way, the callback you pass that calls the transporter methods is called in a random context. (Perhaps during the next it or something --- whenever db is ready.)

If db.connection.query returns something like a promise, then you can simply return its result as a result of it , and everything should work. Otherwise, you need to wrap the db connection in a promise or use the explicit done it callback style:

 it('test1',function(done){ sql = "UPDATE table users set users = 1"; db.connection.query(sql, function(err, rows, fields) { if (!err) { // This is safe because this test won't finish until done is invoked. webElem.click(); } done(err); }); }); 
+1
source

All Articles