Tutorial: 6 - Run Your First Test

6 - Run Your First Test

There can be a bit of a learning curve when getting started with this platform - here's some step-by-step, concrete instructions to help.


Run an example

Run an example runner file, using:

$ npm run-script runner runners/configuration-files/examples/example.js

That will trigger the spec tests/examples/most-basic.spec.js to be run in Chrome on your local machine.


Make a change, then run it

In the example.js file, change the runnerConfig.runRemotely property from false to true (or add the runnerConfig.runRemotely property if it doesn't exist already), save, then run the test again with

$ npm run-script runner runners/configuration-files/examples/example.js

you'll see the test run in a single browser on Sauce Labs.


Run your own file

Please see this doc for information about where to store your own files.

After you copy the runner configuration file (from runners/configuration-files/examples/example.js) and the test file (tests/examples/most-basic.spec.js) into your own personal folders, you should update the test file path in the runner configuration file:

module.exports = {

  specs: [
    'tests/user-tests/firstname-lastname/my-first-test.spec.js' // used to be 'tests/examples/most-basic.spec.js'
  ],

  summaryReportTitle: 'Example Report',

  showDurations: true
}

There are many more advanced runner configuration options available - it could make sense to start by adding your own summaryContext string to the report as an easy step.

Now you can change your test file.

The integration runner configuration file and test file is a good source of examples, since the purpose of that test is to test everything. You can see the runner config file at runners/configuration-files/self-tests/integration-test.js, which will contain a path to the test file(s).


Write your own test

Basic Test Example

Your tests will look something like this very basic example:

// This 'suite' will do a very simple assertion on the document.title value of google.com
describe('STEP 1 - check google.com', function () {
  it('should have the right title', async function () {
    // go to google.com
    await browser.url('https://google.com')
    // after navigation is complete, get the title
    const title = await browser.getTitle()
    // take a screenshot with an explanation (Markdown supported but not used here)
    reporterHelper.takeScreenshot('Page load screenshot of Google.com')
    // ensure the title matches the expected value
    chai.expect(title).to.equal('Google')
  })
})

NOTE The STEP {number} pattern is important - that's used to recognize when to start a new step in the network capture logs, to allow step-based assertions. The example above doesn't do anything with those logs (but a real test would, in a later step).

  • describe is a Mocha 'suite'. Suites contain one or more tests.
  • it is a Mocha 'test'. Tests generally contain at least one assertion, and can contain many.
  • chai.expect(title).to.equal('Google') - this is (obviously) Chai, in Expect style.

See this doc for more detail.