1

I can share frustration with a lot of professionals about default protractor behavior on test failure - it just keeps running the tests and you have to wait until it finishes to fix the error.

I read the related posts and came across jasmine-bail-fast solution. Link to related post is provided here: Exit Protractor e2e test on fail?

However, this solution puts me on the other side of the pickle. I do NOT want to terminate the testing suite when it failed to close the confirmation message or ran into similar minor issues.

I would like to have the ability to control when to exit the script via exitonfailure() function or something similar. For instance, if had this block of code:

> browser.wait(function() 
>       return browser.isElementPresent(acceptBudgetButton);
>     }, 30000, 'Error - Unable to save budget changes because Accept Budget button is not visible. Terminating test run.');

and put exitonfailure() after this block, I want my test run to exit immediately. However, I want to test keep on running if exitonfailure() is not there.

Is there a feasible way to achieve this goal and take control of my own destiny?

Thank you for your help!

Community
  • 1
  • 1
Misha
  • 43
  • 7

1 Answers1

2

You can handle the browser.wait() success and failure cases appropriately:

var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(acceptBudgetButton), 30000).then(
    function () {
        // success
    }, 
    function () {
        // failure
        console.log('Error - Unable to save budget changes because Accept Budget button is not visible. Terminating test run.');
        jasmine.getEnv().bailFast();
    }
});

Also, look into using fail() function which fails a test.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thank you for your response - a lot of useful information! – Misha Jul 25 '16 at 18:33
  • I've tried to use fail() function without dealing with bailFast() but only with a partial success... Will provide more details via a separate question, as they will not fit in comment section... – Misha Jul 25 '16 at 18:39