如何使用GruntJS运行一项特定的CucumberJS功能?

问题描述 投票:6回答:3

我正在使用CucumberJS在NodeJS Web应用程序上运行测试。

目前,我可以使用grunt通过执行grunt cucumberjs或仅CucumberJS任务来运行所有grunt任务。

但是现在我只想执行特定功能。

例如,说我有以下功能文件:

  • Signin.feature
  • 收藏夹功能

我只想使用以下命令来运行收藏夹功能测试:

grunt cucumberjs Favourite

这可能吗?


顺便说一句,这是我的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']);
};
node.js gruntjs cucumberjs
3个回答
4
投票

我终于找到了一个基于tags的似乎很好用的解决方案。

因此,对于我的每个功能文件,我都添加了标签。

例如,对于Favourite.feature:

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

然后,我使用GruntJS option来指定要通过命令行参数运行的标签。

我通过gruntfile中的grunt.option()调用执行此操作:

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

所以现在我可以像这样从命令行运行GruntJS:

grunt cucumberjs --cucumbertags=@favourite

并且它将仅使用@favourite标签运行该功能。是的!


0
投票

这是我的任务,可让您按feature.name进行过滤:

https://github.com/webforge-labs/cuked-zombie/blob/master/tasks/cucumber.js(将其下载到“任务”文件夹中,并可以通过以下方式加载:grunt.loadTasks('tasks')

像这样配置它(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"
      }
    }
  }
});

与它一起使用:

grunt cucumber --filter post

将运行post.feature(在功能部件目录中的某个位置)

使用新的cucumber-js版本,可以通过功能线运行它:https://github.com/cucumber/cucumber-js/pull/168


0
投票

我还没有用咕tested声进行测试,但是Cucumber可以选择执行场景而不修改小黄瓜文件。只需调用cucumber-js --name "Scenario Name",因此我假设发送相同的参数来授予它的权限即可。

© www.soinside.com 2019 - 2024. All rights reserved.