cucumber.runtime.CucumberException: 不是地图或列表类型

cucumber.runtime.CucumberException: Not a Map or List type

如果我在数据 Table 中使用不是 List 或 Map 类型的数据,则会出现错误

cucumber.runtime.CucumberException: Not a Map or List type

我就是这样测试的。我正在从下到上对其进行测试,即编写函数 > 然后编写步骤 def > 编写功能文件(仅用于测试目的)。

java 函数:

public String getScenarioName(Scenario scenario) {
        System.out.println("scenario.getName().toString());
    }

步骤定义:

@And("^Get current scenario name$")
    public void get_current_scenario_name(Scenario scenario) {
        System.out.println(getScenarioName(scenario));
    }

特征文件:

  Scenario: Title of your scenario
    Given I have a scenario
    Then Get current scenario name
      |scenario|

因为我使用 Scenario 接口作为参数,所以我必须在功能、步骤和特性文件中使用它。

注意:请不要以奇怪的场景来判断,我只是在测试。

我浏览了以下链接,但对我没有帮助。它一直给我同样的错误。

https://github.com/cucumber/cucumber-jvm/issues/741

http://grasshopper.tech/340/ >> 这个我没法实现,没搞明白。

您看错方向了。要在给定步骤中打印出场景名称,您必须在步骤中打印之前在 before 挂钩中捕获它:

import cucumber.api.Scenario;
import cucumber.api.java.Before;
import cucumber.api.java.en.And;

public class ExampleSteps {

    private Scenario scenario;

    @Before
    public void capture_scenario(Scenario scenario){
        this.scenario = scenario;
    }

    @And("^get current scenario name$")
    public void get_current_scenario_name() {
        System.out.println(this.scenario.getName());
    }
}

那么这个场景会打印My Scenario.

Scenario: My Scenario
  And I get the current scenario name