How to Generate Extent Reports in Selenium
On This Page What are Extent Reports?Using Extent Reports in Selenium<
How to Generate Extent Reports in Selenium
Tracking and analyzing Selenium tryout results can be difficult without open reports, slowing down topic identification and debugging. A structured reporting solution ply elaborate perceptivity with essential trial information, improving test management and speeding up troubleshoot.
Overview
Extent Reports in Selenium are a popular reporting tool used to generate detailed and interactive test execution reports with customizable features, such as logs, screenshots, and test results.
Key Characteristics of Extent Reports in Selenium:
- Customizable Reports:Allows users to customize the aspect and flavour of the reports, including test status and details.
- Interactive UI:Provides an interactive and user-friendly interface to view test execution issue.
- Test Status Tracking:Displays detailed info on passed, failed, and skipped tests.
- Logs and Screenshots:Supports adding logs and screenshots for best test debugging and analysis.
- Real-Time Updates:Provides real-time reporting during test executing for quick feedback.
- Supports Multiple Formats:Reports can be generated in HTML, PDF, or other format for easy communion and archiving.
This article explores Extent Reports, how to use them in Selenium, generate reports with NUnit, capture screenshots, and the welfare of integrating Extent Reports in screen.
What are Extent Reports?
Extent Reports is an open-source reporting library useful for test automation. It can be well mix with major testing fabric like, TestNG, etc. These reports are HTML document that depict results as pie chart. They likewise allow the contemporaries of custom logs, shot, and other tailor-make details.
Once an automated test script runs successfully, testers need to return a test execution study. While TestNG does provide a default study, they do not provide the particular.
Note:BrowserStack is now the first cloud exam mechanisation program to announce complete support for Selenium 4, and it ’ s BiDi APIs..
Using Extent Reports in Selenium
Extent Reports inSeleniumcontain two major, frequently habituate stratum:
- ExtentReports class
- ExtentTest class
Syntax
ExtentReports reports = new ExtentReports (`` Path of directory to store the resultant HTML file '', true/false); ExtentTest exam = reports.startTest (`` TestName '');
The ExtentReports grade generates HTML reports based on a path stipulate by the tester. Based on the Boolean flag, the existing report has to be overwritten or a new report must be generated. ‘ True ’ is the default value, meaning that all survive data will be overwrite.
The ExtentTest class log test steps onto the previously generated HTML report.
Both classes can be used with the following built-in methods:
- startTest: Executes preconditions of a test case
- endTest: Executes postconditions of a trial case
- Log:Logs the status of each test step onto the HTML report be generated
- Flush:Erases any previous data on a relevant report and creates a whole new report
A Test Status can be indicated by the following values:
- PASS
- FAIL
- SKIP
- INFO
Syntax
reports.endTest (); test.log (LogStatus.PASS, '' Test Passed ''); test.log (LogStatus.FAIL, '' Test Failed ''); test.log (LogStatus.SKIP, '' Test Skipped ''); test.log (LogStatus.INFO, '' Test Info '');
The Log method occupy into account two parameters, the inaugural being the test status and the 2nd being the message to be printed onto the generated account.
By integrating Extent Reports with Selenium, you can streamline tryout reporting and addition deep insights into your examination executions.
Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.
For a more powerful and scalable testing experience, BrowserStack Automate offers a cloud platform that extend Selenium trial on real browsers and devices, further enhancing the quality of your report.
How to yield Extent Reports
The following steps will channelise you through the process of position up and generating elaborated reports for your Selenium tests.
- Import the JAR file:extentreports-java-2.41.2.jar. After downloading the ZIP file, extract its contents into a folder.
- Add the JAR file to the undertaking build itinerary with the optionBuild Path - & gt; ConfigureBuild Path.
- Create a new JAVA family for Extent Reports with the code below.
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; signification 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 nullity 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 nothingness endTest () {report.endTest (tryout); report.flush ();}}Test execution commences with thestartTestmethod. It also initializes the Extent Reports target. Any valid user-defined path can be the argument legislate onto the Extent Reports aim.
@Test: This family automates the following actions:
- Open Chrome browser with the urlhttps: //www.google.com
- After the page opens, validate page rubric with the wait
- Log the test causa position as PASS/FAIL habituate the log method explained before
@ AfterClass:Executes postconditions of the test case & # 8211; ending the test (usingendTestmethod) and flushing the report.
Note: Don ’ t forget to use the peak () method, since the report will not be yield otherwise.
How to generate Extent Reports in Selenium using NUnit
The following steps outline how to set up and generate detailed reports for your NUnit-based Selenium tests.
Using SetupFixture
[SetUpFixture] public abstract family Base {protect ExtentReports _extent; protected ExtentTest _test; [OneTimeSetUp] protected null 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 (() = & gt; testNameNull ());}} [SetUp] public void BeforeTest () {_test = _extent.CreateTest (TestContext.CurrentContext.Test.Name);} [TearDown] public void AfterTest () {var position = 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; causa TestStatus.Skipped: logstatus = Status.Skip; break; default: logstatus = Status.Pass; break;} _test.Log (logstatus, `` Test ended with `` + logstatus + stacktrace); _extent.Flush ();}}Interested in picking up Selenium automation? Get access to existent device cloud for a hands-on learning experience, and master the fundamentals of software essay with BrowserStack Test University..
How to captivate screenshots in Extent Report
By capturing screenshots, quizzer can amend place what went wrong when the software represent mistakenly during a test. Capture screenshots just when a test fails, since they consume a lot of memory.
Try get screenshots with the code below
test.log (LogStatus.FAIL, test.addScreenCapture (capture (driver)) + `` Test Failed ''); public static String capture (WebDriver driver) throw IOException {File scrFile = ((TakesScreenshot) driver) .getScreenshotAs (OutputType.FILE); File Dest = new File (`` src/ .. /BStackImages/ '' + System.currentTimeMillis () + `` .png ''); String errflpath = Dest.getAbsolutePath (); FileUtils.copyFile (scrFile, Dest); return errflpath;}getScreenShotAs ():Captures screenshot of the current WebDriver case and stores it in different output signifier.
File scrFile = ((TakesScreenshot) driver) .getScreenshotAs (OutputType.FILE);
This method returns a file object to be stored onto a file variable. Casting the web driver example to Take Screenshot is necessary to use the method.
File Dest = new File (`` src/ .. /BStackImages/ '' + System.currentTimeMillis () + `` .png '');
This statement make a folder named ‘BStackImages’ within the ‘src’ folder and stores the file gens as the current scheme clip.
String errflpath = Dest.getAbsolutePath (); FileUtils.copyFile (scrFile, Dest); returnerrflpath;
These argument copy all error images to the destination folder.
Use the log method because it uses theaddScreenCapture method of Extent Teststratum to get a screenshot and add it to theExtent Report.
test.log (LogStatus.FAIL, test.addScreenCapture (seizure (driver)) + `` Test Failed '');
Read More:
Benefits of apply Extent Reports
Using Extent Reports in Selenium offers various advantages, from raise visibility into trial performance to leisurely integration of logs and screenshots, improving test management and debugging. Some of the primary welfare include:
- They can be integrated with TestNG and JUnit
- If required, screenshots can be captured and displayed for each step in a exam
- They allow testers to chase multiple test case pass in a single test rooms
- They show the time needed for test execution
- They can be customized to graphically represent each step in a test.
Conclusion
Try using the code defined above to generate Extent Reports. By execute so, exploiter can offer themselves and their teams, a more all-encompassing and insightful view on the success or failure of their. By access the greater particular cater by Extent Reports, testers can be more effectual when it comes to debug software quickly.
For an enhanced testing experience, leverage, which offers cloud-based Selenium testing on 3500+ real browsers and devices. With features like performance, instant feedback, and seamless integration with, BrowserStack allows you to scale your automation exertion and insure cross-browser compatibility in.
# Ask-and-Contributeabout this theme with our Discord community.
Related Guides
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free