File tree 1 file changed +25
-0
lines changed
examples/javascript/test/interactions
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -60,4 +60,29 @@ describe('Interactions - Windows', function () {
60
60
base64Code = encodedString . slice ( startIndex , endIndex )
61
61
assert . strictEqual ( base64Code , imgMagicNumber )
62
62
} ) ;
63
+
64
+ it ( 'Should be able to switch to newWindow and newTab and close' , async function ( ) {
65
+ await driver . get ( 'https://www.selenium.dev/selenium/web/' ) ;
66
+ const initialWindow = await driver . getAllWindowHandles ( ) ;
67
+ assert . strictEqual ( initialWindow . length , 1 )
68
+
69
+ // Opens a new tab and switches to new tab
70
+ await driver . switchTo ( ) . newWindow ( 'tab' ) ;
71
+ const browserTabs = await driver . getAllWindowHandles ( ) ;
72
+ assert . strictEqual ( browserTabs . length , 2 )
73
+
74
+ // Opens a new window and switches to new window
75
+ await driver . switchTo ( ) . newWindow ( 'window' ) ;
76
+ const windows = await driver . getAllWindowHandles ( ) ;
77
+ assert . strictEqual ( windows . length , 3 )
78
+
79
+ //Close the tab or window
80
+ await driver . close ( ) ;
81
+
82
+ //Switch back to the old tab or window
83
+ await driver . switchTo ( ) . window ( windows [ 1 ] ) ;
84
+
85
+ const windowsAfterClose = await driver . getAllWindowHandles ( ) ;
86
+ assert . strictEqual ( windowsAfterClose . length , 2 ) ;
87
+ } ) ;
63
88
} ) ;
You can’t perform that action at this time.
0 commit comments