简体   繁体   English

如何使用 jar 文件运行 mvn cucumber 测试?

[英]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.

相关问题 mvn clean install执行黄瓜测试以执行jar文件 - mvn clean install to execute Cucumber test for executing a jar file 如何使用jar运行黄瓜? - How run cucumber using jar? Spring Boot的黄瓜测试可以在“mvn test”中运行,但不能在“mvn verify”中运行 - Cucumber test for Spring Boot can run in “mvn test” but not in “mvn verify” 没有“测试运行:0,失败:0,错误:0,跳过:0”,即使 cucumber 测试是使用“mvn test”命令执行的 - no "Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, " even that cucumber test was executed using "mvn test" command 如何使用 gradle 运行黄瓜测试 - How to run the cucumber test using gradle “mvn 测试” 0 次测试运行 - spring + cucumber + junit5 - "mvn test" 0 tests run - spring + cucumber + junit5 如何使用Selenium-Junit测试运行程序文件以及黄瓜选项为每次运行创建测试结果文件夹? - How to create test result folder for every run using Selenium - Junit test runner file with cucumber options? 初始化错误期望文件黄瓜运行.jar - Initialization Error expected a file cucumber to run a .jar mvn exec:java在外部JAR文件中运行java文件 - mvn exec:java to run a java file in an external JAR file 如何使用Gradle并行运行黄瓜jvm测试场景? - How to run cucumber jvm test scenarios in parallel using Gradle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM