1

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.

bugCracker
  • 3,656
  • 9
  • 37
  • 58

2 Answers2

1
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.

SteroidKing666
  • 553
  • 5
  • 13
  • Actually, execution starts with the maven surefire plugin and there is no main method. – bugCracker Jul 20 '18 at 08:21
  • I am not sure if dependenciesToScan parameter in surefire configuration might be helpful. You could try pointing dependenciesToScan in surefire and make it point to your JAR and then use the options like you said. – SteroidKing666 Jul 20 '18 at 08:41
  • Actually I would write a main method which would execute the cucumber main method. And make sure to pass in the arguments to the cucumber main method. You should be able to use this to run Cucumber from your executable jar. Please look at my updated comment above. – SteroidKing666 Jul 20 '18 at 08:51
  • Ok let me explain again. When i run "mvn clean test -Dcucumber.options='--tags @all'" It calls pom file -> cucumber jvm paralle plugin -> Maven surefire so its maven surefire which run runner file generated by cucumber jvm parallel plugin. So i want to trigger my test using maven only because without pom.xml nothing will work. – bugCracker Jul 20 '18 at 09:34
0

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);
}
}
sadakar
  • 28
  • 9