使用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上运行这些测试。
解决方案
如果我们以* iehta模式运行,那么我们将在这里和那里遇到一些故障。我们在工作中运行Selenium,而IE和AJAX似乎有很多问题。
但是,听起来我们遇到的问题是Selenium在完全加载之前试图访问另一个窗口中的组件。我不确定默认超时范围设置为什么,但是我们可能想要尝试将其增加到60(60000ms)秒左右以解决问题。
除此之外,我建议我们在Firefox(使用* chrome)中运行测试,因为它会产生更加可靠的结果,但是有时由于业务需求而根本无法实现。
我刚刚尝试添加另一个硒功能,windowFocus():
// 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().windowFocus("enquiryPopup");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");
当我在本地运行该测试时,该测试成功,但是仅使用所有这些方法调用create / focus / wait / select。
我将让构建服务器运行所有测试,如果也能成功,我将使用它做一个库函数...!
尝试在引起问题的调用周围添加一些等待语句。
我之前遇到过相同的错误,并且能够可靠地解决这些错误的唯一方法是调用System.Threading.Thread.Sleep(5000)。
有用!!只是为了让那些喜欢硒的人们更容易。
这对我使用IE7(正常模式)有效。
真是太麻烦了。感谢天空中的意大利面条怪兽,否则我将无法在IE中正常工作。
<tr>
<td>getEval</td>
<td>selenium.browserbot.getCurrentWindow().open('', 'windowName');</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>buttonName</td>
<td></td>
</tr>
<tr>
<td>windowFocus</td>
<td>windowName</td>
<td></td>
</tr>
<tr>
<td>waitForPopUp</td>
<td>windowName</td>
<td>3000</td>
</tr>
<tr>
<td>selectWindow</td>
<td>windowName</td>
<td></td>
</tr>
我需要在弹出窗口中选择一个iframe并填写表格。
我在硒无法找到我的iframe的地方使用selectWindow cmd遇到麻烦,因此我删除了该命令。
这个硒对我来说效果很好(iframe标题和ID = account_frame):
<tr> <td>click</td> <td>//a[@class='item_add']</td> <td></td> </tr> <tr> <td>windowFocus</td> <td>account_frame</td> <td></td> </tr> <tr> <td>waitForPopUp</td> <td>account_frame</td> <td>10000</td> </tr>

