【问题标题】:Rerunning failed scenarios with Selenide/Cucumber - no rerun.txt file使用 Selenide/Cucumber 重新运行失败的场景 - 没有 rerun.txt 文件
【发布时间】:2026-02-08 06:15:01
【问题描述】:

我用 Cucumber/Selenide 编写自动化测试,我想重新运行失败的场景。

这是我项目的一部分,只有两个小测试(一个失败)来展示行为:https://github.com/mtpx/cucumberRerun

我在 How to rerun the failed scenarios using Cucumber?https://medium.com/@belek.bagishbekov/how-to-rerun-failed-test-cases-in-cucumber-b7fe9b1dcf9c 上阅读了如何操作

在@CucumberOptions 插件部分的我的application.feature 测试运行程序(ApplicationTest)中,我有一行:“rerun:rerun/failed_scenarios.txt”,根据之前的网址,它应该生成带有失败场景的文本文件,但在测试执行后使用'mvn clean test'(有失败的场景) - 没有任何 rerun.txt 文件。

你知道这里有什么问题吗?为什么构建后我没有 rerun.txt 文件? 我使用 Selenide 而不是 Selenium,也许问题就在这里?

【问题讨论】:

    标签: cucumber selenide


    【解决方案1】:

    创建另一个场景文件,如下所示。假设这是 FailedScenarios.java。每当您发现任何失败的场景时,都会运行此文件。该文件将使用 target/rerun.txt 作为运行场景的输入。

    此行是必需的:

    features = "@target/rerun.txt",
    

    全黄瓜选项

    @CucumberOptions(
        monochrome = true,
        features = "@target/rerun.txt", //Cucumber picks the failed scenarios from this file 
        format = {"pretty", "html:target/site/cucumber-pretty",
                "json:target/cucumber.json"}
      )
    public class FailedScenarios {
    
    }
    

    如果您需要运行失败的场景也可以从 maven 触发,您可以使用目标以外的重新运行文件路径,在这种情况下,更改主运行程序和失败的测试运行程序的文件中的路径

    【讨论】:

    • 我稍后会检查,但是 FailedScenarios.java 如何访问 rerun.txt 而之前失败的场景在测试失败后不会生成 rerun.txt?
    【解决方案2】:

    问题解决了 :) 在 pom 我有一行:

    -Dcucumber.options="--plugin io.qameta.allure.cucumberjvm.AllureCucumberJvm"
    

    此行覆盖 TestRunner 中的所有插件信息

    【讨论】:

      最近更新 更多