【问题标题】:cucumber-js cannot find the step definition when a variable is neededcucumber-js 在需要变量时找不到步骤定义
【发布时间】:2020-03-22 10:35:16
【问题描述】:

我有一个功能

// test.feature
    Feature: Test1

      Scenario: To test variables
         Given When no variable succeed
         When When value blah and value blah3


    // test_steps.js
    const { Before, Given, When, Then } = require('cucumber');
const assert = require('assert');


Given(/^When no variable succeed$/, function () {
    assert.equal(1,1)
  });

When(/^When value {string} and value {string}$/, function (val1, val2) {
    return 'pending';
});

结果是什么

> Scenario: To test variables #
> tests/bdd/features_cucumber/test.feature:3    ✔ Given When no variable
> succeed # tests/bdd/features_cucumber/step_definitions/test_steps.js:5
> ? When When value blah and value blah3
>        Undefined. Implement with the following snippet:
> 
>          When('When value blah and value blah3', function () {
>            // Write code here that turns the phrase above into concrete actions
>            return 'pending';
>          });

【问题讨论】:

标签: javascript cucumber bdd cucumberjs


【解决方案1】:

您必须在功能文件中的变量周围添加引号 When When value "blah" and value "blah3"

并且您不需要步骤定义中的正则表达式。 When('When value {string} and value {string}', function (val1, val2) { 应该这样做

如果您在步骤定义中使用正则表达式,那么您必须为您的值使用捕获组。例如: When(/^When value "([^"]*)" and value "([^"]*)"$/, function (val1, val2) {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多