@RunWith(Cucumber.class)错误。导入cucumber.api.junit.Cucumber;无法解决

时间:2018-08-12 16:49:37

标签: java maven selenium cucumber

我在所有的黄瓜跑步者文件上都遇到了这个问题。在pom.xml中使用以下依赖项。任何帮助将不胜感激。

我尝试清理并强制更新项目,然后重新启动IDE, 删除.M2中的存储库文件夹,然后清理并强制更新项目,但仍无法正常工作。

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>

<!-- Extent Reports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.26-incubating</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>2.0.4</version>
</dependency>

1 个答案:

答案 0 :(得分:0)

1。您已经添加了Cucumber-TestNG的依赖项,因此必须使用TestNG Runner语法调用Runner类。

带有TestNG的黄瓜语法:

@CucumberOptions(features = "./src/main/java/cfeature", glue = {"stepd"}, monochrome = true,  plugin = { "pretty",  "html:Reports/cucumber-pretty" })

public class runnerDemo extends AbstractTestNGCucumberTests {   

}

它将删除Junit批注@RunWith并扩展AbstractTestNGCucumberTests类。

2。如果要使用Junit运行黄瓜测试,则需要用Cucumber-Junit替换Cucumber-testng依赖度。而且您的语法会正常工作。