[英]How to run mvn cucumber test using jar file?
I have created a test automation framework using maven and cucumber.我使用 maven 和 cucumber 创建了一个测试自动化框架。
1) I want to create a jar file which includes everything (all project files) 1)我想创建一个包含所有内容(所有项目文件)的 jar 文件
2) Then I want to run a test from the command line using above created jar like using the command 2)然后我想使用上面创建的 jar 从命令行运行测试,就像使用命令一样
( mvn clean test -Dcucumber.options='--tags @all'
) (
mvn clean test -Dcucumber.options='--tags @all'
)
I don't want to use the main method or anything.我不想使用主要方法或任何东西。
java -Dcucumber.options="--tags @all" -jar your-test-jar.jar
Try this. 尝试这个。 Although I am not sure why you don't want to use the main method.
尽管我不确定为什么您不想使用main方法。 If you don't use the main method it will just become too complicated.
如果不使用main方法,它将变得过于复杂。
Update: 更新:
Write a main method and run Cucumber main method from it. 编写一个main方法并从中运行Cucumber main方法。 The arguments are what you would pass in as your Cucumber command line arguments.
参数是您将作为Cucumber命令行参数传递的参数。
public static void main(String[] args) throws Throwable {
String[] arguments = {"a", "b"};
cucumber.api.cli.Main.main(arguments);
}
If I have understood your question clearly, this might do your work. 如果我清楚地理解了您的问题,则可以完成您的工作。
This should help you run Cucumber from your executable. 这应该可以帮助您从可执行文件运行Cucumber。
The below code worked for me to execute the cucumber tests from runnable jar with test frame work as TestNG.下面的代码对我有用,可以从可运行的 jar 执行 cucumber 测试,测试框架为 TestNG。
Executing jar: java -jar ProductsAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar执行 jar: java -jar ProductsAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar
import io.cucumber.core.cli.Main;
public static void main(String args[]) throws Throwable {
try {
Main.main(new String[] {
"-g","com.sadakar.cucumber.common",
"-g","com.sadakar.cucumber.runner",
"classpath:features",
"-t","@SmokeTest",
"-p", "pretty",
"-p", "json:target/cucumber-reports/cucumber.json",
"-p", "html:target/cucumber-reports/cucumberreport.html",
"-m"
}
);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Main method exception : " + e);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.