如何允许多个步骤定义匹配

问题描述 投票:0回答:1

我正在使用黄瓜进行BDD测试,功能文件如下:

Feature: Sing Up

  Scenario: User tries to sign up without interests 
    Given the interests are empty
    When user presses on sign up
    Then it should show "The interests field is empty."

  Scenario: User tries to sign up with 2 interests 
    Given 2 interests are entered
    When user presses on sign up
    Then it should show "The interests should be at least three."

我已经在JS中创建了步骤:

const assert = require("assert");
const { Given, When, Then } = require("cucumber");

Given("the interests are empty", function() {
  // Write code here that turns the phrase above into concrete actions
  return "pending";
});

When("user presses on sign up", function() {
  // Write code here that turns the phrase above into concrete actions
  return "pending";
});

Then("it should show {string}", function(string) {
  // Write code here that turns the phrase above into concrete actions
  return "pending";
});

/*----------------------------------------------------------------------*/

Given("{int} interests are entered", function(int) {
  // Given('{float} interests are entered', function (float) {
  // Write code here that turns the phrase above into concrete actions
  return "pending";
});

When("user presses on sign up", function() {
  // Write code here that turns the phrase above into concrete actions
  return "pending";
});

Then("it should show {string}", function(string) {
  // Write code here that turns the phrase above into concrete actions
  return "pending";
});

编译器抱怨:

   ✖ When user presses on sign up
       Multiple step definitions match:
         user presses on sign up - features/step_definitions/signup/steps.js:9 
         user presses on sign up - features/step_definitions/signup/steps.js:27

如何在不同的when中允许相同的scenario

javascript node.js cucumber bdd gherkin
1个回答
0
投票

您的步骤定义必须是唯一的,您不必根据每种情况重新定义它们。编译器告诉您user presses on sign up步骤已定义两次(与it should show {string}相同)。

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