【问题标题】:unable to run cucumber test using maven build run configuration无法使用 Maven 构建运行配置运行黄瓜测试
【发布时间】:2015-02-10 20:37:56
【问题描述】:

我正在尝试使用 maven build 作为运行配置在 Eclipse 中运行黄瓜测试。 当我运行配置时,构建成功但浏览器没有调用。因此测试没有运行。 测试被跳过,给出一个信息“没有编译 - 所有类都是最新的”。 通过将功能文件作为黄瓜功能运行,我能够成功运行相同的测试。

请告诉我为什么会跳过测试。还让我知道将黄瓜测试作为 maven 构建运行的步骤。 下面是我正在使用的 pom.xml。 我也使用 vm 参数作为“-Dcucumber.Options=--format html:target/cucumber-html-report --tags @Runme”

<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>Maven.Project</groupId>
  <artifactId>testMaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Maven.Project-v1-testMaven</name>


    <properties>
        <corporate.test.url>http://google.com</corporate.test.url>
        <corporate.test.browser>Firefox</corporate.test.browser>
        <corporate.selenium.url>http://localhost:8888/wd/hub</corporate.selenium.url>
    </properties>

  <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.1.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.1.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.42.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>test</id>
            <properties>
                <corporate.test.url>http://acc-about.hm.com</corporate.test.url>
                <corporate.test.browser>Firefox</corporate.test.browser>
                <corporate.selenium.url>http://localhost:8888/wd/hub</corporate.selenium.url>
            </properties>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>


</project>

【问题讨论】:

  • 您能展示一下您的项目的包结构以及测试运行程序和功能文件所在的位置吗?
  • 由于这里的声誉较低,我无法上传图片。但我在 src/test/resources 下创建了功能文件,在 src/test/java 下创建了步骤定义和运行器类文件。

标签: eclipse selenium-webdriver maven-2 cucumber-jvm


【解决方案1】:

请删除您的 maven - surefire 插件中的 skiptests 标签...

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
       <skipTests>true</skipTests>
</configuration>

编辑: 请在配置中添加以下行

<suiteXmlFiles>
    <suiteXmlFile>${basedir}${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>./test-output/archive/${timestamp}</reportsDirectory>

在这里,suiteXmlFile 指向您尝试运行的 xml 文件,reportsDirectory 指向您的输出文件夹。在命令行中或者如果在目标中使用 eclipse 提供干净的测试 -DsuiteFile=

希望这会有所帮助。

【讨论】:

  • 删除skiptest后,运行0个测试。测试运行:0,失败:0,错误:0,跳过:0
  • 嗨@shruti...我已经更新了答案,请检查并告诉我。
  • 谢谢维韦克。我现在可以运行测试了。问题与命名约定有关。尽管我使用的是surefire插件,但测试应该以“test”结尾。不知何故,我在 intelliJ 上没有遇到这个问题,但它发生在 Eclipse 中。
  • 对不起,我没听明白...“测试应该以测试结束”在某种意义上?
  • 比如说,你的runner类文件应该命名为“CukeRunnerTest.java”
猜你喜欢
  • 1970-01-01
  • 2020-12-19
  • 2019-12-06
  • 2017-04-20
  • 2022-11-28
  • 1970-01-01
  • 2021-07-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多