Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Set up parallel continuous testing

Matti Schneider edited this page Mar 29, 2017 · 4 revisions

We will use SauceLabs and CircleCI to automate continuous integration testing with Watai. SauceLabs is free for open-source projects.

  1. Create a new (machine) user on GitHub.
  2. Give it access to the repo you want to test.
  3. Create a new Open Sauce account, logging in with that machine user.
  4. Add repo to CircleCI.
  5. Get your SauceLabs access token and add it as SAUCE_ACCESS_KEY to CircleCI through the Web UI (Circle > repo > settings > Environment variables).
  6. Add Watai as a dependency to your project (npm install --save-dev watai).
  7. Copy (or integrate if you already have one) the circle.yml template below to the root of the repo you want to test.
  8. Copy the config-ci.jsbelow next to your Watai config.js, in the folder that contains your integration tests.

circle.yml

machine:
  environment:
    browser_name: $(case $CIRCLE_NODE_INDEX in 0) browser='chrome' ;; 1) browser='firefox' ;; 2) browser='internet explorer' ;; 3) browser='iphone' ;; esac; echo $browser)
    browser_version: $(case $CIRCLE_NODE_INDEX in 3) version='8.2' ;; esac; echo $version)
    SAUCE_LOG: $CIRCLE_ARTIFACTS/sauce_log.txt
    WATAI_TESTS: test/integration
    SAUCE_USERNAME: my-bot
    # SAUCE_ACCESS_KEY is defined in the CircleCI web UI

dependencies:
  post:
    - npm install saucelabs@0.1.1 # allow sending Watai results to SauceLabs; version lock needed due to https://github.com/danjenkins/node-saucelabs/pull/21
    - wget https://saucelabs.com/downloads/sc-latest-linux.tar.gz
    - tar -xzf sc-latest-linux.tar.gz

test:
  pre:
    # start server
    - npm start:
        background: true
        parallel: true
    # start Sauce Connect
    - cd sc-*-linux && ./bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY --tunnel-identifier "circle-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX" --readyfile ~/sauce_is_ready > $SAUCE_LOG:
        background: true
        parallel: true
    # wait for Sauce Connect
    - while [ ! -e ~/sauce_is_ready ]; do sleep 1; done:
        parallel: true
    # wait for server (after Sauce Connect because it is faster to start)
    - wget --retry-connrefused --waitretry=1 --output-document=/dev/null http://localhost:$PORT:
        parallel: true
    # prepare CI-specific config holder and add CI-specific config to Watai
    - mkdir $HOME/.watai && cp $WATAI_TESTS/config-ci.js $HOME/.watai/config.js:
        parallel: true

  override:
    - watai $WATAI_TESTS --config '{"driverCapabilities":{"browserName":"'"$browser_name"'","version":"'"$browser_version"'"}}':
        parallel: true

  post:
    - killall --wait sc:  # wait until Sauce Connect closes the tunnel
        parallel: true

config-ci.js

// this file is for use in CircleCI continuous integration environment
module.exports = {
    seleniumServerURL: {
        hostname    : 'ondemand.saucelabs.com',
        port        : 80,
    },
    driverCapabilities: {
        platform            : 'Windows 7',
        'tunnel-identifier' : 'circle-' + process.env.CIRCLE_BUILD_NUM + '-' + process.env.CIRCLE_NODE_INDEX,
    },
    tags        : [ 'circle-ci', '#' + process.env.CIRCLE_BUILD_NUM ],
    views       : [ 'Verbose', 'SauceLabs' ],
    quit        : 'always', // avoid wasting 90 seconds on SauceLabs
    bail        : true,
    build       : 'CircleCI#' + process.env.CIRCLE_BUILD_NUM,
}
Clone this wiki locally