Skip to content

Instantly share code, notes, and snippets.

@evantahler
Created March 28, 2018 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evantahler/19adb958dc5987c1723ca26564589041 to your computer and use it in GitHub Desktop.
Save evantahler/19adb958dc5987c1723ca26564589041 to your computer and use it in GitHub Desktop.
Testing Node.JS browser apps with Selenium, Async/Await, and Jest
/**
* @jest-environment jest-environment-webdriver
*/
const url = 'https://www.actionherojs.com'
describe('www.actionherojs.com#index', () => {
test('it renders', async () => {
await browser.get(url)
const title = await browser.findElement(by.tagName('h2')).getText()
expect(title).toContain('reusable, scalable, and quick')
})
test('loads the latest version number from GitHub', async () => {
const foundAndLoadedCheck = async () => {
await until.elementLocated(by.id('latestRelease'))
const value = await browser.findElement(by.id('latestRelease')).getText()
return value !== '~'
}
await browser.wait(foundAndLoadedCheck, 3000)
const latestRelease = await browser.findElement(by.id('latestRelease')).getText()
expect(latestRelease).toEqual('v18.1.3')
})
describe('save a screenshot from the browser', () => {
test('save a picture', async () => {
// files saved in ./reports/screenshots by default
await browser.get(url)
await browser.takeScreenshot()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment