使用 WatiN 处理内联 JavaScript 对话
我们当前正在为其编写测试的网站有一些 JavaScript 确认和警报对话,这些对话是在页面刷新后发生的,并且是用内联 JavaScript 编写的。例如:
<script>
if (confirm('Outcome has been saved. Click OK to create a followup appointment, or click Cancel to return to appointment outcome details.')) {
pbFup.click();
}
</script>
我们的测试脚本似乎无法处理这个问题,我无法弄清楚我们是否做错了什么,或者是否因为 WatiN 无法处理内联 JavaScript 而失败。我们的一项测试如下所示:
var confirmDialogHandler = new ConfirmDialogHandler();
using (new UseDialogOnce(IEInstance.DialogWatcher, ConfirmDialogHandler))
{
frame.Button(Find.ByName("cbnSave")).Click();
// The page should reload here.
confirmDialogHandler.WaitUntilExists();
confirmDialogHandler.OKButton.Click();
}
IEInstance.WaitForComplete();
The site that we're currently writing tests for has some JavaScript confirm and alert dialogues that happen after the page has refreshed, and are written in inline JavaScript. For example:
<script>
if (confirm('Outcome has been saved. Click OK to create a followup appointment, or click Cancel to return to appointment outcome details.')) {
pbFup.click();
}
</script>
Our test scripts don't seem to be able to handle this, and I can't figure out if we're doing something wrong, or if it's failing because WatiN can't handle the inline JavaScript. One of our tests looks like this:
var confirmDialogHandler = new ConfirmDialogHandler();
using (new UseDialogOnce(IEInstance.DialogWatcher, ConfirmDialogHandler))
{
frame.Button(Find.ByName("cbnSave")).Click();
// The page should reload here.
confirmDialogHandler.WaitUntilExists();
confirmDialogHandler.OKButton.Click();
}
IEInstance.WaitForComplete();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用了 AlertDialogHandler(),它现在对我有用。
I used AlertDialogHandler() and it's working for me now.