Question

I'm using CucumberJS to run tests on my NodeJS web app.

At the moment, I can run all of my grunt tasks by executing grunt, or only the CucumberJS tasks, using grunt cucumberjs.

But now I want to only execute particular features.

For example, say I have the following feature files:

  • Signin.feature
  • Favourite.feature

I want to only run the Favourite feature tests, using a command such as:

grunt cucumberjs Favourite

Is this possible?


BTW, here's my gruntfile.js:

'use strict';

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        ...
        cucumberjs: {
            src: 'features',
            options: {
                steps: 'features/step_definitions',
                format: 'pretty'
            }
        }
    });

    ...
    grunt.loadNpmTasks('grunt-cucumber');

    grunt.registerTask('default', [... 'cucumberjs']);
};
Was it helpful?

Solution

I finally figured out a solution that seems to work well enough, based on tags.

So for each of my feature files, I've added a tag.

For example, for Favourite.feature:

@favourite
Feature: Favourite
    As a user of the system
    I would like to favourite items

Then I've used a GruntJS option to specify the tags I want to run via a command-line argument.

I do this through a grunt.option() call in my gruntfile:

cucumberjs: {
    src: 'features',
    options: {
        steps: 'features/step_definitions',
        format: 'pretty',
        tags: grunt.option('cucumbertags')
    }
}

So now I can run GruntJS from the command-line like this:

grunt cucumberjs --cucumbertags=@favourite

And it will only run the feature with the @favourite tag. Yay!

OTHER TIPS

here is my task that allows you to filter by feature.name:

https://github.com/webforge-labs/cuked-zombie/blob/master/tasks/cucumber.js (download it into a "tasks" folder and you can load it with: grunt.loadTasks('tasks'))

configure it like this (Gruntfile.js):

grunt.loadNpmTasks('grunt-cucumber');

grunt.initConfig({
  cucumberjs: {
    // config for all features when called with: `grunt cucumber`
    all: {
      src: 'features',
      options: {
        steps: "tests/js/cucumber/bootstrap.js",
        format: "pretty"
      }
    },

    // config for single features when called with `grunt --filter some-feature`
    features: {
      src: 'features',
      options: {
        steps: "tests/js/cucumber/bootstrap.js",
        format: "pretty"
      }
    }
  }
});

use it with:

grunt cucumber --filter post

which will run the post.feature (somewhere in your feature directory)

With the new cucumber-js Version it is possible to run it by feature-line: https://github.com/cucumber/cucumber-js/pull/168

I haven't tested it with grunt but cucumber has an option for executing a scenario without modifying the gherkin file. Just call cucumber-js --name "Scenario Name", therefore I assume that sending the same argument to grant it will do its job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top