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/):
There is a key problem – there will be no particular action description like I clicked here or there, but you will find an error description, if exists.
So, with Intellij Idea, all we need to do is to implement current solution :
http://extentreports.com/docs/versions/3/java/
It’s enough set dependency, but in case of Idea – you will need BddWithStepStatusHierarchyTests.java and Base.java file in your project (you don’t need Base.java copy with Eclipse for some reason). In fact, you will operate with the code like this during your Gherkin code execution:
com.aventstack.extentreports.ExtentTest feature = ExtentReport.getExtentTest(); com.aventstack.extentreports.ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child1"); com.aventstack.extentreports.ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given2").info("info"); com.aventstack.extentreports.ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And3").info("info"); com.aventstack.extentreports.ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When4").info("info"); com.aventstack.extentreports.ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then5").pass("pass");
But it will be at least one problem – you will have a duplicates data like here to set proper name. I raised this question here: https://stackoverflow.com/questions/47966846/using-gherkin-with-java-copy-given-tag-value-as-sting
Honestly, I could not highlight best reporting way for today with ExtentReports, hopefully, they will resolve existing problems. Please note that there are many not so fancy reporting engines for your Java + Cucumber tests (example: https://damienfremont.com/2015/07/30/how-to-cucumber-test-reporting-plugin-with-maven-and-java/).
Hi Admin,
Greetings!
This is to inform you that the Image which you have used on your page, is ours [https://akiselev87.files.wordpress.com/2017/12/capture3.png?w=696&h=293].
So kindly take it down, as it is violation of content plagiarism.
Regards,
Sandeep Tiwari
(AutomationIssues.wordpress.com)
Removed. Sorry about that
Thanks Alexey 🙂
Just make sure you bring into our notice, before/after sharing any of our content.
Regards,
Sandeep Tiwari
(AutomationIssues.wordpress.com)