How to run single files with cucumbers through the command line and through jenkins using Maven?

I'm a little new to Cucumber / Maven, so you need help running test cases. I developed an automation suite in eclipse using Cucumber and Selenium. To run certain function files / Runit Junit class, I right-click on the files in Eclipse and run it.

But how can I run it through the command line or Jenkins, specifying specific commands to run 2-3 function files (or) 2-3 runte runter classes of 50 function files or JUnit classes?

Below is a batch example of how I am structured in Eclipse.

enter image description here

Below is the POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.perspecsys</groupId> <artifactId>salesforce</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>salesforce</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>1.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.48.2</version> </dependency> </dependencies> </project> 
+7
java selenium jenkins cucumber cucumber-jvm
source share
3 answers

You can run a single file using cucumber.options , which will override all the options that you have in the @CucumberOptions annotation:

 mvn test -Dcucumber.options="src/test/features/com/perspecsys/salesforce/featurefiles/Account.feature" 
+8
source share

Given that you are using Maven and you have a separate runner class for each function, you can simply use the Failsafe plugin or Surefire plugin to pass a parameter from the command line like this, and choose which runner to run.

Fault tolerant version:

 -Dit.test=Account*Test,Login*Test 

Surefire Version:

 -Dtest=Account*Test,Login*Test 

Note that you can use wildcards, pass a comma-separated list of tests, and indicate the full location and filter by packages.

 -Dit.test=com.perpecsys.salesforce.*Test 

For this, I would usually use the Failsafe plugin, since Cucumber tests more similar integration tests (end-to-end tests really), and this plugin is needed for this, while the Surefire plugin is designed to run device tests.

Additional information about both plugins:

http://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html

http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

From Jenkins, this is exactly the same, just use the Maven Project plugin to create a new Maven project and in the "Assembly" section in the "Target and Parameters" field, specify the maven command, for example:

 clean verify -Dit.test=Account*Test 

https://wiki.jenkins-ci.org/display/JENKINS/Maven+Project+Plugin

Alternatively, simply add the maven assignment step for the top level Invoke to the assembly if you are not using the Maven Project Plugin and add options there.

Hope this helps.

+2
source share

If you want it to be hardcoded, you could do something like:

 import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features={"src/test/resources/features/belly.feature"} ,glue = "steps" //whatever the name of your steps package is ) public class RunCukesTest { } 
+2
source share

All Articles