Skip to main content

Adding Extent reporting for QA test automation framework

Define these globally:
ExtentLoggerReporter logger = new ExtentLoggerReporter("/ebs/test/build/"); //The path given here will be used to store temp files for extent,create once.
static ExtentReports extent;

Define this method to initialise Extent configs before Test:
@BeforeTest
public void initialiseExtentReport() {
logger.config().setAutoCreateRelativePathMedia(true);
extent = new ExtentReports();
ExtentHtmlReporter html = new ExtentHtmlReporter("Extent.html");
extent.attachReporter(logger);
extent.attachReporter(html);
extent.loadConfig(new File(System.getProperty("user.dir")+"/extent-config.xml")); //extent-config.xml file content given below
}

For pom.xml add:
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.0.9</version>
</dependency>

On Our code, Wherever we are passing/failing the test step, we can use below code to report to extent.html file & flush after every @Test:

extent.createTest("Test case name for our ref","Description of test case which is optional").pass("Test name for report purpose"+" Test passed(You can set any words as per your req)");
OR
extent.createTest("Test case name for our ref","Description of test case which is optional").fail("Test name for report purpose"+" Test failed(You can set any words as per your req)");

Use below snippet once anywhere to flush extent report file(on every test completion this updates report):
@AfterTest
public static void endTest(){
extent.flush();
}

Copy this "extent-config.xml" to project directory directly:

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
  <configuration>
    <!-- report theme -->
    <!-- standard, dark -->
    <theme>standard</theme>
 
    <!-- document encoding -->
    <!-- defaults to UTF-8 -->
    <encoding>UTF-8</encoding>
   
    <!-- protocol for script and stylesheets -->
    <!-- defaults to https -->
    <protocol>https</protocol>
   
    <!-- title of the document -->
    <documentTitle>ExtentReports 2.0</documentTitle>
   
    <!-- report name - displayed at top-nav -->
    <reportName></reportName>
   
    <!-- report headline - displayed at top-nav, after reportHeadline -->
    <reportHeadline>Automation Report</reportHeadline>
   
    <!-- global date format override -->
    <!-- defaults to yyyy-MM-dd -->
    <dateFormat>yyyy-MM-dd</dateFormat>
   
    <!-- global time format override -->
    <!-- defaults to HH:mm:ss -->
    <timeFormat>HH:mm:ss</timeFormat>
   
    <!-- custom javascript -->
    <scripts>
      <![CDATA[
        $(document).ready(function() {
         
        });
      ]]>
    </scripts>
   
    <!-- custom styles -->
    <styles>
      <![CDATA[
       
      ]]>
    </styles>
  </configuration>
</extentreports>

Note:
Also on Jenkins job, we can pick this report to send through email after execution to the team.

Comments

Popular posts from this blog

javamail jdk11(11.0.10 and above) needs tls upgrade from 1.1 to 1.2

ISSUE 1: Unable to send/read mails using javamail/javaxmail after you upgraded your jdk to 11.0.10 or above?  The reason is they came up with higher security level for SSL with TLS 1.2 which is dependency for latest jdk, find the solution below: Possible Exception if you used older version TLS-1.1:  javax.net.ssl.sslhandshakeexception Solution: Add below property to your existing Properties. properties.put("mail.imaps.ssl.protocols","TLSv1.2");(IMAP used to read mail) properties.put("mail.smtp.ssl.protocols","TLSv1.2");(SMTP used to send mail) ISSUE 2: Unable to type case Multipart to String? From jdk11(latest version) onwards multipart and string cant be type casted, so we need to use Object to store message content. Solution: for (int i = 0; i < messages.length; i++) { Message message = messages[i]; Object content = message.getContent(); if (content instanceof String) { String body = (String)content; System.out.println...

Extent report for Rest API test

Below code helps in failing or passing your Rest API test case & updating result to Extent report. Maven dependency(pom.xml): <dependency>     <groupId>com.aventstack</groupId>     <artifactId>extentreports</artifactId>     <version>4.0.9</version> </dependency> code: import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.reporter.ExtentHtmlReporter; import com.aventstack.extentreports.reporter.ExtentLoggerReporter; public class A{ ExtentLoggerReporter logger = new ExtentLoggerReporter("dir path to store extent result"); static ExtentReports extent; @Test public void testname(){ //Your code to capture json from get/post/put/delete API to "JSONObject jsonobjexpected" field. //your code to read actual json content from file/anywhere to "JSONObject jsonobjactual" field. try {         JSONAssert.assertEquals(jsonobjexpected.toString(...

RestAssured rest API test framework for GET & POST API json verification with Extent report

package com.resttest; import static io.restassured.RestAssured.given; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.DriverManager; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import org.apache.commons.collections.iterators.EntrySetMapIterator; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterTest; import org.testn...