Skip to content

Commit 6374d5f

Browse files
committed
prevent closing the final tab, as it will destroy the session
1 parent 69a4e35 commit 6374d5f

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
@@ -3529,10 +3529,11 @@ public function closeTab(): void
35293529
{
35303530
$currentTab = $this->webDriver->getWindowHandle();
35313531
$prevTab = $this->getRelativeTabHandle(-1);
3532-
$this->webDriver->close();
3533-
if ($prevTab !== $currentTab) {
3534-
$this->webDriver->switchTo()->window($prevTab);
3532+
if ($prevTab === $currentTab) {
3533+
throw new ModuleException($this, 'Will not close the last open tab');
35353534
}
3535+
$this->webDriver->close();
3536+
$this->webDriver->switchTo()->window($prevTab);
35363537
}
35373538

35383539
/**

tests/web/WebDriverTest.php

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

10341033
public function testPerformOnWithArray()

0 commit comments

Comments
 (0)