Skip to content

Commit

Permalink
feat: support browser args
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Apr 28, 2020
1 parent 95bea44 commit 1bb2f3b
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions packages/remote/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
} = require('./cp');
require('@faltest/utils/src/require-before-webdriverio');
const { remote } = require('webdriverio');
const path = require('path');
const psList = require('ps-list');
const fkill = require('fkill');
const getPort = require('get-port');
Expand All @@ -19,6 +20,9 @@ const { defaults } = require('@faltest/utils');
// We aren't using `@wdio/cli` (wdio testrunner)
process.env.SUPPRESS_NO_CONFIG_WARNING = 'true';

let configDir = process.env.FALTEST_CONFIG_DIR || process.cwd();


let port;

const webDriverRegex = /^(chromedriver(?:\.exe)?|geckodriver)$/;
Expand Down Expand Up @@ -163,7 +167,7 @@ async function spawnWebDriver(name, args) {
if (process.platform === 'win32') {
let { emit } = webDriver;

webDriver.emit = function(eventName, exitCode) {
webDriver.emit = function (eventName, exitCode) {
if (eventName === 'exit' && exitCode === 1) {
return true;
}
Expand All @@ -179,6 +183,18 @@ async function spawnWebDriver(name, args) {
return webDriver;
}

function loadConfig() {
try {
return require(path.resolve(configDir, '.faltestrc.js'));
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}

return {};
}
}

function startWebDriver(options = {}) {
return log(async () => {
if (!yn(process.env.WEBDRIVER_DISABLE_CLEANUP)) {
Expand Down Expand Up @@ -232,12 +248,20 @@ function stopWebDriver(webDriver) {
});
}

async function getCapabilities({
customizeCapabilities = (browserName, capabilities) => capabilities,
overrides: {
browser: _browser = getDefaults().browser,
} = {},
}) {
async function getCapabilities(options) {
let {
browserArgs = [],
customizeCapabilities = (browserName, capabilities) => capabilities,
overrides: {
browser: _browser = getDefaults().browser,
} = {},
} = options;

let faltestConfig = loadConfig();

let argsFromConfig = (((faltestConfig.options || {}).browsers || {})[_browser] || {}).args || [];


let capabilities = {
browserName: _browser,
};
Expand All @@ -248,7 +272,7 @@ async function getCapabilities({

switch (_browser) {
case 'chrome': {
let args = [];
let args = [...browserArgs, ...argsFromConfig];
if (headless) {
args.push('--headless');
}
Expand All @@ -259,7 +283,7 @@ async function getCapabilities({
break;
}
case 'firefox': {
let args = [];
let args = [...browserArgs, ...argsFromConfig];
if (headless) {
args.push('-headless');
}
Expand Down

0 comments on commit 1bb2f3b

Please sign in to comment.