DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Playwright and Chrome Browser Testing in Heroku
  • Selenium Grid Tutorial: Essential Tips and How to Set It Up
  • Getting Started With Microsoft Tool Playwright for Automated Testing
  • Scriptless Testing in a Mobile World

Trending

  • Navigating and Modernizing Legacy Codebases: A Developer's Guide to AI-Assisted Code Understanding
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • The Role of AI in Identity and Access Management for Organizations
  • What’s Got Me Interested in OpenTelemetry—And Pursuing Certification
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. How to Generate Extent Reports in Selenium WebDriver

How to Generate Extent Reports in Selenium WebDriver

In this article, We will learn How to generate Extent Reports in Selenium WebDriver. For more, read the full article now.

By 
Preeti Singh user avatar
Preeti Singh
·
Nov. 09, 22 · Analysis
Likes (2)
Comment
Save
Tweet
Share
6.7K Views

Join the DZone community and get the full member experience.

Join For Free

We will learn how to generate Extent Reports in Selenium WebDriver in this tutorial.

What Exactly Are Extent Reports?

Extent Reports is an open-source reporting framework that can be used for test automation. It may be seamlessly connected with popular testing fabrics like JUnit, NUnit, TestNG, and others. These reports are HTML documents with pie maps that show the results. They also enable the creation of customized logs, pictures, and other data.

When an automated test script completes successfully, testers must generate a test prosecution report. While TestNG provides a dereliction report, it does not provide information.

Using Extent Reports in Selenium

Selenium range reports contain two important classes that are commonly used.

  • ExtentReports Class
  • ExtentTest Class

Syntax:

 
ExtentReports reports = new ExtentReports("Path of directory to store the resultant HTML file", true/false);
ExtentTest test = reports.startTest("TestName");


The ExtentReports class generates HTML reports based on the route supplied by the verifier. Depending on the boolean flag, an existing report should be rewritten, or a new report should be prepared. "True" is the default, which means that all existing data will be rewritten.

The ExtentTest class saves the test steps to a previously produced HTML report.

Both classes can be combined in the following ways:

  • startTest: Prerequisites for starting the test case.
  • endTest: Meet the following test case conditions.
  • Log: Record the status of each test step in the HTML report that is being generated.
  • Flush: Delete all prior data from a relevant report and produce a fresh one.

The test state can be represented by the following values:

  • PASS
  • FAIL
  • SKIP
  • INFO

Syntax:

Two parameters are taken into account by report techniques. The first is the status of the test, and the second is the message displayed in the created report.


Two parameters are taken into account by report techniques. The first is the status of the test, and the second is the message displayed in the created report.

How to Generate Extent Reports in Selenium?

  1. Import the JAR file degreereports-java-2.1.2.jar. After downloading the ZIP file, extract its contents to a folder.
  2. Add the JAR file to the project's build path by selecting Build Path -> Set Build Path.
  3. Use the following code to create a new JAVA class for Scope Report.
 
package com.browserstack.demo;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class ExtentDemo {
static ExtentTest test;
static ExtentReports report;
@BeforeClass
public static void startTest()
{
report = new ExtentReports(System.getProperty("user.dir")+"ExtentReportResults.html");
test = report.startTest("ExtentDemo");
}
@Test
public void extentReportsDemo()
{
System.setProperty("webdriver.chrome.driver", "D:SubmittalExchange_TFSQAAutomation3rdpartychromechromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in");
if(driver.getTitle().equals("Google"))
{
test.log(LogStatus.PASS, "Navigated to the specified URL");
}
else
{
test.log(LogStatus.FAIL, "Test Failed");
}
}
@AfterClass
public static void endTest()
{
report.endTest(test);
report.flush();
}
}

Starts the test with the smartest method. It also sets up the Scope Reports object. Any valid custom route can be supplied to the Scope Reports object as a parameter.

@Test: This class automatically does the following:

  • Open the Chrome browser with the URL.
  • When you open the page, check that the page title is as expected.
  • Record the test case status as PASS/FAIL using the logging method described above.

@AfterClass: Post the condition to run the test case: end the test (using the endTest method) and clear the report.

How to Generate Extent Reports in Selenium Using NUnit?

Using setup fixture:

 
[SetUpFixture]
public abstract class Base
{
protected ExtentReports _extent;
protected ExtentTest _test;

[OneTimeSetUp]
protected void Setup()
{
var dir = TestContext.CurrentContext.TestDirectory + "\\";
var fileName = this.GetType().ToString() + ".html";
var htmlReporter = new ExtentHtmlReporter(dir + fileName);

_extent = new ExtentReports();
_extent.AttachReporter(htmlReporter);
}

[OneTimeTearDown]
protected void TearDown()
{
_extent.Flush();
}

[TestFixture]
public class TestInitializeWithNullValues : Base
{
[Test]
public void TestNameNull()
{
Assert.Throws(() => testNameNull());
}
}

[SetUp]
public void BeforeTest()
{
_test = _extent.CreateTest(TestContext.CurrentContext.Test.Name);
}

[TearDown]
public void AfterTest()
{
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
? ""
: string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
Status logstatus;

switch (status)
{
case TestStatus.Failed:
logstatus = Status.Fail;
break;
case TestStatus.Inconclusive:
logstatus = Status.Warning;
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
break;
default:
logstatus = Status.Pass;
break;
}

_test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
_extent.Flush();
}
}

How to Capture Screenshots in Extent Report?

Taking screenshots allows testers to better determine what went wrong when the software failed during the test. Take screenshots only if the test fails, as they consume a lot of memory.

Try taking screenshots with the code below:

Taking screenshots with the code.


getScreenShotAs(): This method captures a screenshot of the current WebDriver instance and saves it in a variety of output formats.

This method captures a screenshot of the current WebDriver instance and saves it in a variety of output formats.


This method produces a file object, which is saved in the file variable. The method necessitates giving a web driver instance to the Take Screenshot function.

 The method necessitates giving a web driver instance to the Take Screenshot function.


This statement creates a folder called "BStackImages" in the "src" folder and names the files based on the current system time.

This statement creates a folder called "BStackImages" in the "src" folder and names the files based on the current system time.


All error pictures are copied to the target directory by these statements.

Use the log method because it captures the screenshot and adds it to the extent report using the Extent Test class's addScreenCapture method.

Use the log method because it captures the screenshot and adds it to the extent report using the Extent Test class's addScreenCapture method.


Advantages of Using Extent Reports:

  • They are compatible with TestNG and JUnit.
  • Screenshots of each phase of the test can be recorded and shown if necessary.
  • They enable testers to keep track of various test cases within a single test suite.
  • They represent the amount of time needed to complete the test.
  • They can be adjusted to depict each level of the test graphically.
Google Chrome HTML HTTPS System time Test automation Test case Test script Extent (file systems) Testing Selenium

Published at DZone with permission of Preeti Singh. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Playwright and Chrome Browser Testing in Heroku
  • Selenium Grid Tutorial: Essential Tips and How to Set It Up
  • Getting Started With Microsoft Tool Playwright for Automated Testing
  • Scriptless Testing in a Mobile World

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!