Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: functional test running tweaks #767

Merged
merged 2 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -22,7 +23,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
6 changes: 3 additions & 3 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.

## local selenium and browser testing (without saucelabs)
Make sure selenium webdriver is running and run ```node ./node_modules/codeceptjs/bin/codecept.js run --verbose```
Make sure selenium webdriver is running and run ```RUN_LOCALLY=true node ./node_modules/codeceptjs/bin/codecept.js run --verbose```.
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!');
}
);