Skip to content

Instantly share code, notes, and snippets.

@jtorreggiani
Last active March 1, 2019 22:51
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 jtorreggiani/efc8a6f9f4f968868456aab86c56e330 to your computer and use it in GitHub Desktop.
Save jtorreggiani/efc8a6f9f4f968868456aab86c56e330 to your computer and use it in GitHub Desktop.
Integration test boilerplate code
// Import the remote function from webdriver
import { remote } from 'webdriverio'
// Describe a basic scenario
describe('User visits home page', () => {
// Define a browser variable to be available to each
// assertion that will be declared below
let browser
// Before all the assertions we set up the browser object
// The default configuration for webdriver is async mode,
// so we will need to be defined our specs as async functions.
beforeAll(async () => {
// We declare an options object that will be used to configure
// the webdriver browser object
const options = {
// base url for the app
baseUrl: 'http://localhost:3000',
// default path the browser will open to
path: '/',
// the amount of info you want to see
// choices: "trace", "debug", "info", "warn", "error", "silent"
logLevel: 'error',
// this is where we specific the browser we want to use
// and the settings to run tests in headless mode
// commenting out "moz:firefoxOptions" will run the tests
// in your browser which you can observe go through the tests
capabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['-headless'],
}
}
}
// Call the remote function with the config options to create
// a webdriver browser object
browser = await remote(options)
// navigate to the root url
await browser.url('/')
})
afterAll(async () => {
// After all the tests close the browser session
await browser.deleteSession()
})
it('has the correct title', async () => {
await expect(browser.getTitle()).resolves.toEqual('React App')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment