I am automating an "Add Employee" form-based test for our production site. When an id is entered, or an email , or a name, that already exists, then, a service error is popped up that shows the employee cannot be registered. Even though this box comes up, the
test passes :(. I tried using the driver.switchTo().alert() function in my code. This is what happened:
A lot of times what happens is the Selenium code executes before the browser renders the alert. What I tend to do is something like this:
Alert getAlert() {
try {
Alert alert = driver.switchTo().alert();
return alert;
} catch (NoAlertPresentException e) {
// no alert to dismiss, so return null
return null;
}
}
I don't really think this is ideal, but I don't know of a better way in Selenium at the moment. I tend to just call this blindly from my tests at regular intervals, and if it returns an alert, I'll just dismiss it. If you are expecting an alert from your app and want to dismiss it before proceeding, wrap it in a while loop.
http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox
A lot of times what happens is the Selenium code executes before the browser renders the alert. What I tend to do is something like this:
Alert getAlert() {
try {
Alert alert = driver.switchTo().alert();
return alert;
} catch (NoAlertPresentException e) {
// no alert to dismiss, so return null
return null;
}
}
I don't really think this is ideal, but I don't know of a better way in Selenium at the moment. I tend to just call this blindly from my tests at regular intervals, and if it returns an alert, I'll just dismiss it. If you are expecting an alert from your app and want to dismiss it before proceeding, wrap it in a while loop.
http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox
本文探讨了在使用Selenium进行自动化测试时遇到的问题:当输入已存在的ID、邮箱或姓名时,会触发一个服务错误弹窗,而测试仍然通过。作者尝试使用driver.switchTo().alert()来捕获并处理这个警告,但因Selenium代码执行速度过快导致无法成功捕获。文章提供了一种解决方案,通过定期调用自定义函数getAlert()来检查并处理警告。
3901

被折叠的 条评论
为什么被折叠?



