Tuesday, 31 March 2020

Automating JasperReports Server Login Page using java-selenium-cucumber | Video tutorial on how to run cucumber project from jar file ?

Hi,

In this post, I'd like to share my experience on automating jaspersoft login page using valid (not invalid) credentials using cucumber frame work.

The core of this post is how to generate jar file to run the cucumber project/features from command prompt. You can watch the below  video tutorial for the whole project flow, coding inputs, etc. and I hope this will be helpful for someone in the community.

Watch this ~15 min video tutorial for the cucumber execution flow and for some coding inputs




Below are the steps for core part that is how to generate jar and run cucumber project from jar file.

1) In the pom.xml ensure to provide plugin details for jar and mainClass.
    This is used to generate the manifest file where the project execution starts when execute the jar from command prompt.

2) Write a main method and pass the cucumber options as String to the Main class.

3) Run the project as Maven build by providing : clean package shade:shade 

4) Note down the path of the generated jar

5) Open command prompt and navigate to the path run this command
          java -jar <GeneratedJarFile>


pom.xml plugin snippet for jar:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
      <archive>
          <manifest>
             <addClasspath>true</addClasspath>
                <mainClass>com.sadakar.selenium.common.BasePage</mainClass>
          </manifest>
      </archive>
                </configuration>

</plugin>

calling main method with cucumber options as input
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","@ValidLogin",
"-g", "com.sadakar.cucumber.stepdefinitions/", 
"-g","com.sadakar.cucumber.common",
"-p","pretty", 
"-p","json:target/cucumber-reports/Cucumber.json",
"-p", "html:target/cucumber-reports",

}
             ); 
}
catch(Exception e) {
System.out.println("Main method exception");
}

}

}

Build the jar file : clean package shade:shade


Navigate to the target folder where jar is generated and running it.
C:\Users\sadakar\eclipse-workspace\Jaspersoft Automation\target>java -jar Jaspersoft_Automation-0.0.1-SNAPSHOT.jar

Click on the image to get the best view of the content:


Sample output:

No comments:

Post a Comment