Skip to content

Commit

Permalink
feat(tests): add flags to functional test runner to configure browser (
Browse files Browse the repository at this point in the history
…#6199)

--browser can be 'chrome' or 'firefox'
--headless prevents the browser from opening a desktop window
--savelogs saves a file with whatever the browser prints to console.log
           after a test finishes
  • Loading branch information
Scott authored Dec 13, 2018
1 parent a2343e6 commit 4b08123
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"@types/js-yaml": "3.5.30",
"@types/lodash": "^4.14.64",
"@types/marked": "^0.0.28",
"@types/minimist": "^1.2.0",
"@types/moment-timezone": "^0.2.34",
"@types/node": "7.0.5",
"@types/prop-types": "^15.5.2",
Expand Down Expand Up @@ -161,6 +162,7 @@
"less-loader": "4.1.0",
"loader-utils": "^1.1.0",
"md5": "^2.2.1",
"minimist": "^1.2.0",
"ngtemplate-loader": "^1.3.1",
"node-libs-browser": "^2.0.0",
"physical-cpu-count": "^2.0.0",
Expand Down
42 changes: 41 additions & 1 deletion wdio.conf.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
require('ts-node/register');

const fs = require('fs');
const path = require('path');
const process = require('process');
const minimist = require('minimist');

const flags = minimist(process.argv.slice(2), {
default: {
browser: 'chrome',
headless: false,
savelogs: false,
},
});

if (flags.savelogs && flags.browser !== 'chrome') {
console.warn('fetching browser logs is only supported by chrome driver; disabling --savelogs');
flags.savelogs = false;
}

const config = {
specs: ['test/functional/tests/**/*.spec.ts'],
maxInstances: 1,
capabilities: [
{
maxInstances: 1,
browserName: 'chrome',
browserName: flags.browser,
},
],
sync: true,
Expand All @@ -33,6 +51,28 @@ const config = {
beforeTest: function(test) {
browser.windowHandleSize({ width: 1280, height: 1024 });
},

afterTest: function(test) {
if (flags.savelogs && browser.sessionId) {
const outPath = path.resolve(__dirname, './' + browser.sessionId + '.browser.log');
fs.writeFileSync(outPath, JSON.stringify(browser.log('browser'), null, 4));
console.log(`browser log written to ${outPath}`);
}
},
};

if (flags.headless) {
config.capabilities.forEach(cap => {
if (cap.browserName === 'chrome') {
cap.chromeOptions = cap.chromeOptions || {};
cap.chromeOptions.args = cap.chromeOptions.args || [];
cap.chromeOptions.args.push('--headless');
} else if (cap.browserName === 'firefox') {
cap['moz:firefoxOptions'] = cap['moz:firefoxOptions'] || {};
cap['moz:firefoxOptions'].args = cap['moz:firefoxOptions'].args || [];
cap['moz:firefoxOptions'].args.push('-headless');
}
});
}

exports.config = config;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@
resolved "https://registry.yarnpkg.com/@types/memoize-one/-/memoize-one-3.1.1.tgz#0e21a1b91dc031fb59c1e1657b807ca9aec77475"
integrity sha512-VlMu4eWNfQ8CDfhHYe8P/RgBq8vgce8LMo4vVKASPPAv+TE9SCR1bH6pA4nHEKNUQz1L/PIdElU2vqA2m366Dw==

"@types/minimist@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/moment-timezone@^0.2.34":
version "0.2.34"
resolved "https://registry.yarnpkg.com/@types/moment-timezone/-/moment-timezone-0.2.34.tgz#948e0aff82742a31dd63714d1aac9616bc375053"
Expand Down

0 comments on commit 4b08123

Please sign in to comment.