webdriverio-automation
Version:
WebdriverIO-Automation android ios project
175 lines (151 loc) • 5.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.launchWithStdin = launchWithStdin;
exports.launch = launch;
exports.handler = handler;
exports.builder = exports.cmdArgs = exports.desc = exports.command = void 0;
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _path = _interopRequireDefault(require("path"));
var _launcher = _interopRequireDefault(require("./../launcher"));
var _watcher = _interopRequireDefault(require("./../watcher"));
var _utils = require("../utils");
var _constants = require("../constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
const command = 'run <configPath>';
exports.command = command;
const desc = 'Run your WDIO configuration file to initialize your tests. (default)';
exports.desc = desc;
const cmdArgs = {
watch: {
desc: 'Run WebdriverIO in watch mode',
type: 'boolean'
},
hostname: {
alias: 'h',
desc: 'automation driver host address',
type: 'string'
},
port: {
alias: 'p',
desc: 'automation driver port',
type: 'number'
},
path: {
type: 'string',
desc: 'path to WebDriver endpoints (default "/")'
},
user: {
alias: 'u',
desc: 'username if using a cloud service as automation backend',
type: 'string'
},
key: {
alias: 'k',
desc: 'corresponding access key to the user',
type: 'string'
},
logLevel: {
alias: 'l',
desc: 'level of logging verbosity',
choices: ['trace', 'debug', 'info', 'warn', 'error', 'silent']
},
bail: {
desc: 'stop test runner after specific amount of tests have failed',
type: 'number'
},
baseUrl: {
desc: 'shorten url command calls by setting a base url',
type: 'string'
},
waitforTimeout: {
alias: 'w',
desc: 'timeout for all waitForXXX commands',
type: 'number'
},
framework: {
alias: 'f',
desc: 'defines the framework (Mocha, Jasmine or Cucumber) to run the specs',
type: 'string'
},
reporters: {
alias: 'r',
desc: 'reporters to print out the results on stdout',
type: 'array'
},
suite: {
desc: 'overwrites the specs attribute and runs the defined suite',
type: 'array'
},
spec: {
desc: 'run only a certain spec file - overrides specs piped from stdin',
type: 'array'
},
exclude: {
desc: 'exclude certain spec file from the test run - overrides exclude piped from stdin',
type: 'array'
},
mochaOpts: {
desc: 'Mocha options'
},
jasmineNodeOpts: {
desc: 'Jasmine options'
},
cucumberOpts: {
desc: 'Cucumber options'
}
};
exports.cmdArgs = cmdArgs;
const builder = yargs => {
return yargs.options(cmdArgs).example('$0 run wdio.conf.js --suite foobar', 'Run suite on testsuite "foobar"').example('$0 run wdio.conf.js --spec ./tests/e2e/a.js --spec ./tests/e2e/b.js', 'Run suite on specific specs').example('$0 run wdio.conf.js --mochaOpts.timeout 60000', 'Run suite with custom Mocha timeout').epilogue(_constants.CLI_EPILOGUE).help();
};
exports.builder = builder;
function launchWithStdin(wdioConfPath, params) {
let stdinData = '';
const stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', data => {
stdinData += data;
});
stdin.on('end', () => {
if (stdinData.length > 0) {
params.specs = stdinData.trim().split(/\r?\n/);
}
launch(wdioConfPath, params);
});
}
function launch(wdioConfPath, params) {
const launcher = new _launcher.default(wdioConfPath, params);
return launcher.run().then((...args) => {
if (!process.env.JEST_WORKER_ID) {
process.exit(...args);
}
}).catch(err => {
console.error(err);
if (!process.env.JEST_WORKER_ID) {
process.exit(1);
}
});
}
async function handler(argv) {
const {
configPath
} = argv,
params = _objectWithoutProperties(argv, ["configPath"]);
if (!_fsExtra.default.existsSync(configPath)) {
await (0, _utils.missingConfigurationPrompt)('run', `No WebdriverIO configuration found in "${configPath}"`);
}
const localConf = _path.default.join(process.cwd(), 'wdio.conf.js');
const wdioConf = configPath || (_fsExtra.default.existsSync(localConf) ? localConf : null);
if (params.watch) {
const watcher = new _watcher.default(wdioConf, params);
return watcher.watch();
}
if (process.stdin.isTTY || !process.stdout.isTTY) {
return launch(wdioConf, params);
}
launchWithStdin(wdioConf, params);
}