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
3525
3525
*/
3526
3526
public function closeTab (): void
3527
3527
{
3528
+ $ currentTab = $ this ->webDriver ->getWindowHandle ();
3528
3529
$ prevTab = $ this ->getRelativeTabHandle (-1 );
3530
+ if ($ prevTab === $ currentTab ) {
3531
+ throw new ModuleException ($ this , 'Will not close the last open tab ' );
3532
+ }
3529
3533
$ this ->webDriver ->close ();
3530
3534
$ this ->webDriver ->switchTo ()->window ($ prevTab );
3531
3535
}
@@ -3573,8 +3577,12 @@ protected function getRelativeTabHandle($offset)
3573
3577
3574
3578
$ handle = $ this ->webDriver ->getWindowHandle ();
3575
3579
$ 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 ];
3578
3586
}
3579
3587
3580
3588
/**
Original file line number Diff line number Diff line change @@ -1040,6 +1040,9 @@ public function testBrowserTabs()
1040
1040
$ this ->module ->switchToNextTab (2 );
1041
1041
$ this ->module ->seeInCurrentUrl ('example1 ' );
1042
1042
$ this ->module ->seeNumberOfTabs (3 );
1043
+ $ this ->module ->closeTab ();
1044
+ $ this ->module ->seeNumberOfTabs (2 );
1045
+ $ this ->module ->closeTab ();
1043
1046
}
1044
1047
1045
1048
public function testPerformOnWithArray ()
You can’t perform that action at this time.
0 commit comments