Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions setup/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,36 @@ const client = await DevTools.newSession({
}
})

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

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

const searchInput = await client.findElement('css selector', 'textarea')
await client.elementSendKeys(searchInput['element-6066-11e4-a52e-4f735466cecf'], 'DevTools')
const submitBtns = await client.findElements('css selector', 'input[value="Google Search"]')
await client.elementClick(submitBtns[1]['element-6066-11e4-a52e-4f735466cecf'])
const addElementBtn = await client.findElement('css selector', '.example button')
await client.elementClick(addElementBtn['element-6066-11e4-a52e-4f735466cecf'])

await client.navigateTo('https://the-internet.herokuapp.com/login')
const usernameInput = await client.findElement('css selector', '#username')
await client.elementSendKeys(usernameInput['element-6066-11e4-a52e-4f735466cecf'], 'tomsmith')
const passwordInput = await client.findElement('css selector', '#password')
await client.elementSendKeys(passwordInput['element-6066-11e4-a52e-4f735466cecf'], 'SuperSecretPassword!')
const loginBtn = await client.findElement('css selector', 'button[type="submit"]')
await client.elementClick(loginBtn['element-6066-11e4-a52e-4f735466cecf'])

// pause
await new Promise((resolve) => setTimeout(resolve, 1000))
await new Promise((resolve) => setTimeout(resolve, 300))

const title = await client.getTitle()
console.log(title) // outputs "DevTools - Google Search"
const url = await client.getUrl()
console.log(url) // sometimes this goes to /sorry/ page as Google thinks you are a bot
console.log(url)
assert.ok(url.includes('secure'))

const youAreLoggedInBanner = await client.findElement('css selector', '#flash')
const bannerText = await client.getElementText(youAreLoggedInBanner['element-6066-11e4-a52e-4f735466cecf'])
console.log(bannerText) // outputs "You logged into a secure area!"

assert.ok(bannerText.includes('You logged into a secure area!'))

await client.deleteSession()

assert.ok(title.includes('Google Search') || url.includes('sorry'))
20 changes: 14 additions & 6 deletions setup/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ const browser = await remote({
}
})

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

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

const title = await browser.getTitle()
console.log(title) // outputs: "WebdriverIO at DuckDuckGo"
await browser.pause(300)

const url = await browser.getUrl()
console.log(url) // outputs: "https://the-internet.herokuapp.com/secure"
assert.ok(url.includes('secure'))

const bannerText = await browser.$('#flash').getText()
console.log(bannerText) // outputs "You logged into a secure area!"

assert.ok(bannerText.includes('You logged into a secure area!'))

await browser.deleteSession()
assert.equal(title, 'WebdriverIO at DuckDuckGo')
21 changes: 12 additions & 9 deletions setup/testrunner.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { browser, $ } from '@wdio/globals'

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

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

const title = await browser.getTitle()
expect(title).toBe('WebdriverIO at DuckDuckGo')
await browser.pause(300)

const url = await browser.getUrl()
expect(url).toBe('https://the-internet.herokuapp.com/secure')
// or just
await expect(browser).toHaveTitle('WebdriverIO at DuckDuckGo')
await expect(browser).toHaveUrl('https://the-internet.herokuapp.com/secure')
})
})
})
38 changes: 24 additions & 14 deletions setup/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,36 @@ const client = await WebDriver.newSession({
})

await client.setTimeouts(2000, 2000, 0)
await client.navigateTo('https://www.google.com/ncr')
await client.navigateTo('https://the-internet.herokuapp.com/')

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

const searchInput = await client.findElement('css selector', 'textarea')
await client.elementSendKeys(searchInput['element-6066-11e4-a52e-4f735466cecf'], 'WebDriver')
const submitBtns = await client.findElements('css selector', 'input[value="Google Search"]')
await client.elementClick(submitBtns[0]['element-6066-11e4-a52e-4f735466cecf'])
const addElementBtn = await client.findElement('css selector', '.example button')
await client.elementClick(addElementBtn['element-6066-11e4-a52e-4f735466cecf'])

// pause after clicking
await new Promise((resolve) => setTimeout(resolve, 1000))
await client.navigateTo('https://the-internet.herokuapp.com/login')
const usernameInput = await client.findElement('css selector', '#username')
await client.elementSendKeys(usernameInput['element-6066-11e4-a52e-4f735466cecf'], 'tomsmith')
const passwordInput = await client.findElement('css selector', '#password')
await client.elementSendKeys(passwordInput['element-6066-11e4-a52e-4f735466cecf'], 'SuperSecretPassword!')
const loginBtn = await client.findElement('css selector', 'button[type="submit"]')
await client.elementClick(loginBtn['element-6066-11e4-a52e-4f735466cecf'])

// pause
await new Promise((resolve) => setTimeout(resolve, 300))

const url = await client.getUrl()
console.log(url) // sometimes this goes to /sorry/ page as Google thinks you are a bot
const title = await client.getTitle()
console.log(title) // outputs "WebDriver - Google Search"
console.log(url)
assert.ok(url.includes('secure'))

const youAreLoggedInBanner = await client.findElement('css selector', '#flash')
const bannerText = await client.getElementText(youAreLoggedInBanner['element-6066-11e4-a52e-4f735466cecf'])
console.log(bannerText) // outputs "You logged into a secure area!"

assert.ok(bannerText.includes('You logged into a secure area!'))

await client.deleteSession()

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