@@ -11,26 +11,36 @@ const client = await WebDriver.newSession({
11
11
} )
12
12
13
13
await client . setTimeouts ( 2000 , 2000 , 0 )
14
- await client . navigateTo ( 'https://www.google .com/ncr ' )
14
+ await client . navigateTo ( 'https://the-internet.herokuapp .com/' )
15
15
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' ] )
19
19
}
20
20
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' ] )
25
23
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 ) )
28
34
29
35
const 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!' ) )
33
44
34
45
await client . deleteSession ( )
35
46
36
- assert . ok ( title . includes ( 'WebDriver' ) || url . includes ( 'sorry' ) )
0 commit comments