java - 无法从 Maven 运行 Cucumber 测试

标签 java eclipse selenium-webdriver maven-2 cucumber-junit

我的 Maven 项目结构是

enter image description here

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

但是,如果我尝试通过 maven 执行它,则会出现以下错误:

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 运行时

[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 中实现了这些步骤。

如果我使用 maven-compiler 插件并通过 maven 运行它,我得到包 cucumber.api.junit.Cucumber 不存在!! (下面是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>

最佳答案

作为--glue你应该指定你的java测试类的包名

关于java - 无法从 Maven 运行 Cucumber 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25258927/

相关文章:

java - AnyLogic:狄利克雷分布的实现?

eclipse - 在 Eclipse 中提交失败

python - Selenium - 发送 key - 我应该使用什么元素

python - 如何使用 Selenium 找到一行并单击表格中的表格元素?

java - 压缩这段代码?

java - 损坏的 NTFS 文件夹 java

eclipse - 如何使Helios中的Eclipse快捷方式再次起作用?

java - JFrog Artifact 要做的基本设置

python - splinter - 奇怪的 ElementNotVisible 异常,链接在转储的 html/屏幕截图中确实可见

java - JavaMail 中使用哪种方法获取 CC 和 BCC 列表中给出的邮件 ID?