无法从maven运行黄瓜测试

无法从maven运行黄瓜测试

问题描述:

我的Maven项目结构

My Maven Project Structure is

项目运行良好如果我尝试通过eclipse运行JUnitTest(CucumberRunnerTest.java)。

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

但是,如果我尝试通过maven执行它,那么我得到以下错误:

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

pom如下:

<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>

从命令prompT运行******* mvn integration-test

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();
}

我在Search_Text.java中已经执行了这些步骤。

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

如果我使用maven-compiler插件,并通过maven运行它,我得到包cucumber.api.junit.Cucumber不存在! (以下是POM中添加的插件)

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>


As - glue 你应该指定你的java测试类的包名称

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