【问题标题】:Codeception + PhantomJS: how to open a new tab and switch to itCodeception + PhantomJS:如何打开一个新标签并切换到它
【发布时间】:2016-11-08 11:59:26
【问题描述】:

我使用 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

我的acceptance.suite.yml:

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

有人有想法吗?

【问题讨论】:

    标签: php phantomjs codeception


    【解决方案1】:

    我已经找到了解决方案,以防万一还有其他受苦的开发者灵魂:

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

    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-16
      • 1970-01-01
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多