使用 Codeception 测试框架和 Selenium 2 模块来测试网站,我最终点击了一个超链接,该链接打开了一个没有名称的新窗口。结果是switchToWindow()
函数将不起作用,因为它正在尝试切换到父窗口(我当前所在的窗口)。如果无法切换到新窗口,我无法对其进行任何测试。
<a class="external" target="_blank" href="http://mylocalurl/the/page/im/opening">
View Live
</a>
使用 Chrome 和 Firefox 调试工具,我可以确认新窗口没有名称,但我无法给它命名,因为我无法编辑正在处理的 HTML 页面。理想情况下我会更改 HTML 以使用 javascriptonclick="window.open('http://mylocalurl/the/page/im/opening', 'myPopupWindow')
然而,这对我来说是不可能的。
我在 Selenium 论坛上四处寻找,没有任何明确的方法来解决这个问题,并且 Codeception 似乎没有太多关于这个问题的功能。
在搜索 Selenium 论坛和 @Mark Rowlands 的一些有用的产品后,我使用原始 Selenium 让它工作。
// before codeception v2.1.1, just typehint on \Webdriver
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles=$webdriver->window_handles();
$last_window = end($handles);
$webdriver->focusWindow($last_window);
});
返回父窗口很容易,因为我可以使用 Codeception 的switchToWindow
method:
$I->switchToWindow();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)