Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Protractor browser.wait return if the condition never becomes true?

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!

like image 680
JasoonS Avatar asked Jun 17 '15 15:06

JasoonS


1 Answers

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.
    });
like image 82
JasoonS Avatar answered Jan 03 '23 20:01

JasoonS