在我们的一项测试中,有时当用户尝试注销时我们会收到浏览器警报消息。
我不希望测试因这些警报而失败。当出现警报时,我们会收到以下错误:
An error was thrown in an afterAll
AfterAll Failed: unexpected alert open: {Alert text : You have unsaved changes! If you leave, your changes will be lost.}
我尝试通过以下方式解决它 1. 在conf.js 文件中添加了unexpectedAlertBehaviour: 'accept',但失败了;2、使用 if/else block 修改代码,如下所示:
exports.logOutfromESY =function(){
var G = GV;
var EC = protractor.ExpectedConditions;
expect(G.User_Menu_Dropdown.isPresent()).toBeTruthy();
G.User_Menu_Dropdown.click();
browser.wait(EC.presenceOf(G.logOut_Button), 2000, 'The Logout Buttons taking too long to appear in the DOM');
G.logOut_Button.click();
browser.sleep(500);
if(alert.isPresent()){
browser.switchTo().alert().then(function (alert) {
alert.accept();
});
}
browser.wait(EC.presenceOf(G.Email_Input_box), 3000, 'The Login Page redirection taking long time');
browser.sleep(500);
};
它也不起作用。请注意,“alert”变量是我让 Protractor 识别警报的最后努力。
有什么办法可以实现这一点吗?
最佳答案
似乎这个解决方案可能会有所帮助: https://stackoverflow.com/a/29873887/6331748
编辑:
您还可以考虑使用 --disable-notifications
标志。
您需要将其添加到您的配置文件中,如下所示:
export const config = {
capabilities: {
chromeOptions: {
args: ['--disable-notifications']
}
}
}
关于javascript - Protractor : How to detect if an unexpected alert is open,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54872824/