Skip to content

Commit

Permalink
Chore: functional test running tweaks (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanDeMicco authored Apr 17, 2018
1 parent 5de7093 commit c3ea1e6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
5 changes: 3 additions & 2 deletions codecept.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions functional-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SAUCELABS_USER_NAME> -k <SAUCELABS_ACCESS_KEY> -N -i <TUNNEL_ID>``` 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=<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.

## Selenium (without SauceLabs)
1) Install selenium-standalone `npm install selenium-standalone@latest -g`
Expand Down
82 changes: 82 additions & 0 deletions functional-tests/run-all.js
Original file line number Diff line number Diff line change
@@ -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!');
}
);

0 comments on commit c3ea1e6

Please sign in to comment.