Skip to content

Commit f536846

Browse files
webmaster777Naktibalda
authored andcommitted
prevent closing the final tab, as it will destroy the session
1 parent 6196943 commit f536846

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
@@ -3456,10 +3456,11 @@ public function closeTab()
34563456
{
34573457
$currentTab = $this->webDriver->getWindowHandle();
34583458
$prevTab = $this->getRelativeTabHandle(-1);
3459-
$this->webDriver->close();
3460-
if ($prevTab !== $currentTab) {
3461-
$this->webDriver->switchTo()->window($prevTab);
3459+
if ($prevTab === $currentTab) {
3460+
throw new ModuleException($this, 'Will not close the last open tab');
34623461
}
3462+
$this->webDriver->close();
3463+
$this->webDriver->switchTo()->window($prevTab);
34633464
}
34643465

34653466
/**

tests/web/WebDriverTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,6 @@ public function testBrowserTabs()
10391039
$this->module->closeTab();
10401040
$this->module->seeNumberOfTabs(2);
10411041
$this->module->closeTab();
1042-
$this->module->closeTab();
10431042
}
10441043

10451044
public function testPerformOnWithArray()

0 commit comments

Comments
 (0)