Introduction intro Cucumber Reports

Introduction intro Cucumber Reports

After a test Execution we need to generate a useful test report, cucumber provides some good functional for us.

It is also require to understand the out put of the execution. Whether it is Manual execution or an Automated, the output of the same has to be in format, which immediately depicts the overall results of the execution. Hence, our framework also should have the same capability to create output or generate test execution reports.

It is essential to know, how better we can generate our Cucumber test reports. As we know that Cucumber is a BDD framework, it does not have a fancy reporting mechanism. In order to achieve this, Cucumber itself has provided nice feature to generate reports. These are very basic reports, but using the output of these reports anybody can build more detailed HTML reports.

 

Now when we understand the importance of Cucumber Reports, lets learn to generate it as well.

When we execute Cucumber Scenarios, it automatically generates an output in the eclipse console. There is a default behavior associated with that output and we can also configure that output as per our needs also. So how do we modify the default behavior, let’s see this now.

 

Pretty Report

The first plugin, we will talk about is Pretty.  This provides more verbose output. To implement this, just specify plugin = “pretty” in CucumberOptions. This is what the code looks like:

@CucumberOptions( plugin = { “pretty” } )

Complete TestRunner would look like this:

TestRunner.java

</pre>
@RunWith(Cucumber.class)
@CucumberOptions( features = "src/test/resources/functionalTests",
glue= {"stepDefinitions"}, 
plugin = { "pretty" }, 
monochrome = true ) 
public class TestRunner { }

Monochrome Mode Reporting

If the monochrome option is set to false, then the console output is not as readable as it should be. The output when the monochrome option is set to false is shown in the above example. It is just because, if the monochrome is not defined in Cucumber Options, it takes it as false by default. How to specify it:

@CucumberOptions( monochrome = true );

Usage Report

If we are more concerned about the time taken by each Step Definition, then we should use the usage plugin. This is how we specify the same in @CucumberOptions:

@CucumberOptions( plugin = { “usage” })

Full Code

</pre>
@CucumberOptions( features = "src/test/resources/functionalTests", 
glue= {"stepDefinitions"}, 
plugin = { "usage" }, 
monochrome = true )

Cucumber Report Output

You must be wondering that all we have seen above is actually good for a test or for couple of tests. But if we run a full test suite, this report is not much useful in that case. On top of that it is difficult to keep these console output safe for future use.

Cucumber gives us capability to generate reports as well in the form of HTML, XML, JSON & TXT. Cucumber frameworks generate very good and detailed reports, which can be shared with all stake holders. There are multiple options available for reports which can be used depending on the requirement.

 

Cucumber HTML Reports

For HTML reports, add html:target/cucumber-reports to the @CucumberOptions plugin option.

@CucumberOptions( features = "src/test/resources/functionalTests", 
glue= {"stepDefinitions"},
 plugin = { "pretty", "html:target/cucumber-reports" }, 
monochrome = true )

Cucumber JSON Report

For JSON reports, add json:target/cucumber-reports/Cucumber.json to the @CucumberOptions plugin option.

@CucumberOptions( features = "src/test/resources/functionalTests",
glue= {"stepDefinitions"}, 
plugin = { "pretty", "json:target/cucumber-reports/Cucumber.json" }, 
monochrome = true )

 

Cucumber JUNIT XML Report

For JUNIT reports, add junit:targe/cucumber-reports/Cucumber.xml to the @CucumberOptions plugin option.

@CucumberOptions( features = "src/test/resources/functionalTests",
glue= {"stepDefinitions"}, 
plugin = { "pretty", "junit:target/cucumber-reports/Cucumber.xml" }, 
monochrome = true )

 

All Reports Together

We can even generate all reports together as well.

</pre>
@CucumberOptions( features = "src/test/resources/functionalTests",
glue= {"stepDefinitions"}, 
plugin = { "pretty", "json:target/cucumber-reports/Cucumber.json", 
"junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
 monochrome = true )