I have a test for PHP project which opens a new tab by double-click. I test it in Firefox.
I am new to Codeception, but I've read and tried everything I've found with no luck.
I have a table which rows are spans. I want to double-click it and to check if correct page is open.
I try:
$i->scrollTo(['xpath' => '//span[text()="test"]']);
$i->doubleClick(['xpath' => '//span[text()="test"]']);
$i->waitForText("test text", 15);
$i->seeCurrentUrlMatches('~^/register/materials/view/\d+$~');
The issue is that doubleClick opens a requested page in new tab like this:
jumpTo: function(row) {
const link = document.createElement('a');
link.href = window.location.pathname + '/view/' + row.id;
link.setAttribute('target', '_blank');
document.body.appendChild(link);
link.click();
},
If I try to run this test as is - it starts, double-clicks span, then new tab opens, focus switches to it, I see correct page and test text on it, but test fails because it does not see requested text because it seems that though I see that tab changed the WebDriver remains on first tab.
I tried switchToNextTab() - it does not work. Sometimes switchToNextTab() 3 times in a row works, sometimes not. I tried reloadPage() - it reloads first tab, not the one recently opened. I tried
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles=$webdriver->window_handles();
$last_window = end($handles);
$webdriver->focusWindow($last_window);
});
and it seems that there is one currently active window in terms of this method ($handles is an array of 1 element).
I tried closeTab() - it closes entire Firefox instance.
How can I programmatically change active tab?