繁体   English   中英

如何在 Cucumber 中重新运行失败的场景

[英]How to rerun failed scenarios in Cucumber

我在我们的项目中使用 Cucumbe 编写自动化测试,并使用 gradle 依赖项中的插件,例如 Junit。 但是,某些场景失败了,主要是由于超时原因,然后重新运行它们将是一个永久的解决方案。

我试过以下代码:

Run our test classes
@RunWith(CustomCucumber.class)
@CucumberOptions(
        junit = "--filename-compatible-names",
        features = "src/test/resources/features",
        glue = {"stepdefinition", "main", "hooks"},
        tags = {"@MyScenario", "@5"},
        plugin = {
                "pretty",
                "json:target/cucumber-reports/CucumberTestReport.json",
                "com.github.kirlionik.cucumberallure.AllureReporter",
                "html:target/cucumber-repoIrts/cucumber-pretty",
                "com.cucumber.listener.ExtentCucumberFormatter:",
                "rerun:target/rerun.txt"
        }
)

public class RunTest { }

重新运行失败的场景:

@RunWith(CustomCucumber.class)
@CucumberOptions(
        junit = "--filename-compatible-names",
        features = "@target/rerun.txt",
        glue = {"stepdefinition", "main", "hooks"},
        plugin = {
                "pretty",
                "json:target1/cucumber-reports/CucumberTestReport.json",
                "com.github.kirlionik.cucumberallure.AllureReporter",
                "junit:target1/cumcumber.xml",
                "html:target1/cucumber-repoIrts/cucumber-pretty",
                "com.cucumber.listener.ExtentCucumberFormatter:",
        }
)
public class RunTestRerun {
}

我看到文件是在目标文件夹中生成的,但是当我尝试运行 rerun.txt 时,它会引发异常:

java.lang.IllegalArgumentException: Neither found on file system or on classpath: Not a file or directory: C:/mytest/Signup/Client/Client.feature, No resource found for: classpath:Signup/Client/Client.feature
    at cucumber.runtime.model.CucumberFeature.loadFromFileSystemOrClasspath(CucumberFeature.java:84)
    at cucumber.runtime.model.CucumberFeature.loadFromRerunFile(CucumberFeature.java:67)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:52)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:34)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:239)
    at runner.CustomCucumber.CustomCucumber.<init>(CustomCucumber.java:68)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

[SETUP ERROR] Neither found on file system or on classpath: Not a file or directory: C:/mytest/Signup/Client/Client.feature, No resource found for: classpath:Signup/Client/Client.feature

重新运行.txt

Signup/Client/Client.feature:30

关于我如何解决这个问题的任何想法?

在 eclipse 中运行失败的测试用例时,我遇到了类似的问题。 我将类路径指向我的功能文件在项目中的文件夹。 您可以按照以下步骤操作:
1)右键单击项目和Go运行配置
2)点击类路径
3)在用户条目下选择您的项目,然后单击高级
4)点击添加文件夹
5)然后 select 您的项目文件夹中的功能文件,然后单击应用。

尝试重新运行失败的运行器,它应该在此之后运行。 如果您再次将 go 转到类路径,那么您将在失败的跑步者可以引用的用户条目下找到添加的类路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM