I have an Acceptance Test with Codeception. PhantomJS is configured as my Webdriver. On my page, I have a link that has target="_blank"
. The problem is, when I instruct Codeception to click on it, it does not focus on the newly opened tab. Hence my test fails.
Code:
$I->click('My Link that opens new tab');
What I have tried:
$I->switchToWindow('Title of my new window'); // doesn't work
$I->see('Some text in my new tab'); // also doesn't work
My acceptance.suite.yml:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
config:
WebDriver:
url: 'http://localhost'
browser: 'phantomjs'
port: 5555
window_size: '1024x768'
Does anyone have an idea?
I have found the solution, in case there is some other suffering developer soul out there:
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
});