Prerequisites: Cucumber Again. From Requirements to Java Test
To create any simple Cucumber+Java test, we will need to create a glue file, that is pretty simple to do, because, if you don’t need all vhistles and blows on your first step – this will be enough:
package com.cucumber.StepDefinitions; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features="src/test/resources/feature", glue = "com.cucumber.StepDefinitions" ) public class CukesRunner { }
My favorite report engine is ExtentReports, so, let’s add a proper class:
package com.framework.common; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus; import org.testng.annotations.AfterSuite; public class ExtentReport { public static ExtentReports extentReports; protected static ExtentTest extentTest; public static ExtentReports getExtentReport() { if (extentReports == null){ extentReports = new ExtentReports(System.getProperty("user.dir") +"/ExtentReport/index.html", true); } return extentReports; } public static ExtentTest getExtentTest(String testName) { if (extentReports == null) { getExtentReport(); }; if (extentTest == null){ extentTest = extentReports.startTest(testName); extentTest.log(LogStatus.INFO, testName + " configureation started"); } return extentTest; } @AfterSuite public void endSuite(){ ExtentReport.getExtentReport().close(); } }
and implementation is extremely simple:
ExtentReport.getExtentTest(getClass().getSimpleName()).log(LogStatus.INFO, "Run test for " + className);
This is how it looks like:
After that I tried to research if there are any ready to go plugins or examples about how to make reports in Gherkin-like format. I easily found one, but that was working with no problems only with Eclipse. Here is an example – (https://automationissues.wordpress.com/2017/09/29/cucumber-extent-reporting/):