我有一个带有Codeception的验收测试。 PhantomJS配置为我的Webdriver。在我的网页上,我有一个target="_blank"
的链接。问题是,当我指示Codeception点击它时,它不会关注新打开的选项卡。因此我的测试失败了。
代码:
$I->click('My Link that opens new tab');
我尝试过:
$I->switchToWindow('Title of my new window'); // doesn't work
$I->see('Some text in my new tab'); // also doesn't work
我的接受度.site.yml:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
config:
WebDriver:
url: 'http://localhost'
browser: 'phantomjs'
port: 5555
window_size: '1024x768'
有没有人有想法?
答案 0 :(得分:3)
我找到了解决方案,万一有其他一些痛苦的开发者灵魂出现在那里:
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
});