[英]Cucumber cannot find StepDefinitions while running the code but manually using the option “Find Step” can find step definition
在如下定义的项目结构中,
当我RunCukesTest.java using RunAs --> JUnit Test,
从RunCukesTest.java using RunAs --> JUnit Test,
运行时, RunCukesTest.java using RunAs --> JUnit Test,
者无法找到步骤定义
当我单击查找步骤时,打开正确的文件。 由于几天前代码在运行,因此无法理解问题所在。 文件从这里下载
https://drive.google.com/open?id=0B4SgyzyvwKhiVTRmRDZuNXNTSjA
跑步者类代码
package helpers;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//features= "src/test/resources/features/navigation",
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"classpath:features"},
plugin = {"pretty", "html:target/cucumber-html-report"},
tags = {"@OnlyOneTime"},
// dryRun = true,
monochrome = true
)
public class RunCukesTest{
}
我发现了您的问题,根据您的跑步者课程,未设置粘合路径。 请设置胶水路径。 glue={"stepDefinitions"}
package helpers;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//features= "src/test/resources/features"@RunWith(Cucumber.class) @CucumberOptions(
features = {"classpath:features"}, glue={"stepDefinitions"},plugin = {"pretty", "html:target/cucumber-html-report"}, tags = {"@OnlyOneTime"}, // dryRun = true, monochrome = true )
public class RunCukesTest{ }
作为Cucumber功能运行它,效果很好,但是如果我提供胶水= {“ stepDefinitions”}并尝试从运行器运行它,则会抛出NullPointerException,
此问题是由于找不到钩子引起的。 但是,如果我将@Before和@After移至SDLogin类,则它会很好地工作。
胶水代码应该具有钩子和步骤定义的路径
因此,修改后的内容改为glue={"helpers","stepDefinitions"}
而不是glue={"helpers","classpath/stepDefinitions", "classpath/stepDefinitions.LogIn","classpath/stepDefinitions.Publish"}
请参考此链接github上的类似问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.