I'm working on the automation of a website and i ran into a particular problem. I'm using protractor over gulp to run the automated tests and also a report generator included in the gulp task.
The issue at hand is the following: Whenever an alert is triggered by chrome, protractor stops and throws the "UnexpectedAlertOpenError" in the console, stopping the test run and canceling the report generation.
I would like to know if there is a way to make the spec fail and continue running the rest of the suite.
I know you can do this:
browser.get(url).catch(function () {
return browser.switchTo().alert().then(function (alert) {
alert.accept();
return browser.get(url);
});
});
But i don't want protractor to close the alert and continue, I would like to fail the test where it came up, and return an error message to continue with the run.
Is there any way to do that? Is it possible to pass an exception to the catch function and return a message? I could not find any documentation about that catch method.
Thank you!
EDIT: After going over the stack trace on the console, I've found that protractor detects as if the spec failed, and the exception comes from the reporter when it tries to take a screenshot (I'm using protractor-jasmine2-html-reporter) I'm going to paste a bit of the stack trace in case someone can figure out something, I'm lost really.
E/launcher - UnexpectedAlertOpenError: unexpected alert open: {Alert text : You have pending changes}
From: Task: WebDriver.takeScreenshot()
EDIT2: I found the real problem with my implementation. The npm plugin protractor-jasmine2-html-reporter (which i'm using) was trying to take a screenshot when the alert was open, causing the webdriver to break and the kept the report from being generated.
What i did to fix this was to fork from their repository and before trying to take a screenshot confirm if the alert was open and avoid taking the screenshot if it was:
function alertIsPresent() {
return browser.driver.switchTo().alert()
.then(function (alert) {
alert.accept();
return true;
}, function (err) {
return false;
});
};
In case it was open, i would close it and continue without taking the screenshot, otherwise take the screenshot. By doing this the report generates correctly and it documents that on the next spec report that there was an alert open.
Hope this is helpful to someone.
I've had a similar problem. Searched for hours and finally found this:
unexpectedAlertBehaviour: 'accept'
See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#read-write-capabilities for more information. You basically create a capabilities
object and pass the desired values into it:
capabilities: {
browserName: "chrome",
unexpectedAlertBehaviour: 'accept',
chromeOptions: {
args: ["--window-size=1920,1080", "--disable-gpu"],
},
},
Hope this helps!
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