If we wan to run the cucumber project from command line/prompt using executable jar , we should create main method and inside it have to pass string values of cucumber options.
The options for command line differs from what we give in CucumberRunner.java (cucumber runner class with )
These options for command line are presented with -g, -p, -m and etc.
-g for glue code
-p for pretty
-m for monochrome
and to read the .feature files give "classpath:features".
The below piece of code explains how the cucumber options should be passed to main method.
Basepage.java
CucumberRunner.java
In standalone cucumber runner class options are represented with tags, glue, plugin and etc.
MANIFEST.FM
Adding main method for BasePage.java class and appropriate jar assembly plugin in pom.xml with the fully qualified class name say com.sadakar.selenium.common.BasePage
(in which main method is written), generates the MANIFEST.FM file that can be viewed if extracts the jar
(in which main method is written), generates the MANIFEST.FM file that can be viewed if extracts the jar
The options for command line differs from what we give in CucumberRunner.java (cucumber runner class with )
These options for command line are presented with -g, -p, -m and etc.
-g for glue code
-p for pretty
-m for monochrome
and to read the .feature files give "classpath:features".
The below piece of code explains how the cucumber options should be passed to main method.
Basepage.java
package com.sadakar.selenium.common;
import org.openqa.selenium.WebDriver;
public class BasePage {
public static WebDriver driver;
public static void main(String args[]) throws Throwable{
try {
cucumber.api.cli.Main.main(
new String[]{
"classpath:features",
"-t","@scenario_AccountPage",
"-g", "com.sadakar.cucumber.stepdefinitions/",
"-g","com.sadakar.cucumber.common",
"-p","pretty",
"-p","json:target/cucumber-reports/Cucumber.json",
"-p", "html:target/cucumber-reports",
"-m"
}
);
}
catch(Exception e) {
System.out.println("Main method exception");
}
}
}
CucumberRunner.java
In standalone cucumber runner class options are represented with tags, glue, plugin and etc.
package com.sadakar.cucumber.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions
(
features="classpath:features",
tags="@scenario_AddAccountPage",
glue={"com.sadakar.cucumber.stepdefinitions/","com.sadakar.cucumber.common"},
plugin = { "pretty", "json:target/cucumber-reports/Cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml",
"html:target/cucumber-reports"},
monochrome = true
)
public class CucumberRunner {
}
MANIFEST.FM
Manifest-Version: 1.0
Built-By: Sadakar
Class-Path: cucumber-java-1.2.5.jar cucumber-core-1.2.5.jar cucumber-h
tml-0.2.3.jar cucumber-jvm-deps-1.0.5.jar gherkin-2.12.2.jar cucumber
-junit-1.2.5.jar junit-4.12.jar hamcrest-core-1.3.jar selenium-java-3
.141.59.jar selenium-api-3.141.59.jar selenium-chrome-driver-3.141.59
.jar selenium-edge-driver-3.141.59.jar selenium-firefox-driver-3.141.
59.jar selenium-ie-driver-3.141.59.jar selenium-opera-driver-3.141.59
.jar selenium-remote-driver-3.141.59.jar selenium-safari-driver-3.141
.59.jar selenium-support-3.141.59.jar byte-buddy-1.8.15.jar commons-e
xec-1.3.jar guava-25.0-jre.jar jsr305-1.3.9.jar checker-compat-qual-2
.0.0.jar error_prone_annotations-2.1.3.jar j2objc-annotations-1.1.jar
animal-sniffer-annotations-1.14.jar okhttp-3.11.0.jar okio-1.14.0.ja
r log4j-1.2.17.jar poi-4.1.0.jar commons-codec-1.12.jar commons-colle
ctions4-4.3.jar commons-math3-3.6.1.jar poi-ooxml-4.1.0.jar poi-ooxml
-schemas-4.1.0.jar commons-compress-1.18.jar curvesapi-1.06.jar xmlbe
ans-3.1.0.jar poi-scratchpad-4.1.0.jar
Created-By: Apache Maven 3.6.3
Build-Jdk: 1.8.0_181
Main-Class: com.inovalon.selenium.common.BasePage
maven-assembly-plugin in pox.xml
maven-assembly-plugin in pox.xml
<plugin>
<!-- NOTE: We don't need a groupId specification because the group is
org.apache.maven.plugins ...which is assumed by default.
-->
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.sadakar.selenium.common.BasePage</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Eclipse command to generate the jar from Maven build:
clean compile assembly:single install
Hope this helps someone in the community.
Cheers.!
Sadakar Pochampalli