Skip to content

Commit

Permalink
Chore: functional test running tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Apr 25, 2018
1 parent 8d636a2 commit 20386bc
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ aliases:
- sleep 5
addons:
sauce_connect: true
script: yarn run functional-tests-ci
script: travis_retry yarn run functional-tests-ci
- &sauce-labs-mobile
<<: *sauce-labs
script: yarn run functional-tests-ci --grep @mobile
script: travis_retry yarn run functional-tests-ci --grep @mobile
- &sauce-labs-desktop
<<: *sauce-labs
script: yarn run functional-tests-ci --grep @desktop
script: travis_retry yarn run functional-tests-ci --grep @desktop
- &sauce-labs-ie
<<: *sauce-labs
script: yarn run functional-tests-ci --grep @ie
script: travis_retry yarn run functional-tests-ci --grep @ie
jobs:
include:
- script: yarn run ci
Expand Down
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'];
const { cleanupAnnotations } = require('./functional-tests/helpers/cleanup');
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
100 changes: 100 additions & 0 deletions functional-tests/run-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/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';

// file information
const CHROME_FILE = {
id: '285567874839',
version: '300496591287'
};
const SAFARI_FILE = {
id: '285569765346',
version: '300498497346'
};
const FIREFOX_FILE = {
id: '285568802145',
version: '300497533713'
};
const EDGE_FILE = {
id: '285567976309',
version: '300496707445'
};
const IE_FILE = {
id: '285568624824',
version: '300497342136'
};

const envArr = [
`BROWSER_PLATFORM="${OSX}" BROWSER_NAME="${CHROME}" FILE_ID="${CHROME_FILE.id}" FILE_VERSION_ID="${CHROME_FILE.version}"`,
`BROWSER_PLATFORM="${OSX}" BROWSER_NAME="safari" FILE_ID="${SAFARI_FILE.id}" FILE_VERSION_ID="${SAFARI_FILE.version}"`,
`BROWSER_PLATFORM="${OSX}" BROWSER_NAME="${FIREFOX}" FILE_ID="${FIREFOX_FILE.id}" FILE_VERSION_ID="${FIREFOX_FILE.version}"`,
`BROWSER_PLATFORM="${WINDOWS}" BROWSER_NAME="${EDGE}" FILE_ID="${EDGE_FILE.id}" FILE_VERSION_ID="${EDGE_FILE.version}"`,
`BROWSER_PLATFORM="${WINDOWS}" BROWSER_NAME="internet explorer" FILE_ID="${IE_FILE.id}" FILE_VERSION_ID="${IE_FILE.version}"`,
`BROWSER_PLATFORM="${ios}" DEVICE_NAME="iPhone 6 Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="${SAFARI}" FILE_ID="${SAFARI_FILE.id}" FILE_VERSION_ID="${SAFARI_FILE.version}"`,
`BROWSER_PLATFORM="${ios}" DEVICE_NAME="iPad Simulator" PLATFORM_VERSION="11.2" BROWSER_NAME="${SAFARI}" FILE_ID="${FIREFOX_FILE.id}" FILE_VERSION_ID="${FIREFOX_FILE.version}"`,
`BROWSER_PLATFORM="${android}" DEVICE_NAME="Android GoogleAPI Emulator" PLATFORM_VERSION="7.1" BROWSER_NAME="Chrome" FILE_ID="${CHROME_FILE.id}" FILE_VERSION_ID="${CHROME_FILE.version}"`
];

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 mobileRegex = /iOS|Android/;

if (mobileRegex.test(envStr)) {
grepStr = '--grep "@mobile"';
} else {
grepStr = '--grep "@desktop"';
}

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 20386bc

Please sign in to comment.