diff --git a/codecept.conf.js b/codecept.conf.js index 5e434a563..5609b88dd 100644 --- a/codecept.conf.js +++ b/codecept.conf.js @@ -8,7 +8,8 @@ const { BROWSER_PLATFORM, PLATFORM_VERSION, DEVICE_NAME, - DEFAULT_WAIT_TIME = 90000 + DEFAULT_WAIT_TIME = 90000, + RUN_LOCALLY=false } = process.env; const MOBILE_PLATFORMS = ['iOS', 'Android']; @@ -21,7 +22,7 @@ const commonConfigObj = { }; const helperObj = {}; -const isLocalBuild = typeof SAUCE_USERNAME === 'undefined'; +const isLocalBuild = typeof SAUCE_USERNAME === 'undefined' || RUN_LOCALLY; if (isLocalBuild) { helperObj.WebDriverIO = commonConfigObj; diff --git a/functional-tests/README.md b/functional-tests/README.md index df870e840..a0282e753 100644 --- a/functional-tests/README.md +++ b/functional-tests/README.md @@ -3,9 +3,9 @@ ## SauceLabs 1) Download the [saucelabs proxy](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy) 2) Run ```yarn functional-tests``` to start a local server on localhost:8000 -3) Run the proxy ```./bin/sc -u SAUCELABS_USER_NAME -k SAUCELABS_ACCESS_KEY -N -i test``` to allow saucelabs to access your localhost +3) Run the proxy ```./bin/sc -u -k -N -i ``` to allow saucelabs to access your localhost. SAUCE_USERNAME, SAUCELABS_ACCESS_KEY can be found in saucelabs website. TUNNEL_ID is a unique identifier such as your username. 4) Run the tests -```SAUCE_USERNAME=SAUCELABS_USER_NAME SAUCE_ACCESS_KEY=SAUCELABS_ACCESS_KEY TRAVIS_JOB_NUMBER=TUNNEL_ID node ./node_modules/codeceptjs/bin/codecept.js run --verbose``` where SAUCE_USERNAME, SAUCELABS_ACCESS_KEY can be found in saucelabs website. TUNNEL_ID is a unique identifier such as your username. +```SAUCE_USERNAME= SAUCE_ACCESS_KEY= TRAVIS_JOB_NUMBER= node ./node_modules/codeceptjs/bin/codecept.js run --verbose``` where SAUCE_USERNAME, SAUCELABS_ACCESS_KEY can be found in saucelabs website. TUNNEL_ID is a unique identifier such as your username. ## Selenium (without SauceLabs) 1) Install selenium-standalone `npm install selenium-standalone@latest -g` diff --git a/functional-tests/run-all.js b/functional-tests/run-all.js new file mode 100644 index 000000000..37b6e6fd7 --- /dev/null +++ b/functional-tests/run-all.js @@ -0,0 +1,82 @@ +#!/usr/bin/env node + +/* eslint-disable no-console */ +const async = require('async'); +const util = require('util'); +const colors = require('colors'); +const exec = util.promisify(require('child_process').exec); + +const { SAUCE_USERNAME, SAUCE_ACCESS_KEY, TRAVIS_JOB_NUMBER } = process.env; + +// browsers +const CHROME = 'chrome'; +const FIREFOX = 'firefox'; +const EDGE = 'MicrosoftEdge'; +const IE = 'internet explorer'; + +// platforms +const SAFARI = 'Safari'; +const WINDOWS = 'Windows 10'; +const OSX = 'macOS 10.13'; +const ios = 'iOS'; +const android = 'Android'; + +const envArr = [ + `BROWSER_PLATFORM="${WINDOWS}" BROWSER_NAME="${CHROME}"`, + `BROWSER_PLATFORM="${WINDOWS}" BROWSER_NAME="${FIREFOX}"`, + `BROWSER_PLATFORM="${WINDOWS}" BROWSER_NAME="internet explorer"`, + `BROWSER_PLATFORM="${WINDOWS}" BROWSER_NAME="${EDGE}"`, + `BROWSER_PLATFORM="${OSX}" BROWSER_NAME="safari"`, + `BROWSER_PLATFORM="${OSX}" BROWSER_NAME="${CHROME}"`, + `BROWSER_PLATFORM="${OSX}" BROWSER_NAME="${FIREFOX}"`, + `BROWSER_PLATFORM="${ios}" DEVICE_NAME="iPhone X Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="${SAFARI}"`, + `BROWSER_PLATFORM="${ios}" DEVICE_NAME="iPhone 6 Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="${SAFARI}"`, + `BROWSER_PLATFORM="${ios}" DEVICE_NAME="iPad Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="${SAFARI}"`, + `BROWSER_PLATFORM="${android}" DEVICE_NAME="Android GoogleAPI Emulator" PLATFORM_VERSION="7.1" BROWSER_NAME="Chrome"` +]; + +if (!TRAVIS_JOB_NUMBER || !SAUCE_USERNAME || !TRAVIS_JOB_NUMBER) { + throw new Error('missing TRAVIS_JOB_NUMBER, SAUCE_USERNAME, or TRAVIS_JOB_NUMBER'); +} + +const processArr = []; +async.eachLimit( + envArr, + 4, + async (envStr) => { + let grepStr = ''; + + const ieRegex = new RegExp(IE); + const mobileRegex = /iOS|Android/; + + if (mobileRegex.test(envStr)) { + grepStr = '--grep "@mobile"'; + } else if (ieRegex.test(envStr)) { + grepStr = '--grep "@ie"'; + } + + const cmd = `cd .. && CI=true SAUCE_USERNAME=${SAUCE_USERNAME} SAUCE_ACCESS_KEY=${SAUCE_ACCESS_KEY} TRAVIS_JOB_NUMBER=${TRAVIS_JOB_NUMBER} ${envStr} node ./node_modules/codeceptjs/bin/codecept.js run --steps ${grepStr}`; + + console.log('Running cmd: ', cmd); + const process = exec(cmd); + processArr.push(process); + await process; + }, + (err) => { + if (err) { + console.log(colors.red.underline(err)); + console.log(colors.red(err.stdout)); + processArr.forEach((process) => { + if (process && process.kill) { + try { + process.kill(); + } catch (err2) { + console.error(err2); + } + } + }); + throw new Error(); + } + console.log('SUCCESS!'); + } +);