Unable to run Cucumber tests from maven

Susanta Adhikary picture Susanta Adhikary · Aug 12, 2014 · Viewed 7.7k times · Source

My Maven Project Structure is

enter image description here

The project runs well If I try to run it through eclipse as JUnitTest (CucumberRunnerTest.java).

But if I try executing it through maven then I get the below error:

The pom is as below:

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

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


 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber-jvm.version>1.1.8</cucumber-jvm.version>
    <selenium.version>2.42.2</selenium.version>
    <junit.version>4.11</junit.version>
    <cucumber.options>--format pretty --tags @Search</cucumber.options>
 </properties>

<build>
<plugins>
    <plugin>

         <groupId>org.codehaus.mojo</groupId>
           <artifactId>exec-maven-plugin</artifactId>
                <version>1.3.2</version>
                 <executions>
                    <execution>
                      <phase>integration-test</phase>

                        <goals>
                            <goal>java</goal>
                        </goals>

                    </execution>
                 </executions>
   <configuration>

            <classpathScope>test</classpathScope>
            <mainClass>cucumber.api.cli.Main</mainClass>

            <arguments>
                <argument>--format</argument>
                <argument>junit:output/cucumber-junit-report/allcukes.xml</argument>
                <argument>--format</argument>
                <argument>pretty</argument>
                <argument>--format</argument>
                <argument>html:output/cucumber-html-report</argument>
                <argument>--format</argument>
                <argument>json:output/cucumber_report.json</argument>

                <argument>--glue</argument>
                <argument>src\</argument>
                <argument>src\main\resource\com\ericsson\</argument>
                </arguments>
    </configuration>
 </plugin>

 </plugins>
 </build>

 <dependencies>
 <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber-jvm.version}</version>
        </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber-jvm.version}</version>
<scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>

    </dependency>
    <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0-rc1</version>
</dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
<scope>test</scope>
    </dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.3</version>

</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>

</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin-jvm-deps</artifactId>
<version>1.0.2</version>

</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber-jvm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
 <artifactId>cucumber-reporting</artifactId>
 <version>0.0.23</version>
 <scope>test</scope>
  </dependency>
 <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>${cucumber-jvm.version}</version>
        <scope>test</scope>
        </dependency>

  <dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
 </dependency>
    <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.1.1</version>
    </dependency>



   </dependencies> 
  </project>

When run from command prompT******* mvn integration-test

[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenCuke ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenCuke ---
   [INFO] Building jar: C:\Users\esusadh\MavenCucumber\MavenCuke\target\MavenCuke-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- exec-maven-plugin:1.3.2:java (default) @ MavenCuke ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please commenon MEXEC-6.
Feature: Navigating into ericsson.com and verify text

  In order to verify tags
  I open browser
  and I navigate to ericsson.com
  I verify the search text.

 @Search
 Scenario Outline: Searching for text                          ←[90m# Cucumber.
feature:9←[0m
 ←[36mGiven ←[0m←[36mI go to "URL" on "<Browser>"←[0m
←[36mWhen ←[0m←[36mI click on "Links"←[0m
←[36mThen ←[0m←[36mI verify for "Search_Text" against "<Expected_Result>"←[0m

Examples:

 @Search
Scenario Outline: Searching for text                  ←[90m# Cucumber.feature:16←[0m
←[33mGiven ←[0m←[33mI go to "URL" on "Mozilla"←[0m
←[33mWhen ←[0m←[33mI click on "Links"←[0m
←[33mThen ←[0m←[33mI verify for "Search_Text" against "The Company"←[0m

1 Scenarios (←[33m1 undefined←[0m)
3 Steps (←[33m3 undefined←[0m)0m0.000s


You can implement missing steps with the snippets below:

@Given("^I go to \"(.*?)\" on \"(.*?)\"$")
public void i_go_to_on(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@When("^I click on \"(.*?)\"$")
public void i_click_on(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@Then("^I verify for \"(.*?)\" against \"(.*?)\"$")
public void i_verify_for_against(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

where as I have implemented this steps in Search_Text.java.

IF I use maven-compiler plugin and run it through maven I get package cucumber.api.junit.Cucumber does not exists!! ( below is the pluggin added in POM)

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

        <version>3.1</version>

        <configuration>

          <source>1.7</source>

            <target>1.7</target>
<includes>
<include>**/*Test.java</include>
</includes>
        </configuration>

    </plugin>
    <plugin>

Answer

Bozho picture Bozho · Aug 12, 2014

As --glue you should specify the package name of your java test classes