Skip to content

Instantly share code, notes, and snippets.

@wswebcreation
Created July 26, 2018 12:21
Show Gist options
  • Save wswebcreation/142d5a7bb5f31e9cfc890fd5cbe9a43c to your computer and use it in GitHub Desktop.
Save wswebcreation/142d5a7bb5f31e9cfc890fd5cbe9a43c to your computer and use it in GitHub Desktop.
Simple setup to provide feature files through the command line, 1, multiple or all. Use this with webdriver.io
/**
* This is an example conf with webdriver.io + cucumberjs to run 1 or multiple feature through the command line.
* I use `yargs` to get command line arguments, but there is maybe a better / easier way.
*
* Feel free to use it for all kinds of purposes, a star is much appreciated ;-)
*
* Grtz,
* Wim | wswebreation
*/
const argv = require('yargs').argv;
exports.config = {
// Add some config here
// ...
// ======================
// Cucumber configuration
// ======================
framework: 'cucumber',
cucumberOpts: {
// the cucumber options ....
},
// This is where the magic happens
specs: getFeatureFiles(),
// Some other config
// ......
};
/**
* Get the featurefiles that need to be run based on an command line flag that is passed,
* if nothing is passed all the featurefiles are run.
* For the name of the feature, just remove the extension `.feature` from the file name
*
* @example:
*
* <pre>
* // For 1 feature
* npm run test -- --feature=playground
*
* // For multiple features, seperate with a ','
* npm run test -- --feature=playground,login,...
*
* // Else (all files are run)
* npm run test
* </pre>
*/
function getFeatureFiles() {
const featureFolder = `${process.cwd()}/{your-test-folder}/**/`;
if (argv.feature) {
return argv.feature.split(',')
.map(feature => `${featureFolder}/**/${feature}.feature`);
}
return [`${featureFolder}/**/*.feature`];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment