如何使用 Selenium 测试模态对话框? [英] How do I test modal dialogs with Selenium?

查看:54
本文介绍了如何使用 Selenium 测试模态对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 Selenium IDE 并尝试测试一个充满模态对话框的网络应用程序(window.showModalDialog).

I'm getting started with Selenium IDE and trying to test a webapp that's full of modal dialogs (window.showModalDialog).

录制测试似乎有效(除了弹出对话框时日志中没有任何内容)但它们无法正常播放.该脚本实际上打开了窗口(由单击按钮触发),但随后只是无限期地等待.

Recording the test seems to work (except there's nothing in the log when the dialog pops up) but they don't play back properly. The script actually opens the window (triggered by a button click), but then just waits indefinitely.

有什么建议吗?

推荐答案

来自 Selenium 常见问题,Selenium 显然适用于某些类型的对话框,但不适用于其他:

From the Selenium FAQ, Selenium apparently works with some types of dialogs but not others:

我无法与弹出对话框交互.我的测试停止了!

I can't interact with a popup dialog. My test stops in its tracks!

您可以,但前提是对话框是警报或确认对话框.其他特殊对话框不能被关闭javascript,因此目前不能进行互动.这些包括保存文件"、记住密码"(Firefox) 和模态 (IE) 对话框.当它们出现时,Selenium 只能绝望地双手合十.

You can, but only if the dialog is an alert or confirmation dialog. Other special dialogs can't be dismissed by javascript, and thus currently cannot be interacted with. These include the "Save File", "Remember this Password" (Firefox), and modal (IE) dialogs. When they appear, Selenium can only wring its hands in despair.

要解决此问题,您可以使用解决方法(如果存在);除此以外你可能不得不从测试中排除你的自动化语料库.对于保存Firefox 中的文件"对话框,自定义运行时可以指定模板通过 RC 总是会导致文件下载到指定的位置,无需查询用户(看http://forums.openqa.org/thread.jspa?messageID=31350).记住此密码"对话框不应该在你之后再次出现选择记住它.目前有关于 IE 能做的并不多模态对话框.

To solve this issue, you may use a workaround (if one exists); otherwise you may have to exclude the test from your automated corpus. For the "Save File" dialog in Firefox, a custom template may be specified when running via the RC that will always cause the file to be downloaded to a specified location, without querying the user (see http://forums.openqa.org/thread.jspa?messageID=31350). The "Remember this Password" dialog should not appear again after you've chosen to remember it. Currently there is not much that can be done about IE modal dialogs.

我似乎记得有人使用 AutoHotKey 脚本解决了这个问题,该脚本关闭了对话框.

I seem to remember someone working around this with an AutoHotKey script that dismissed the dialog.

这篇关于如何使用 Selenium 测试模态对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆