无法从 Maven 运行 Cucumber 测试

2024-02-11

我的 Maven 项目结构是

如果我尝试通过 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>

从命令提示符运行时T******** mvnintegration-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>

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法从 Maven 运行 Cucumber 测试 的相关文章

随机推荐