Combine Multiple json results in one, updated Cucumber-JVM Report

走远了吗. 提交于 2021-02-07 08:21:34

问题


I have two runners in my automation project as follows:

  1. Main runner - Executes all the @ui-test tagged test cases and if a scenario is failed target/rerun.txt will be populated with the scenario location (e.g. features/Dummy.feature:22):

    @RunWith(Cucumber.class)
    @CucumberOptions(
        features = "classpath:features",
        plugin = {"pretty", "html:target/cucumber-html-report", "json:target/cucumber.json", "rerun:target/rerun.txt"},
        tags = {"@ui-test", "~@ignore"}
    )
    
    public class RunCukesTest {
    }
    
  2. Secondary runner - Re-executes the scenarios from target/rerun.txt:

    @RunWith(Cucumber.class)
    @CucumberOptions(
        features = "@target/rerun.txt",
        plugin = {"pretty", "html:target/cucumber-html-report-rerun", "json:target/cucumber_rerun.json"}
    )
    
    public class ReRunFailedCukesTest {
    }
    

When the execution is performed two result json files are created:

  • cucumber.json
  • cucumber_rerun.json

Jenkins will collect the results via Cucumber-JVM Reports plugin and will create a combined report.

The problem is, even if all the target/rerun.txt tests are passed in the second run, the report status will remain failed because of the cucumber.json.

Is there a way (to set up Cucumber-JVM Reports plugin or modify the upper presented runners) to overwrite cucumber.json with the results from cucumber_rerun.json and to publish only the modified cucumber.json?

Another sub-keywords: maven, java, cucumber-java8, cucumber-junit, junit


回答1:


I had problem similar to yours, though, I've used single runner, handled re-runs from testNG(re-runs was one of the reasons I've switched from JUnit to TestNG) directly and as a results I had increased amount of tests in my json report. My solution was to clean json files afterwards, despite the fact that Jenkins knows about failed tests it won't mark build as failed or as unstable. In your particular case you may try to somehow match tests from rerun.json and exclude them from regular json report. For parsing jsons I may recommend using Jackson FasterXML




回答2:


I use Jenkins cucumber reporting latest release with below config in Jenkins.

Image Of Config In Jenkins

1st Runner

@RunWith(Cucumber.class)
@CucumberOptions(
		features="FolderFeature",
		glue={"Gluefolder"},
		plugin={"html:target/cucumberpf-html-report",
				"json:target/cucumberpf.json"}
		)

public class RunPF {

}

2nd Runner

@RunWith(Cucumber.class)
@CucumberOptions(
		features="Blah/Test.feature",
		glue={"mygluefolder"},
		plugin={"html:target/cucumber-html-report",
				"json:target/cucumber.json"}
		)

public class RunRA {
	
}

I had failed in both .json files and when it passed both were merged and updated correctly in one cucumber report.

Here is the error:

[CucumberReport] Preparing Cucumber Reports
[CucumberReport] JSON report directory is "C:\Users\ajacobs\workspace\com.mytest.framework\target\"
[CucumberReport] Copied 2 json files from workspace "C:\Users\admin\workspace\yourtest\target" to 
  reports directory "C:\Users\admin\.jenkins\jobs\Regression\builds\21\cucumber-html-reports\.cache"
[CucumberReport] Processing 2 json files:
[CucumberReport] C:\Users\admin\yourtest\builds\21\cucumber-html-reports\.cache\cucumber.json
[CucumberReport] C:\Users\admin\yourtest\builds\21\cucumber-html-reports\.cache\cucumberpf.json
Finished: SUCCESS


来源:https://stackoverflow.com/questions/39742420/combine-multiple-json-results-in-one-updated-cucumber-jvm-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!