gpt4 book ai didi

java - Maven Surefire 插件没有重新运行失败的 Cucumber 测试

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:57:32 24 4
gpt4 key购买 nike

我正在使用 Selenium WebDriver(2.53.0 版)的 Java 实现对 Web 应用程序运行一些自动化测试。这些测试是使用 Cucumber(1.2.3 版)的 Java 实现以行为驱动测试格式编写的。我使用 Maven(3.3.9 版)来导入我所有的依赖项,并构建和运行测试。使用 Cucumber 标签将测试组织成不同的类别。例如,我可以使用以下命令从命令行运行一类标记为 @JohnnyBravo 的测试:

cd path_to_Maven_POM_file
mvn clean test -Dcucumber.options="--tags @JohnnyBravo"

经过一些研究,我发现您可以使用 Maven SureFire 插件重新运行失败的测试,方法是根据这个 link 向上面的 Maven 命令添加“-Dsurefire.rerunFailingTestsCount=2”。然后我尝试使用下面的命令重新运行该类别的测试,同时确保其中一些肯定会失败,以便查看它们是否会重新运行:

mvn clean test -Dcucumber.options="--tags @JohnnyBravo" -Dsurefire.rerunFailingTestsCount=2

不幸的是,失败的测试没有重新运行。我在这里做错了什么?

我的POM文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<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.company</groupId>
<artifactId>regression-test</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<cucumber.version>1.2.3</cucumber.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.2</version>
</dependency>

<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>com.pojosontheweb</groupId>
<artifactId>monte-repack</artifactId>
<version>1.0.1</version>
</dependency>

</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>src/test/resources/chromedriver/chromedriver.exe</webdriver.chrome.driver>
</systemPropertyVariables>
<!--<testFailureIgnore>true</testFailureIgnore>-->
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

Cucumber JUnit 测试运行器类如下所示:

import com.cucumber.listener.ExtentCucumberFormatter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import java.io.File;
import java.util.HashMap;

@RunWith(Cucumber.class)
@CucumberOptions(
monochrome = false,
plugin = {
"pretty",
"html:C:/Test_Output_Data/Results/HTML/",
"json:C:/Test_Output_Data/Results/results.json",
"com.cucumber.listener.ExtentCucumberFormatter"
},
features = {"src/test/resources/"},
tags = {
"@JohnnyBravo",
//"@AgentUI", "@Smoke",
//"@GenUI", "@Smoke",
//"@GenUI", "@Regression",
}
)
public class GeneralRunnerTest {

@BeforeClass
public static void setup() {
ExtentCucumberFormatter.initiateExtentCucumberFormatter();
ExtentCucumberFormatter.loadConfig(new File("src/test/resources/extent-config.xml"));

ExtentCucumberFormatter.addSystemInfo("Browser Name", "Firefox");
ExtentCucumberFormatter.addSystemInfo("Browser version", "46.0.1");
ExtentCucumberFormatter.addSystemInfo("Selenium version", "2.53.0");

HashMap<String, String> systemInfo = new HashMap<>();
systemInfo.put("Cucumber Version", "1.2.3");
systemInfo.put("Extent Cucumber Reporter Version", "1.1.0");
ExtentCucumberFormatter.addSystemInfo(systemInfo);
}
}

最佳答案

检查您是否为 cucumber 依赖项使用了正确的版本。

关于 page for this feature on the surefire website , 它说

Since of 2.21.0 the provider surefire-junit47 can rerun scenarios created by cucumber-jvm 2.0.0 and higher.

同时检查您使用的是否与他们提到的相同的 junit 提供程序。我不确定哪个是默认提供程序。

关于java - Maven Surefire 插件没有重新运行失败的 Cucumber 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38265317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com