Codeception + PhantomJS:如何打开一个新标签并切换到它

Codeception + PhantomJS: how to open a new tab and switch to it

我有一个使用 Codeception 的验收测试。 PhantomJS 配置为我的 Webdriver。在我的页面上,我有一个 link 有 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

我的acceptance.suite.yml:

class_name: AcceptanceTester
modules:
    enabled:
       - WebDriver
       - \Helper\Acceptance
    config:
        WebDriver:
            url: 'http://localhost'
            browser: 'phantomjs'
            port: 5555
            window_size: '1024x768'

有人知道吗?

我找到了解决方案,以防万一还有其他受苦的开发人员:

$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);

});