I have a simple case of handling an alert with Protractor which I could not solve. I simply want to navigate to another application page after accepting the alert. I've tried the following cases which did not succeed:
(PS, if I comment out the failing tests all other tests run as expected)
(PS2, the alert is activate via a @HostListener('window:beforeunload')
annotation)
1)
const alert = await browser.get('/homepage')
.catch(function () {
return browser.switchTo().alert();
});
await alert.accept();
await browser.get('/homepage');
const url = await browser.getCurrentUrl();
expect(url).endsWith('/homepage');
await browser.get('/homepage').catch(function () {
return browser.switchTo().alert().then(function (alert) {
alert.accept();
});
});
await browser.get('/homepage');
const url = await browser.getCurrentUrl();
expect(url).endsWith('/homepage');
In this cases, the browser navigates to data:text/html,<html></html>
and I get an error like: Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:52132
3)
await browser.get('/homepage');
await browser.wait(ExpectedConditions.alertIsPresent(), 10000);
await browser.switchTo().alert().accept();
await browser.get('/homepage');
const url = await browser.getCurrentUrl();
expect(url).endsWith('/homepage');
In this case I get an error like: UnexpectedAlertOpenError: unexpected alert open: {Alert text : }
4)
browser.ignoreSynchronization = true;
await browser.get('/homepage');
await browser.wait(ExpectedConditions.alertIsPresent(), 10000);
await browser.switchTo().alert().accept();
In this case, the browser navigates to the homepage. But, subsequent tests fail with the error: Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:60759
I also tried to revert the ignoreSynchronization
to false
at the end of the test but it did not make a difference.
I run the tests by something like: npm run e2e -- --baseUrl=http://localhost:9001