I am running multiple cases using --suites config in protractor. I have to launch my webapp newly for each case but my app is having an alert which will be pop out for the confirmation [Stay on this page or Leave the page] whenever the page reloads or closed. In that case protractor throws an error
WARN - Exception: unexpected alert open:
Thanks in advance.
Switch to the alert and accept it:
browser.switchTo().alert().accept();
This though might not work in Chrome, in this case you can do:
browser.executeScript("window.onbeforeunload = function(e){};");
No of the found solutions had worked for me until I found a snippet in a Protractor thread. This:
browser.get(url).catch(function () {
    return browser.switchTo().alert().then(function (alert) {
        alert.accept();
        return browser.get(url);
    });
});
I hope this solution works for someone who, like me, was already desperate :P
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