diff --git a/setup/devtools.js b/setup/devtools.js index 276e166..cdc2a9f 100644 --- a/setup/devtools.js +++ b/setup/devtools.js @@ -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')) diff --git a/setup/standalone.js b/setup/standalone.js index f0156b6..5bee02a 100644 --- a/setup/standalone.js +++ b/setup/standalone.js @@ -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') \ No newline at end of file diff --git a/setup/testrunner.js b/setup/testrunner.js index f129456..5103a89 100644 --- a/setup/testrunner.js +++ b/setup/testrunner.js @@ -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') }) -}) \ No newline at end of file +}) diff --git a/setup/webdriver.js b/setup/webdriver.js index 9ee1e9b..fb9eb5d 100644 --- a/setup/webdriver.js +++ b/setup/webdriver.js @@ -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'))