How to run single cucumber feature files through command prompt and through jenkins using Maven?

Ronnie picture Ronnie · Jan 13, 2016 · Viewed 46.8k times · Source

I am bit new to Cucumber / Maven, so require help on running test cases. I have developed an automation suite in eclipse using Cucumber and Selenium. To run specific feature files / Junit runner class, I right-click on the files in Eclipse and run it.

But how do I run it through command prompt or Jenkins by giving specific commands to run 2-3 feature files (or) 2-3 Junit runner classes out of say 50 feature files or JUnit classes?

Below is the package explorer of how I have 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>

Answer

S&#233;bastien Le Callonnec picture Sébastien Le Callonnec · Jan 14, 2016

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

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