This repository holds the beginner code for anyone who wants to understand and start using ExtentReports for reporting in their automation framework.
Extent Report is an open-source library used for generating test reports in automation testing. It has been more widely used for report generation than the inbuilt reports in various test frameworks because of its enhanced features and customisation. It is a simple yet powerful reporting library that can be integrated with the automation framework for generating the automation test report.
Three classes are used for generating and customising the Extent Reports in Selenium. They are:
- ExtentHtmlReporter if using the version below 4.1.x else ExtentSparkReporter on latest version 5. In this blog, we are using ExtentSparkReporter.
- ExtentReports
- ExtentTest
ExtentSparkReporter extentSparkReporter = new ExtentSparkReporter(System.getProperty("user.dir") + "/test-output/extentReport.html");
ExtentReports extentReports = new ExtentReports();
extentReports.attachReporter(extentSparkReporter);
extentSparkReporter.config().setDocumentTitle("Simple Automation Report");
extentSparkReporter.config().setReportName("Test Report");
extentSparkReporter.config().setTheme(Theme.STANDARD);
extentSparkReporter.config().setTimeStampFormat("EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'");
ExtentTest extentTest = extentReports.createTest("Test Case", "Test description");
public void captureScreenshot()
{
try {
String screenshotPath = System.getProperty("user.dir") + "/test-output/screenshots";
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String screenshotName = "screenshot_" + new Random().nextInt(999) + ".png";
screenshotPath = screenshotPath + File.separator + screenshotName;
Files.copy(screenshot, new File(screenshotPath));
extentTest.addScreenCaptureFromPath(screenshotPath);
}
catch (IOException e) {
e.printStackTrace();
}
}
To generate extent reports in parallel in we make use of the parallel
attribute in the testng.xml and also implement ThreadLocal for ExtentTest class object to implement thready-safety to prevent any overwritting or issues while generating Extent Reports.
<test name="Parallel Tests by Methods" parallel="methods" thread-count="3">
<test name = "Parallel Tests by Classes" parallel = "classes" thread-count="3">
It is created using Selenium with Java, TestNG, and Maven for Web-based automation
This is the list of tools, being used in this framework:
- Apache Maven
- Java
- TestNG Framework
- Selenium WebDrvier
- Import this project in Eclipse/IntelliJ as an “Existing Maven Project”
- Update your LambdaTest account username and accessKey in BaseTest.java. You can find these in the Profile section.
- Execute any one of the test cases by right-clicking and selecting the Run as the TestNG option.
- You can see the logs coming on Console as your execution progresses.
- Log into your LambdaTest dashboard to see the detailed execution results for the executed test case.