So I'm currently trying to write some tests for a webpage in a Page Object Model format. I have a separate file for my module as shown below.
var webdriver = require('selenium-webdriver');
var by = webdriver.By;
var driver = new webdriver.Builder()
.forBrowser('phantomjs')
.build();
driver.get("my-url.com");
module.exports = {
id : function(callback){
callback = (typeof callback === 'function') ? callback : function() {};
driver.findElements(by.id("id")).then(function(element){
console.log("first in here");
driver.findElement(by.id("id")).then(function(element){
console.log("now in here");
callback(element);
});
});
}
}
This works fine as a piece standard node code such as
driver.get("my-url.com");
element.id(function(el){
el.getText().then(function(text){
console.log(text)
});
However, as soon as I put this snippit inside a mocha test suite, it suddenly breaks with a "nosuchelement" error.
test.it('Text', function(){
element.id(function(el){
el.getText().then(function(text){
console.log("Second function: " + text);
});
});
})
I've tried putting in time delays, but what I don't understand is that it makes it through the findElements line as it prints out the first line, however, it doens't get any further.
Aucun commentaire:
Enregistrer un commentaire