How To Generate Extent Reports Version 3 in Selenium WebDriver

Generate Extent Reports Version 3 in Selenium WebDriver

Earlier we posted “ How To Generate Extent Reports ” and in that post, we used version 2 of extent reports. This post will guide you on “How To Generate Extent Reports Version 3 in Selenium“. Extent reports are the advanced Selenium Reporting Tool.

Extent Reports Version 4 – Latest Version [2019]

By default, TestNG generates a report. A small note on how to generate reports using TestNG. Once you execute your tests, TestNG generates a test-output folder at the root of your project. It contains a detailed report and a summary report. But to get an advanced selenium report, you need to go for Extent Reports. If you still, want to see how TestNG Reports look like – click here to see the TestNG Report in Selenium

Now lets move on to advanced selenium reports i.e., Extent Reports.

Pre-requisites to Advanced Selenium Reporting – Generate Extent Reports:

  1. Java should be installed (Link to Install and setup Java )
  2. TestNG should be installed (Link to Install TestNG )
  3. Extent Report Version 3 Jars – Download
  4. extent-config.xml – It allows to configure HTML Report

Steps To Generate Extent Reports:

  1. Firstly, create a TestNG project in eclipse
  2. Now download extent library files from the following link:  https://extentreports.com/
  3. Add the downloaded library files to your project
  4. Create a java class say ‘ExtentReportsClass’ and add the following code to it

Code explanation is clearly given in the earlier post “ How To Generate Extent Reports Version 2 ”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package extentReports;
 
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
 
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;
 
 
 
public class ExtentReportsClassVersion3{
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest logger;
@BeforeTest
public void startReport(){
htmlReporter = new ExtentHtmlReporter(System.getProperty(“user.dir”) +“/test-output/STMExtentReport.html”);
extent = new ExtentReports ();
extent.attachReporter(htmlReporter);
extent.setSystemInfo(“Host Name”, “SoftwareTestingMaterial”);
extent.setSystemInfo(“Environment”, “Automation Testing”);
extent.setSystemInfo(“User Name”, “Rajkumar SM”);
htmlReporter.config().setDocumentTitle(“Title of the Report Comes here”);
htmlReporter.config().setReportName(“Name of the Report Comes here”);
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
}
@Test
public void passTest(){
logger = extent.createTest(“passTest”);
Assert.assertTrue(true);
logger.log(Status.PASS, MarkupHelper.createLabel(“Test Case Passed is passTest”, ExtentColor.GREEN));
}
@Test
public void failTest(){
logger = extent.createTest(“failTest”);
Assert.assertTrue(false);
logger.log(Status.PASS, “Test Case (failTest) Status is passed”);
logger.log(Status.PASS, MarkupHelper.createLabel(“Test Case (failTest) Status is passed”, ExtentColor.GREEN));
}
@Test
public void skipTest(){
logger = extent.createTest(“skipTest”);
throw new SkipException(“Skipping – This is not ready for testing “);
}
@AfterMethod
public void getResult(ITestResult result){
if(result.getStatus() == ITestResult.FAILURE){
//logger.log(Status.FAIL, “Test Case Failed is “+result.getName());
//MarkupHelper is used to display the output in different colors
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + ” – Test Case Failed”, ExtentColor.RED));
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + ” – Test Case Failed”, ExtentColor.RED));
}else if(result.getStatus() == ITestResult.SKIP){
//logger.log(Status.SKIP, “Test Case Skipped is “+result.getName());
logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + ” – Test Case Skipped”, ExtentColor.ORANGE));
}
}
@AfterTest
public void endReport(){
extent.flush();
    }
}

extent-config.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version=“1.0” encoding=“UTF-8”?>
<extentreports>
    <configuration>
        <! report theme >
        <! standard, dark >
        <theme>standard</theme>
    
        <! document encoding >
        <! defaults to UTF8 >
        <encoding>UTF8</encoding>
        
        <! protocol for script and stylesheets >
        <! defaults to https >
        <protocol>https</protocol>
        
        <! title of the document >
        <documentTitle>Extent</documentTitle>
        
        <! report name displayed at topnav >
        <reportName>Automation Report</reportName>
        
        <! location of charts in the test view >
        <! top, bottom >
        <testViewChartLocation>bottom</testViewChartLocation>
        <! custom javascript >
        <scripts>
            <![CDATA[
                $(document).ready(function() {
                    
                });
            ]]>
        </scripts>
        
        <! custom styles >
        <styles>
            <![CDATA[
                
            ]]>
        </styles>
    </configuration>
</extentreports>

Refresh the project after execution of the above ExtentReportsClassVersion3.java file. You could find an HTML file named “STMExtentReport.html” in your test-output folder. Copy the location of the STMExtentReport.html file and open it by using any browser. You could see beautiful high rich HTML reports as shown below.

Test Summary Report:

Graphical Report with PIE Charts:

Check this post to learn “ How To Insert Captured Screenshots in Extent Reports

If you have any queries, please comment below. Like this post, don’t forget to share it.

© 2021 bewegingstechnologie.net