我尝试使用 @Before
Hook 获取当前场景对象,因为我想显示其名称。
但是当我尝试这样做时,我收到以下异常:
cucumber.runtime.CucumberException:
When a hook declares an argument it must be of type \
cucumber.runtime.ScenarioResult.
public void sefa.sqlpmi.CucumberStedDefs.afterCucumberScenario(
gherkin.formatter.model.Scenario) throws java.lang.Exception
我的代码如下所示:
@Before
public void beforeCucumberScenario(Scenario scenario) throws Exception{
System.out.println(scenario.getName());
}
这似乎也适用于许多其他人。
最佳答案
确保导入 cucumber.api.Scenario
而不是 gherkin.formatter.model.Scenario
。第二个会产生您提到的异常。
关于java - 无法使用 @Before Hook 获取场景对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38478318/