使用 Selenium 处理浏览器弹出窗口
我们正在针对现有代码库运行 Selenium 回归测试,并且我们的 Web 应用程序中的某些屏幕使用弹出窗口作为中间步骤。
目前我们在测试中使用以下命令:
// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");
...大部分时间都有效。 有时,测试会在 waitForPopUp()
行上失败,并显示“
com.thoughtworks.selenium.SeleniumException: Permission denied
谁能建议一个更好、更可靠的方法?”
此外,我们主要在 IE6 和 7 上运行这些测试。
We are running Selenium regression tests against our existing code base, and certain screens in our web app use pop-ups for intermediate steps.
Currently we use the commands in the test:
// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");
...which works most of the time. Occasionally the test will fail on the waitForPopUp()
line with
com.thoughtworks.selenium.SeleniumException: Permission denied
Can anyone suggest a better, more reliable method?
Also, we primarily run these tests on IE6 and 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我需要在弹出窗口中选择一个 iframe 并填写表格。
我在使用 selectWindow cmd 时遇到问题,其中 selenium 无法找到我的 iframe,因此我删除了该命令。
这个 Selenese 对我来说效果很好(其中 iframe 标题和 id = account_frame):
I needed to select an iframe within a popup window and fill out a form.
I had trouble using the selectWindow cmd where selenium couldn't find my iframe, so I removed the command.
This selenese worked well for me (where the iframe title and id = account_frame) :
尝试在导致问题的调用周围添加一些等待语句。
我以前也遇到过同样的错误,我能够可靠解决这些错误的唯一方法是调用 System.Threading.Thread.Sleep(5000)..
Try adding some wait statements around the calls that are causing you issues.
I've had the same errors before and the only way I was able to reliably resolve them was by making calls to System.Threading.Thread.Sleep(5000)..
如果您在 *iehta 模式下运行,那么您将会在这里或那里遇到一些故障。 我们在工作中运行 Selenium,并且 IE 和 AJAX 似乎存在很多问题。
然而,听起来您遇到的问题是 Selenium 试图在完全加载之前访问另一个窗口中的组件。 我不确定您的默认超时范围设置为多少,但您可能需要尝试将其增加到 60 (60000ms) 秒左右以解决该问题。
除此之外,我建议在 Firefox 中运行测试(使用 *chrome),因为它会产生更可靠的结果,但有时由于业务需求,这是不可能的。
If you are running in *iehta mode then you are going to run into some glitches here and there. We run Selenium at my job and there seem to be lots of issues with IE and AJAX.
However, it sounds like the issue you are running into is one where Selenium is trying to access a component in another window before it completely loads up. I am not sure what your default timeout range is set to, but you may want to try increasing it to 60 (60000ms) seconds or so to get past the issue.
Other than that I would suggest running your tests in Firefox (using *chrome) as it produces much more reliable results, but sometimes it is simply not possible due to business requirements.
有用!! 只是为了让那些喜欢 Selenese 的人更容易。
这对我使用 IE7(正常模式)有用。
真是太麻烦了。 感谢天空中的意大利面怪物,否则我不可能在 IE 中运行它。
It works!! Just to make it easier for the folks who prefer selenese.
This worked for me using IE7(normal mode).
What a freaking hassle. Thank the spaghetti monster in the sky for SO or there is no way I would have got this working in IE.
我刚刚尝试添加另一个 selenium 函数
windowFocus()
:当我在本地运行它时测试成功,但仅限于所有这些方法调用 - create/focus/wait/select。
我即将让构建服务器运行所有测试,如果也成功,我将用它创建一个库函数......!
I just trialled adding another selenium function,
windowFocus()
:The test succeeded when I ran it locally, but only with all those method calls - create/focus/wait/select.
I'm about to let the build server run all the tests, and if that succeeds too, I'll be making a library function out of it...!