Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 919
Ronnie Avatar asked Jan 13 '16 16:01

Ronnie


People also ask

How do I run a cucumber test in Maven?

Run Cucumber Test from Command Line / Terminal. There are different ways to run Cucumber Test from command line. Tests can be run by using JUnit and Maven as well. But maven is the most suggested way and has extra benefits to it. This is why we started this Project as Maven project.

How to run cucumber scenarios from the command prompt?

1. Open the command prompt and cd until the project root directory. 2. First, let’s run all the Cucumber Scenarios from the command prompt. Since it’s a Maven project and we have added Cucumber in test scope dependency and all features are also added in src/test packages, run the following command in the command prompt: mvn test

How do I run a cucumber class In JUnit?

Here’s how: First, create a Class that ends with Test in name. For example, CucumberTest.java. I noticed that if your class name doesn’t end with Test, maven doesn’t call that Class. Next, add a @RunWith annotation in your class and put Cucumber.class inside. It defines how JUnit can run your class.

How to add dependency for cucumber-Java in Maven?

Add dependency for Cucumber-Java − This will indicate Maven, which Cucumber files are to be downloaded from the central repository to the local repository. Create one more dependency tag. Provide the following information within the dependency tag.


2 Answers

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"

EDIT (Jun 2021): Subsequent versions removed the cucumber.options construct and replaced it. One way to achieve the same result now is through the use of tags. Place a tag on top of your feature file (example @feature_file_name) and then run the following command:

mvn test -Dcucumber.filter.tags='@feature_file_name'
like image 91
Sébastien Le Callonnec Avatar answered Oct 21 '22 01:10

Sébastien Le Callonnec


You can run a single feature file by using cucumber.options

mvn test -Dcucumber.options="--tags @TestTag"
like image 24
user6939 Avatar answered Oct 21 '22 00:10

user6939