File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -3525,7 +3525,11 @@ public function seeNumberOfTabs(int $number): void
35253525 */
35263526 public function closeTab (): void
35273527 {
3528+ $ currentTab = $ this ->webDriver ->getWindowHandle ();
35283529 $ prevTab = $ this ->getRelativeTabHandle (-1 );
3530+ if ($ prevTab === $ currentTab ) {
3531+ throw new ModuleException ($ this , 'Will not close the last open tab ' );
3532+ }
35293533 $ this ->webDriver ->close ();
35303534 $ this ->webDriver ->switchTo ()->window ($ prevTab );
35313535 }
@@ -3573,8 +3577,12 @@ protected function getRelativeTabHandle($offset)
35733577
35743578 $ handle = $ this ->webDriver ->getWindowHandle ();
35753579 $ handles = $ this ->webDriver ->getWindowHandles ();
3576- $ idx = array_search ($ handle , $ handles );
3577- return $ handles [($ idx + $ offset ) % count ($ handles )];
3580+ $ currentHandleIdx = array_search ($ handle , $ handles );
3581+ $ newHandleIdx = ($ currentHandleIdx + $ offset ) % count ($ handles );
3582+ if ($ newHandleIdx < 0 ) {
3583+ $ newHandleIdx = count ($ handles ) + $ newHandleIdx ;
3584+ }
3585+ return $ handles [$ newHandleIdx ];
35783586 }
35793587
35803588 /**
Original file line number Diff line number Diff line change @@ -1040,6 +1040,9 @@ public function testBrowserTabs()
10401040 $ this ->module ->switchToNextTab (2 );
10411041 $ this ->module ->seeInCurrentUrl ('example1 ' );
10421042 $ this ->module ->seeNumberOfTabs (3 );
1043+ $ this ->module ->closeTab ();
1044+ $ this ->module ->seeNumberOfTabs (2 );
1045+ $ this ->module ->closeTab ();
10431046 }
10441047
10451048 public function testPerformOnWithArray ()
You can’t perform that action at this time.
0 commit comments