Skip to content

Commit 38f70a6

Browse files
authored
Move tests off Google (#518)
* move test off Google to the-internet * move another flaky test off Google/DDG * moving all tests off Google * Update setup/testrunner.js * Update setup/testrunner.js
1 parent 348b409 commit 38f70a6

File tree

4 files changed

+73
-42
lines changed

4 files changed

+73
-42
lines changed

setup/devtools.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,36 @@ const client = await DevTools.newSession({
1010
}
1111
})
1212

13-
await client.navigateTo('https://www.google.com/ncr')
13+
await client.navigateTo('https://the-internet.herokuapp.com/')
1414

15-
const approveCookieBtns = await client.findElements('css selector', 'button div[role="none"]')
16-
if (approveCookieBtns.length) {
17-
await client.elementClick(approveCookieBtns[approveCookieBtns.length - 1]['element-6066-11e4-a52e-4f735466cecf'])
15+
const addRemoveElementsBtn = await client.findElements('css selector', 'a[href="/add_remove_elements/"]')
16+
if (addRemoveElementsBtn.length) {
17+
await client.elementClick(addRemoveElementsBtn[addRemoveElementsBtn.length - 1]['element-6066-11e4-a52e-4f735466cecf'])
1818
}
1919

20-
const searchInput = await client.findElement('css selector', 'textarea')
21-
await client.elementSendKeys(searchInput['element-6066-11e4-a52e-4f735466cecf'], 'DevTools')
22-
const submitBtns = await client.findElements('css selector', 'input[value="Google Search"]')
23-
await client.elementClick(submitBtns[1]['element-6066-11e4-a52e-4f735466cecf'])
20+
const addElementBtn = await client.findElement('css selector', '.example button')
21+
await client.elementClick(addElementBtn['element-6066-11e4-a52e-4f735466cecf'])
22+
23+
await client.navigateTo('https://the-internet.herokuapp.com/login')
24+
const usernameInput = await client.findElement('css selector', '#username')
25+
await client.elementSendKeys(usernameInput['element-6066-11e4-a52e-4f735466cecf'], 'tomsmith')
26+
const passwordInput = await client.findElement('css selector', '#password')
27+
await client.elementSendKeys(passwordInput['element-6066-11e4-a52e-4f735466cecf'], 'SuperSecretPassword!')
28+
const loginBtn = await client.findElement('css selector', 'button[type="submit"]')
29+
await client.elementClick(loginBtn['element-6066-11e4-a52e-4f735466cecf'])
2430

2531
// pause
26-
await new Promise((resolve) => setTimeout(resolve, 1000))
32+
await new Promise((resolve) => setTimeout(resolve, 300))
2733

28-
const title = await client.getTitle()
29-
console.log(title) // outputs "DevTools - Google Search"
3034
const url = await client.getUrl()
31-
console.log(url) // sometimes this goes to /sorry/ page as Google thinks you are a bot
35+
console.log(url)
36+
assert.ok(url.includes('secure'))
37+
38+
const youAreLoggedInBanner = await client.findElement('css selector', '#flash')
39+
const bannerText = await client.getElementText(youAreLoggedInBanner['element-6066-11e4-a52e-4f735466cecf'])
40+
console.log(bannerText) // outputs "You logged into a secure area!"
41+
42+
assert.ok(bannerText.includes('You logged into a secure area!'))
3243

3344
await client.deleteSession()
3445

35-
assert.ok(title.includes('Google Search') || url.includes('sorry'))

setup/standalone.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ const browser = await remote({
1010
}
1111
})
1212

13-
await browser.url('https://duckduckgo.com')
13+
await browser.url('https://the-internet.herokuapp.com/login')
1414

15-
await browser.$('aria/Search with DuckDuckGo').setValue('WebdriverIO')
16-
await browser.$('aria/Search').click()
15+
await browser.$('aria/Username').setValue('tomsmith')
16+
await browser.$('aria/Password').setValue('SuperSecretPassword!')
17+
await browser.$('button[type="submit"]').click()
1718

18-
const title = await browser.getTitle()
19-
console.log(title) // outputs: "WebdriverIO at DuckDuckGo"
19+
await browser.pause(300)
20+
21+
const url = await browser.getUrl()
22+
console.log(url) // outputs: "https://the-internet.herokuapp.com/secure"
23+
assert.ok(url.includes('secure'))
24+
25+
const bannerText = await browser.$('#flash').getText()
26+
console.log(bannerText) // outputs "You logged into a secure area!"
27+
28+
assert.ok(bannerText.includes('You logged into a secure area!'))
2029

2130
await browser.deleteSession()
22-
assert.equal(title, 'WebdriverIO at DuckDuckGo')

setup/testrunner.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { browser, $ } from '@wdio/globals'
22

3-
describe('DuckDuckGo search', () => {
4-
it('Searches for WebdriverIO', async () => {
5-
await browser.url('https://duckduckgo.com/')
3+
describe('the-internet login', () => {
4+
it('Logs in and assert banner text', async () => {
5+
await browser.url('https://the-internet.herokuapp.com/login')
66

7-
await browser.$('aria/Search with DuckDuckGo').setValue('WebdriverIO')
8-
await browser.$('aria/Search').click()
7+
await browser.$('aria/Username').setValue('tomsmith')
8+
await browser.$('aria/Password').setValue('SuperSecretPassword!')
9+
await browser.$('button[type="submit"]').click()
910

10-
const title = await browser.getTitle()
11-
expect(title).toBe('WebdriverIO at DuckDuckGo')
11+
await browser.pause(300)
12+
13+
const url = await browser.getUrl()
14+
expect(url).toBe('https://the-internet.herokuapp.com/secure')
1215
// or just
13-
await expect(browser).toHaveTitle('WebdriverIO at DuckDuckGo')
16+
await expect(browser).toHaveUrl('https://the-internet.herokuapp.com/secure')
1417
})
15-
})
18+
})

setup/webdriver.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,36 @@ const client = await WebDriver.newSession({
1111
})
1212

1313
await 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

2935
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!'))
3344

3445
await client.deleteSession()
3546

36-
assert.ok(title.includes('WebDriver') || url.includes('sorry'))

0 commit comments

Comments
 (0)