Skip to content

Instantly share code, notes, and snippets.

@dcypherthis
Created September 20, 2017 13:16
Show Gist options
  • Save dcypherthis/c4345e9667843344b75cbb2c51277686 to your computer and use it in GitHub Desktop.
Save dcypherthis/c4345e9667843344b75cbb2c51277686 to your computer and use it in GitHub Desktop.
Master WDIO config for wdio cucumber framework 1.x or higher
require('babel-core/register');
const _config = require('config');
const debug = process.env.DEBUG;
const errorLogs = [];
let feature, scenario, step, status, timestamp, allTags, caseId;
exports.config = {
sync: true,
debug: debug, //eslint-disable-line object-shorthand
coloredLogs: true,
screenshotPath: './reports/errorShots/',
baseUrl: 'https://myemma.com/',
waitforTimeout: 30000,
connectionRetryTimeout: 30000,
connectionRetryCount: 3,
framework: 'cucumber',
env: _config,
suites: {
base: [
'./test/features/base/**/*.feature',
],
CAMP: [
'./test/features/CAMP/**/*.feature',
],
CMS: [
'./test/features/CMS/**/*.feature',
],
CRM: [
'./test/features/CRM/**/*.feature',
],
EN2: [
'./test/features/EN2/**/*.feature',
],
INF: [
'./test/features/INF/**/*.feature',
],
PINT: [
'./test/features/PINT/**/*.feature',
],
RDV: [
'./test/features/RDV/**/*.feature',
],
},
cucumberOpts: {
// compiler: [
// 'js:babel-register',
// ],
require: [
'./test/step_definitions/given.steps.js',
'./test/step_definitions/when.steps.js',
'./test/step_definitions/then.steps.js',
],
backtrace: true,
dryRun: false,
failFast: false, // <boolean> abort the run on first failure
format: ['pretty'],
colors: true,
snippets: false,
source: false,
profile: [],
strict: false,
// tags: [], // ['@only', '@isolate'], // <string[]> (expression) only execute the features or scenarios with tags matching the expression
timeout: 60000,
ignoreUndefinedDefinitions: false,
},
before: function before() { //eslint-disable-line object-shorthand
/**
* Setup the Chai assertion framework
*/
const chai = require('chai');
global.expect = chai.expect;
global.assert = chai.assert;
global.should = chai.should();
},
afterStep: function(stepResult) { //eslint-disable-line object-shorthand
/**
* Assign Step Status of Passed/Failed/Skipped to a variable.
*/
status = stepResult.status;
/**
* If the step passes or is skipped, skip browser console logging.
*/
if (status !== `failed`) {
return;
}
/**
* Assign current step data to variables for error logging purposes
*/
feature = stepResult.step.scenario.feature.name;
scenario = stepResult.step.scenario.name;
step = stepResult.step.name;
/**
* gets the current browser logs from selenium and assigns them to a variable
*/
const logs = browser.log('browser');
/**
* Filters out everything except error messages and adds step/scenario/feature info to the errorLogs array
*/
logs.value.forEach(log => {
/**
* only print error messages
*/
if (!log || typeof log.level !== 'string' || log.level.toLowerCase() !== 'severe') {
return;
}
/**
* Assign time error was incurred to a variable
*/
timestamp = log.timestamp.toString();
/**
* Add The test path and browser console message to the errorLogs array
*/
errorLogs.push({
name: `${status}: ${feature} ${scenario} ${step}`,
message: log.message,
});
});
},
after: function (result, capabilities, spec) { //eslint-disable-line object-shorthand
/* eslint-disable no-console */
/**
* Skip if there are no severe browser errors to report
*/
if (status === 'passed') {
return;
} else if ((status === 'failed' || status === 'skipped') && errorLogs.length === 0) {
console.error(`\n<==== NO SEVERE BROWSER ERRORS DETECTED ====>`);
return;
}
console.error('\n====> SEVERE BROWSER LOGS OF FAILING TESTS <====');
console.error(`Case ID: ${caseId}`);
console.error(`Feature: ${feature}`);
console.error(`Scenario: ${scenario}`);
console.error(`Step: ${step}`);
console.error(`TimeStamp: ${timestamp}`);
console.error(`Capabilities: ${JSON.stringify(capabilities)}`);
errorLogs.forEach((log, i) => {
if (i === 0 || errorLogs[i - 1].name !== log.name) {
console.error(`\n> ${log.name}`);
}
console.error(`BROWSER CONSOLE LOG: ${log.message}`);
});
console.error('====> END OF BROWSER LOGS <====');
/* eslint-enable no-console */
},
/* eslint-disable no-shadow */
afterFeature: function (feature) { //eslint-disable-line object-shorthand
console.log(feature.tags[0].name);
allTags = feature.tags;
caseId = allTags[0].name;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment