Cucumber Run Command Line

Cucumber Tests can be run from the command line in different ways. JUnit and Maven are used majorly to run tests.

We would be using a Maven project as it has a lot of advantages over other build tools, such as dependency management, available plugins and can easily run integration tests, it can integrate with Jenkins and supports parallel execution.

If it is needed to run from the command line, then we need to download Maven (https://maven.apache.org/download.cgi ), and add the path to the Maven install \bin directory to your Windows system path, open cmd and use mvn –version to check installed OK. Let look at how to do that in detail.

Setup Maven Project

Step 1: Create a Maven project

Step 2: Add below dependencies to Pom.xml

 

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>


  <groupId>ToolsQA</groupId>

  <artifactId>CucumberFramework</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>jar</packaging>

<name>CucumberFramework</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.12</version>

                    <scope>test</scope>

                 </dependency>

    <dependency>

                    <groupId>org.seleniumhq.selenium</groupId>

                    <artifactId>selenium-java</artifactId>

                    <version>3.7.0</version>

                </dependency>

                <dependency>

                    <groupId>info.cukes</groupId>

                    <artifactId>cucumber-java</artifactId>

                    <version>1.2.5</version>

                </dependency>

                <dependency>

                    <groupId>info.cukes</groupId>

                    <artifactId>cucumber-jvm-deps</artifactId>

                    <version>1.0.5</version>

                    <scope>provided</scope>

                </dependency>

                <dependency>

                    <groupId>info.cukes</groupId>

                    <artifactId>cucumber-junit</artifactId>

                    <version>1.2.5</version>

                    <scope>test</scope>

                </dependency>

                <dependency>

                    <groupId>info.cukes</groupId>

                    <artifactId>cucumber-picocontainer</artifactId>

                    <version>1.2.5</version>

                    <scope>test</scope>

                </dependency>

                <dependency>

                    <groupId>com.aventstack</groupId>

                    <artifactId>extentreports</artifactId>

                    <version>3.1.2</version>

                </dependency>

                <dependency>

                    <groupId>com.vimalselvam</groupId>

                    <artifactId>cucumber-extentsreport</artifactId>

                    <version>3.0.2</version>

                </dependency>

  </dependencies>


   <build>
           <plugins>

                <plugin>

                     <groupId>org.apache.maven.plugins</groupId>

                     <artifactId>maven-compiler-plugin</artifactId>

                     <version>3.7.0</version>

                     <configuration>

                     <source>1.8</source>

                    <target>1.8</target>

                      <encoding>UTF-8</encoding>        

                  </configuration>

              </plugin>                                                                         

      </plugins>

</build>

</project>

 

Step 3: Add feature file, Step definition under src/main and create Test Runner under src/test

 

Run Tests from Command Line

Step 1: Open the command prompt and navigate to the project root directory.

Step 2: Run the following command in the command prompt: mvn test

Running the above command will trigger the test runner file, as src/test package we have added Test Runner.

All the features and step definitions are added to the Test Runner. Thus, internally all files will get executed.

Step 3: Build Success Output will be displayed