为什么黄瓜不执行我的步骤定义

Why is Cucumber not executing my step definitions?

本文关键字:定义 我的 黄瓜不 执行 为什么      更新时间:2023-09-26

在Windows上工作,我已经安装了Ruby和Ruby DevKit,以便与Cucumber一起工作。现在我有以下基本设置:

/app
   /features
       example.feature
       /step_definitions
           example.steps.js

在示例功能文件中,我有:

Feature: This is an example feature
    In order to learn Cucumber
    As a developer
    I want to make this feature pass
    Scenario: wrote my first scenario
        Given a variable set to 1
        When I increment the variable by 2
        Then the variable should contain 3

在 example.step.js 文件中,我有:

'use strict';
module.exports = function () {
    this.givenNumber = 0;
    this.Given(/^a variable set to ('d+)$/, function(number, next) {
        this.givenNumber = parseInt(number);
        next();
    });
    this.When(/^I increment the variable by ('d+)$/, function (number, next) {
        this.givenNumber = this.givenNumber + parseInt(number);
        next();
    });
    this.Then(/^the variable should contain ('d+)$/, function (number, next) {
        if (this.givenNumber != number)
            throw(new Error("This test didn't pass, givenNumber is " + this.givenNumber + " expected 0"));
        next();
    });
};

现在,当我从/app dir 运行"黄瓜"时,我不断获得以下输出:

1 scenario (1 undefined)
3 steps (3 undefined)
0m0.004s

我尝试在文件中移动,添加 --require 选项等,但似乎没有任何帮助。

有什么想法吗?

显然这不能直接使用"cucumber"命令执行。使用咕噜声设置事情,咕噜黄瓜任务似乎按预期工作:

我的咕噜咕噜.js

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']);
};

另外:如果您使用的是量角器。它内置了黄瓜。只需为量角器创建正确的配置(protractor.conf.js):

exports.config = {
    specs: [
        //'e2e/features/*.feature'
        '**/*.feature'
    ],
    capabilities: {
        'browserName': 'chrome'
    },
    baseUrl: 'http://localhost:9000/',
    framework: 'cucumber'
}