简体   繁体   中英

How to run mvn cucumber test using jar file?

I have created a test automation framework using maven and cucumber.

1) I want to create a jar file which includes everything (all project files)

2) Then I want to run a test from the command line using above created jar like using the command

( 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. If you don't use the main method it will just become too complicated.

Update:

Write a main method and run Cucumber main method from it. The arguments are what you would pass in as your Cucumber command line arguments.

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.

The below code worked for me to execute the cucumber tests from runnable jar with test frame work as TestNG.

Executing 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);
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM