@@ -11,26 +11,36 @@ const client = await WebDriver.newSession({
1111} )
1212
1313await client . setTimeouts ( 2000 , 2000 , 0 )
14- await client . navigateTo ( 'https://www.google .com/ncr ' )
14+ await client . navigateTo ( 'https://the-internet.herokuapp .com/' )
1515
16- const approveCookieBtns = await client . findElements ( 'css selector' , 'button div[role="none "]' )
17- if ( approveCookieBtns . length ) {
18- await client . elementClick ( approveCookieBtns [ approveCookieBtns . length - 1 ] [ 'element-6066-11e4-a52e-4f735466cecf' ] )
16+ const addRemoveElementsBtn = await client . findElements ( 'css selector' , 'a[href="/add_remove_elements/ "]' )
17+ if ( addRemoveElementsBtn . length ) {
18+ await client . elementClick ( addRemoveElementsBtn [ addRemoveElementsBtn . length - 1 ] [ 'element-6066-11e4-a52e-4f735466cecf' ] )
1919}
2020
21- const searchInput = await client . findElement ( 'css selector' , 'textarea' )
22- await client . elementSendKeys ( searchInput [ 'element-6066-11e4-a52e-4f735466cecf' ] , 'WebDriver' )
23- const submitBtns = await client . findElements ( 'css selector' , 'input[value="Google Search"]' )
24- await client . elementClick ( submitBtns [ 0 ] [ 'element-6066-11e4-a52e-4f735466cecf' ] )
21+ const addElementBtn = await client . findElement ( 'css selector' , '.example button' )
22+ await client . elementClick ( addElementBtn [ 'element-6066-11e4-a52e-4f735466cecf' ] )
2523
26- // pause after clicking
27- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
24+ await client . navigateTo ( 'https://the-internet.herokuapp.com/login' )
25+ const usernameInput = await client . findElement ( 'css selector' , '#username' )
26+ await client . elementSendKeys ( usernameInput [ 'element-6066-11e4-a52e-4f735466cecf' ] , 'tomsmith' )
27+ const passwordInput = await client . findElement ( 'css selector' , '#password' )
28+ await client . elementSendKeys ( passwordInput [ 'element-6066-11e4-a52e-4f735466cecf' ] , 'SuperSecretPassword!' )
29+ const loginBtn = await client . findElement ( 'css selector' , 'button[type="submit"]' )
30+ await client . elementClick ( loginBtn [ 'element-6066-11e4-a52e-4f735466cecf' ] )
31+
32+ // pause
33+ await new Promise ( ( resolve ) => setTimeout ( resolve , 300 ) )
2834
2935const url = await client . getUrl ( )
30- console . log ( url ) // sometimes this goes to /sorry/ page as Google thinks you are a bot
31- const title = await client . getTitle ( )
32- console . log ( title ) // outputs "WebDriver - Google Search"
36+ console . log ( url )
37+ assert . ok ( url . includes ( 'secure' ) )
38+
39+ const youAreLoggedInBanner = await client . findElement ( 'css selector' , '#flash' )
40+ const bannerText = await client . getElementText ( youAreLoggedInBanner [ 'element-6066-11e4-a52e-4f735466cecf' ] )
41+ console . log ( bannerText ) // outputs "You logged into a secure area!"
42+
43+ assert . ok ( bannerText . includes ( 'You logged into a secure area!' ) )
3344
3445await client . deleteSession ( )
3546
36- assert . ok ( title . includes ( 'WebDriver' ) || url . includes ( 'sorry' ) )
0 commit comments