Search code examples
gradlecucumbercucumber-junitcucumber-serenity

Rerun runnerclass is running before the original runner class in cucumber


CucumberSerenityBDDAPIAutoRunner
CucumberSerenityBDDUIAutoRunner
CucumberSerenityBDDUIReRunner

Are my runner classes lying in one folder. I have chosen alphabetical increasing order to run the rerunner class at the end.

@RunWith(CucumberWithSerenity.class)

@CucumberOptions(features= “src/test/resources/features/ui/“, glue = “com.xxxx.xxxx.xxxx.features”, plugin = {“pretty”,“rerun:target/failedrerun.txt”}, monochrome = true, tags = “@envr=stagging and @UI”)

public class CucumberSerenityBDDUIAutoRunner {
    @WithTag(“envr:stagging”)
    public void run_stagging_tests(){}

    @WithTag(“envr:prod”)
    public void run_production_tests(){}
}
@RunWith(CucumberWithSerenity.class)

@CucumberOptions(features= {“@target/failedrerun.txt”}, glue = “com.xxxx.xxxx.xxxx.features”, plugin = “pretty”, monochrome = true, tags = “@envr=stagging and @UI”)

public class CucumberSerenityBDDUIReRunner {
    @WithTag(“envr:stagging”)
    public void run_stagging_tests(){}

    @WithTag(“envr:prod”)
    public void run_production_tests(){}
}

These are my two concreate runner classes.

Error which I am receing from the gradle run is below since the rerunner is running before the original runner:

com.xxxx.xxxx.xxxx.features.CucumberSerenityBDDUIReRunner > initializationError FAILED
    io.cucumber.core.exception.CucumberException: Failed to parse ‘target/failedrerun.txt’

How can i choose the correct sequence?


Solution

  • As a workaround I have created a seperate gradle task to run the rerunner classes at the end and removed the CucumberSerenityBDDUIReRunner class from source.

    configurations {
        cucumberRuntime {
            extendsFrom implementation
        }
    }
    
    task reRun(type: JavaExec, dependsOn:testClasses) {
                systemProperties System.getProperties()
                systemProperty "cucumber.options", System.getProperty("cucumber.options")
    
                mainClass = "net.serenitybdd.cucumber.cli.Main"
                classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
                args += [
                        '--plugin', 'pretty',
                        '@target/failedrerun.txt',
                        '--glue', 'com.abc.def.ijk.features']
    }
    

    Now I run gradle --info clean test reRun aggregate -Denvironment='stagging' -Dtags='envr:stagging' -Dcucumber.options='--tags @envr=stagging' from commandLine.

    This time the

    CucumberSerenityBDDAPIAutoRunner 
    and 
    CucumberSerenityBDDUIAutoRunner
    

    Classes as a part of test task and rerun will run the failed test cases link generated in @target/failedrerun.txt file.

    Serenity report only takes the latest test case run in account( i.e the rerun one if it has run as a part of reRun task)

    P.S: we can put after reRun task in build.gradle file

    tasks.test {
        finalizedBy reRun
    }
    

    then the old gradle --info clean test aggregate -Denvironment='stagging' -Dtags='envr:stagging' -Dcucumber.options='--tags @envr=stagging' command will also work.