【问题标题】:cucumber.runtime.junit.UndefinedThrowable: The step is undefinedcucumber.runtime.junit.UndefinedThrowable:步骤未定义
【发布时间】:2019-11-16 10:40:11
【问题描述】:

我有两个不同班级的一个场景。

我的黄瓜结构:

  • 测试类:

    @RunWith(Cucumber.class)
    @CucumberOptions(plugin = "pretty", features = "src\\test\\resources\\samuel\\tripleAnd.feature")//and.feature in first case
    public class CucumberTest {
    
    }
    
  • 黄瓜实现:

    public class ElementsTestSteps implements En {
    
    public ElementsTestSteps() {
    
        Given("^Element test$", () -> {
    
        });
    
        When("^Using element as \"([^\"]*)\"$", (String arg1) -> {
        });
    
        //Commented on when using the second scenario
        When("^Accept (\\d+) (\\d+)$", (Integer arg1, Integer arg2) -> {
        });
    
        //Commented on when using the first scenario
        When("^Accept (\\d+) (\\d+)$ (\\d+)$", (Integer arg1, Integer arg2, Integer arg3) -> {
        });
    
        Then("^Return (\\d+)$", (Integer arg1) -> {
        });
    }
    
    }
    
  • 当我使用关注and.feature 功能时一切正常:

    Scenario Outline:
    Given Element test
    When Using element as "and"
    And Accept <switchA> <switchB>
    Then Return <resultSign>
    
    Examples:
      | switchA | switchB | resultSign |
      |       1 |       1 |          1 |
      |       0 |       1 |          0 |
      |       1 |       1 |          1 |
      ...
    
  • 但是当我使用以下tripleand.feature 功能时,我得到The step is undefined 异常:

    Scenario Outline:
    Given Element test
    When Using element as "triple_And"
    And Accept <switchA> <switchB> <switchC>
    Then Return <resultSign>
    
    Examples:
      | switchA | switchB | switchC | resultSign |
      |       1 |       1 |       1 |          1 |
      |       0 |       1 |       1 |          0 |
      |       1 |       0 |       1 |          0 |
      ...
    

为什么在第一种情况下一切顺利,而在第二种情况下却没有?

【问题讨论】:

  • 带有 3 个参数的步骤定义的正则表达式有错误的 $

标签: java junit cucumber


【解决方案1】:

您的第二个接受正则表达式是错误的。您有 $ 符号在该表达式中出现两次。 $ 表示行尾 EOL。删除第一个 $ ,它应该可以正常工作。看起来像一个简单的复制粘贴错误。

【讨论】:

    【解决方案2】:

    您在下面的步骤定义函数中有一个简单的问题。在第二个 (\\d+) 之后,您会得到一个额外的 $ 符号。

    When("^Accept (\\\d+) (\\\d+)$ (\\\d+)$", (Integer arg1, Integer arg2, Integer arg3) -> {
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 2022-08-19
      相关资源
      最近更新 更多