2016-11-08 8 views
0

私はCodeceptionでAcceptance Testを持っています。 PhantomJSは私のWebdriverとして設定されています。私のページには、target="_blank"のリンクがあります。問題は、私がCodeptionにそれをクリックするように指示したときに、新しく開かれたタブに焦点を合わせないことです。したがって、私のテストは失敗します。Codeception + PhantomJS:新しいタブを開き、それに切り替える方法

$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->click('My Link that opens new tab'); 

答えて

3

ソリューションは、ケースにはいくつかの他の苦しみ開発者の魂がそこにあり、私を発見した:

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

});

関連する問題