0

Trying to Achieve:

Run cucumber test cases configured in runner class using Maven.

Issue:

Configured test cases are not being executed using maven.

Configured pom.xml 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>simplify360Cucumber</groupId>
    <artifactId>s360UIAutomation</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>Cucumber-JVM template</name>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
            <version>2.24</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>3.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.16</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.16</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.8.0</version>
        </dependency>
        <!-- <dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-junit</artifactId> 
            <version>2.6</version> </dependency> -->
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20</version>
                    <configuration>
                        <includes>
                            <include>**/helpers.RunCukesTest.java</include>
                        </includes>
                        <!-- <excludes> <exclude>**/*RunCukesTest.java</exclude> </excludes> -->
                    </configuration>
                    <!-- <dependencies> <dependency> <groupId>org.apache.maven.surefire</groupId> 
                        <artifactId>surefire-junit</artifactId> <version>2.6</version> </dependency> 
                        </dependencies> -->
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

And the runner class is like this

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:features"},
        plugin = {"pretty", "html:target/cucumber-html-report","json:target/cucumber.json"},
        tags = {"@tag1"},
        glue={"helpers","stepDefinitions"},
//      dryRun = true,
        monochrome = true
        )
public class RunCukesTest{

}

When maven test or maven install are executed from eclipse, test cases are not getting executed but the build is successfull.

Nagarjuna Reddy
  • 759
  • 9
  • 19
  • 39
  • `**/helpers.RunCukesTest.java` looks strange, shouldn't it be `**/helpers/RunCukesTest.java`? – Tome Jun 01 '17 at 12:58
  • @Tome Tried `**/*RunCukesTest.java`. same result – Nagarjuna Reddy Jun 01 '17 at 13:07
  • Is the 'helpers\RunCukesTest' is inside the '\src\test\java' folder hierarchy? Also by default maven should pick up this test class as it matches the acceptable patterns. - http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html – Grasshopper Jun 01 '17 at 13:31
  • @Grasshopper helpers\RunCukesTest this is under `src/main/java` – Nagarjuna Reddy Jun 01 '17 at 16:12
  • 1
    move it under '\src\test\java' and try... – Grasshopper Jun 01 '17 at 17:38
  • @Grasshopper may i know why it has to be under test instead of main folder – Nagarjuna Reddy Jun 01 '17 at 17:59
  • surefire looks for test sources from the value of testSourceDirectory. By default it is set to '\src\test\java'. So either you place your test classes in this or change the value of testSourceDirectory. --- http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#includes – Grasshopper Jun 01 '17 at 18:08
  • @Grasshopper if i move to package to test/java, tests are getting executed. But i'm looking to change the test directory. let me try that – Nagarjuna Reddy Jun 01 '17 at 18:23

1 Answers1

0
import org.apache.log4j.Logger;
import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty", "json:target/Cucumber-report/cucumber.json" },
    features = { "src/test/resources/com/testcases/testsuite" })

public final class CucumberCommandLineTest {

private CucumberCommandLineTest() {
}

static final Logger LOGGER = Logger.getLogger(CucumberCommandLineTest.class.getName());

}

This seems to work for me for running at the CLI :

C:\Tools\jdk1.7.0_79\bin\java" -cp lib\*;target\62110_Automation_KW_Smoke_Test-1.0.0.0-jar-with-dependencies.jar cucumber.api.cli.Main --glue com.gm.testcases .\src\test\resources\com\testcases\testsuite --tags @TC_185826,@TC_185824 --plugin pretty

in src/main/java and when doing maven clean:install through Eclipse m2e plugin.