I want to use the browser.wait function to repeatedly check if a button element is present for a certain amount of time then use the relevant callback. Below I have the code that doesn't use the wait.
detailsButton.isPresent()
.then(function(present){
if(!present) {
callback();
} else {
callback(new Error('The details button was not present.'));
}
});
I would like some help fixing this code, as I am not sure how the wait function deals with a falure/timeout. Essentially I am asking what should be in the '.then' part of the below code that is less clunky that what I have currently.
browser.driver.wait(function(){
return pgTransactionHistory.transactionHistoryDetails.isPresent();
}, 60000).then(function(){
pgTransactionHistory.transactionHistoryDetails.isPresent()
.then(function(present){
if(!present) {
callback();
} else {
callback(new Error('The details button was not present.'));
}
});
});
Thank you!
There are two ways to do this: First you can use the third argument of browser.wait to a string that will be sent as an error message. Like so:
browser.driver.wait(function(){
return //condition
}, timeout, 'Error message string')
.then(function(){
callback();
});
Or secondly using a second argument to the .then like this:
browser.driver.wait(function(){
return //condition
}, timeout)
.then(function(){
callback();
}, function(){
//code to want to execute on failure.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With