【问题标题】:Automatically re-run failed only scenario in cucumber java+testng在黄瓜 java+testng 中自动重新运行失败的唯一场景
【发布时间】:2018-07-17 13:16:31
【问题描述】:

我怎样才能让失败的场景在失败时自动再次运行?

这是我在做什么的一些线索:

  • 在运行时通过 cucumber-testng.xml 文件从命令行传递 TestRunner 类。
  • 场景失败后我可以看到 rerun.txt 文件,feature/GM/TK/payment.feature:71(指向失败的场景)但失败的场景不会自动重新运行。

“TestRunner”java 文件

@RunWith(Cucumber.class)
@CucumberOptions(strict = true, 
    features = { "src/test/resources/" },  //feature file location
    glue = { "com/test/stepdefs", "com.test.cucumber.hooks" },  //hooks and stepdef location
    plugin = { "json:target/cucumber-report-composite.json", "pretty", "rerun:target/rerun.txt"}
)
public class CucumberTestRunner extends AbstractTestNGCucumberTests
{
}

从 rerun.txt 文件重新运行的“RunFailedTest”类

@RunWith(Cucumber.class)
@CucumberOptions(
    strict = false,
    features = { "@target/rerun.txt"  },  //rerun location
    glue = { "com/test/stepdefs", "com.test.cucumber.hooks" }, //hooks and stepdef location
    plugin = {"pretty", "html:target/site/cucumber-pretty", "json:target/cucumber.json"}
)
class RunFailedTest
{
}

【问题讨论】:

  • 您是希望动态识别失败的测试以重新运行,还是只是手动将它们分离到另一个文件中?看起来像后者,在这种情况下,您应该考虑使用 tags 并在 CucumberOptions 中指定它们。
  • jsheeran 是的,动态失败的场景存储在 rerun.txt 中,并在第一次执行完成后立即自动运行,因为失败发生
  • 为什么 CucumberTestRunner 中既有 junit 又有 testng?并且只有在 RunFailedTest 中的 junit?你是如何进行测试的?

标签: testing cucumber-java


【解决方案1】:

您可以通过使用gherkin with qaf 来实现它,它会为失败的场景生成 testng XML 配置,您可以将其用于重新运行。它还支持通过设置retry.count 属性在失败时重新运行场景。

【讨论】:

    【解决方案2】:

    使用 Cucumber + Maven + TestNG 首先,您不需要像您在问题中提到的“@RunWith(Cucumber.class)”,如果您使用的是TestNG,则只需要"@CucumberOptions"。 当您开始执行测试时,所有场景失败都将根据您的 Runner 文件中提到的配置写入文件 "target/rerun.txt"。 现在,您需要再创建一个 Runner 文件(例如 - “FailureRunner”),并在此文件中提供 "@target/rerun.txt" 的路径(这已经包含失败场景的详细信息)为 -> features = { "@target/rerun.txt" }

    现在,您需要更新您的 TestNG.xml 文件并包含“FailureRunner”,如下所示 -

        <class name="Class path of Your First Runner Class name" />
        <class name="class path of FailureRunner Class" />
    

    一旦您完成上述所有步骤并运行您的执行,第一次执行将在"target/rerun.txt" 中写入失败场景,之后,将执行“FailureRunner”类,该类将获取"@target/rerun.txt" 文件和因此,将执行失败场景。

    我用同样的方法执行过,效果很好,如果有帮助请告诉我!!

    【讨论】:

    • 在这种情况下,两个 Runner 类开始并行执行
    猜你喜欢
    • 2012-04-07
    • 2020-11-30
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多