Created
October 12, 2023 12:34
-
-
Save ckzgraphics/b02ec2a58545de2d684ca359014fea01 to your computer and use it in GitHub Desktop.
Template - API Test - Extent Report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.aventstack.extentreports.ExtentReports; | |
import com.aventstack.extentreports.ExtentTest; | |
import com.aventstack.extentreports.Status; | |
import com.aventstack.extentreports.reporter.ExtentSparkReporter; | |
import com.aventstack.extentreports.reporter.configuration.Theme; | |
import org.testng.ITestContext; | |
import org.testng.ITestListener; | |
import org.testng.ITestResult; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
public class TemplateExtentReports implements ITestListener { | |
public ExtentSparkReporter sparkReporter; | |
public ExtentReports extentReports; | |
public ExtentTest extentTest; | |
String reportName; | |
@Override | |
public void onTestStart(ITestResult result) {} | |
@Override | |
public void onTestSuccess(ITestResult result) { | |
extentTest=extentReports.createTest(result.getName()); | |
extentTest.assignCategory(result.getMethod().getGroups()); | |
extentTest.createNode(result.getName()); | |
extentTest.log(Status.PASS, "Test Passed"); | |
} | |
@Override | |
public void onTestFailure(ITestResult result) { | |
extentTest=extentReports.createTest(result.getName()); | |
extentTest.createNode(result.getName()); | |
extentTest.assignCategory(result.getMethod().getGroups()); | |
extentTest.log(Status.FAIL, "Test Failed"); | |
extentTest.log(Status.FAIL, result.getThrowable().getMessage()); | |
} | |
@Override | |
public void onTestSkipped(ITestResult result) { | |
extentTest=extentReports.createTest(result.getName()); | |
extentTest.createNode(result.getName()); | |
extentTest.assignCategory(result.getMethod().getGroups()); | |
extentTest.log(Status.SKIP, "Test Skipped"); | |
extentTest.log(Status.SKIP, result.getThrowable().getMessage()); | |
} | |
@Override | |
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {} | |
@Override | |
public void onStart(ITestContext context) { | |
String timestamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); | |
reportName = "Test-Report-" + timestamp + ".html"; | |
sparkReporter=new ExtentSparkReporter(System.getProperty("user.dir") + "/reports/" + reportName);//specify location of the report | |
sparkReporter.config().setDocumentTitle("RestAssuredAutomationProject"); // Title of report | |
sparkReporter.config().setReportName("Sample API"); // name of the report | |
sparkReporter.config().setTheme(Theme.DARK); | |
extentReports=new ExtentReports(); | |
extentReports.attachReporter(sparkReporter); | |
extentReports.setSystemInfo("Application", "Pest Store Users API"); | |
extentReports.setSystemInfo("Operating System", System.getProperty("os.name")); | |
extentReports.setSystemInfo("User Name", System.getProperty("user.name")); | |
extentReports.setSystemInfo("Environemnt","QE"); | |
extentReports.setSystemInfo("user","Chinmay"); | |
} | |
@Override | |
public void onFinish(ITestContext context) { | |
extentReports.flush(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment