Skip to content

Commit f91575c

Browse files
webmaster777Naktibalda
authored andcommitted
prevent closing the final tab, as it will destroy the session
1 parent 1563c11 commit f91575c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Codeception/Module/WebDriver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,10 +3507,11 @@ public function closeTab(): void
35073507
{
35083508
$currentTab = $this->webDriver->getWindowHandle();
35093509
$prevTab = $this->getRelativeTabHandle(-1);
3510-
$this->webDriver->close();
3511-
if ($prevTab !== $currentTab) {
3512-
$this->webDriver->switchTo()->window($prevTab);
3510+
if ($prevTab === $currentTab) {
3511+
throw new ModuleException($this, 'Will not close the last open tab');
35133512
}
3513+
$this->webDriver->close();
3514+
$this->webDriver->switchTo()->window($prevTab);
35143515
}
35153516

35163517
/**

tests/web/WebDriverTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,6 @@ public function testBrowserTabs()
10271027
$this->module->closeTab();
10281028
$this->module->seeNumberOfTabs(2);
10291029
$this->module->closeTab();
1030-
$this->module->closeTab();
10311030
}
10321031

10331032
public function testPerformOnWithArray()

0 commit comments

Comments
 (0)