Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run cucumber-jvm tests with maven

How do I run the cucumber tests that I have in the following locations with Maven.

Source folders 'src/main/java' and 'src/main/resources' include step definitions and feature files in package 'com.testing.TestProject.login' created in each source folder.

I have included plugins and dependencies in the POM file but when I run maven phase integration-test, cucumber tests are not getting executed.

I'm new to Maven. Please let me know what to include in the POM file to run the cucumber tests with Maven.

Here is my POM file:

   <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.testing</groupId>
  <artifactId>MyMavenProject</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>MyMavenProject</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber-jvm.version>1.1.5</cucumber-jvm.version>
    <selenium.version>2.39.0</selenium.version>
    <junit.version>4.11</junit.version>
  </properties>

    <build>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executableDependency>
                    <groupId>info.cukes</groupId>
                    <artifactId>cucumber-core</artifactId>
                </executableDependency>
                <mainClass>cucumber.api.cli.Main</mainClass>
                <arguments>
                    <argument>--format</argument>
                    <argument>junit:target/cucumber-junit-report/allcukes.xml</argument>
                    <argument>--format</argument>
                    <argument>pretty</argument>
                    <argument>--format</argument>
                    <argument>html:target/cucumber-html-report</argument>
                    <argument>--tags</argument>
                    <argument>@login</argument>
                    <argument>--glue</argument>
                    <argument>com/</argument>
                    <argument>src/</argument>
                </arguments>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>info.cukes</groupId>
                    <artifactId>cucumber-core</artifactId>
                    <version>1.1.5</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>  

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber-jvm.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber-jvm.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.8.7</version>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.3</version>
</dependency>
</dependencies>
</project>

Thanks in advance.

like image 744
user3188928 Avatar asked Feb 02 '14 19:02

user3188928


People also ask

How do I run Cucumber tests from POM XML?

Run Test from Command Line Open the command prompt and change the directory to the project location where pom. xml is present. 2. All feature files should be in src/test/resources and create the Cucumber Runner class as CucumberRunnerTest.


1 Answers

Your test classes need to end with the Test suffix.

like image 131
Sergiu Indrie Avatar answered Sep 22 '22 05:09

Sergiu Indrie