[英]How to run a Cucumber-JVM feature file from the command line
I have a file with file extension .feature
.我有一个文件扩展名为
.feature
的文件。 HOw do run this from the command line?如何从命令行运行它?
In order to make a batch file for each feature.为了为每个功能制作一个批处理文件。 I am using Cucumber-JVM with Java and Selenium .
我将Cucumber-JVM与 Java 和Selenium 一起使用。
Cucumber-JVM is based on JUnit so its just like running any unit tests from the command line Cucumber-JVM基于JUnit,因此它就像从命令行运行任何单元测试一样
java -cp /path/to/junit.jar org.junit.runner.JUnitCore [test class name]
where test class name
is annotated with @CucumberOptions
whose features
refer to the feature file. 其中
test class name
使用@CucumberOptions
注释,其features
引用功能文件。 If youre using Maven you could use 如果您使用Maven,您可以使用
mvn test
If you are using Maven, you can run your .feature
file this way: 如果您使用的是Maven,则可以通过以下方式运行
.feature
文件:
mvn -Dcucumber.options="from/the/root/of/module/to/the/feature/MyFeature.feature" test
This will override the @CucumberOptions
in the test runner class. 这将覆盖测试运行器类中的
@CucumberOptions
。
You can run any test runner or override default test runner by using the command line below.您可以使用下面的命令行运行任何测试运行程序或覆盖默认测试运行程序。 This means you only want to run the test named SmokeTestRunner.
这意味着您只想运行名为 SmokeTestRunner 的测试。 By the way, you are free to set surefire plugin in your pom.xml any way.
顺便说一句,你可以随意在你的 pom.xml 中设置surefire插件。 For example, you can set up your surefire plugin in your pom.xml to run the regression test named RegressionTestRunner.
例如,您可以在 pom.xml 中设置您的万能插件来运行名为 RegressionTestRunner 的回归测试。 It doesn't matter.
没关系。
mvn -Dtest=**/SmokeTestRunner.java test
mvn -Dtest=**/SmokeTestRunner.java测试
Your SmokeTestRunner java file should look like this.您的 SmokeTestRunner java 文件应如下所示。 ->
->
@CucumberOptions(
features = "src/test/resources/features/Smoke.feature",
glue = {"stepdefinitions", "hooks"},
tags = "@chrome", // It runs only scenarios tagged with "@chrome"
plugin = {"pretty"/*you can add more cucumber plugins here if you want.*/},
monochrome = true)
public class SmokeTestRunner extends AbstractTestNGCucumberTests {}
For more details, have a look at the maven surefire plugin docs.有关更多详细信息,请查看 maven surefire 插件文档。 ( https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html )
( https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.