0% found this document useful (0 votes)
41 views5 pages

Extent Listener Class

Extent Listner Class

Uploaded by

abhishek dabral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views5 pages

Extent Listener Class

Extent Listner Class

Uploaded by

abhishek dabral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

package com.mystore.

utilities;

import java.io.File;

import java.text.SimpleDateFormat;

import java.util.Date;

import org.testng.ITestContext;

import org.testng.ITestListener;

import org.testng.ITestResult;

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.ExtentSparkReporter;

import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentListenerClass implements ITestListener{

ExtentSparkReporter htmlReporter;

ExtentReports reports;

ExtentTest test;

public void configureReport()

{
ReadConfig readConfig = new ReadConfig();

String timestamp = new SimpleDateFormat("yyyy.mm.dd.hh.mm.ss").format(new


Date());

String reportName = "MyStoreTestReport-" + timestamp + ".html";

htmlReporter = new ExtentSparkReporter(System.getProperty("user.dir") +


"//Reports//" + reportName);

reports = new ExtentReports();

reports.attachReporter(htmlReporter);

//add system information/environment info to reports

reports.setSystemInfo("Machine:", "testpc1");

reports.setSystemInfo("OS", "windows 11");

reports.setSystemInfo("browser:", readConfig.getBrowser());

reports.setSystemInfo("user name:", "Prachi");

//configuration to change look and feel of report

htmlReporter.config().setDocumentTitle("Extent Listener Report Demo");

htmlReporter.config().setReportName("This is my First Report");

htmlReporter.config().setTheme(Theme.DARK);

//OnStart method is called when any Test starts.

public void onStart(ITestContext Result)

configureReport();

System.out.println("On Start method invoked....");


}

//onFinish method is called after all Tests are executed

public void onFinish(ITestContext Result)

System.out.println("On Finished method invoked....");

reports.flush();//it is mandatory to call flush method to ensure information is written


to the started reporter.

// When Test case get failed, this method is called.

public void onTestFailure(ITestResult Result)

System.out.println("Name of test method failed:" + Result.getName() );

test = reports.createTest(Result.getName());//create entry in html report

test.log(Status.FAIL, MarkupHelper.createLabel("Name of the failed test case is: " +


Result.getName() ,ExtentColor.RED));

String screenShotPath = System.getProperty("user.dir") + "\\ScreenShots\\" +


Result.getName() + ".png";

File screenShotFile = new File(screenShotPath);

if(screenShotFile.exists())

{
test.fail("Captured Screenshot is below:" +
test.addScreenCaptureFromPath(screenShotPath));

// test.addScreenCaptureFromPath(null)

// When Test case get Skipped, this method is called.

public void onTestSkipped(ITestResult Result)

System.out.println("Name of test method skipped:" + Result.getName() );

test = reports.createTest(Result.getName());

test.log(Status.SKIP, MarkupHelper.createLabel("Name of the skip test case is: " +


Result.getName() ,ExtentColor.YELLOW));

// When Test case get Started, this method is called.

public void onTestStart(ITestResult Result)

System.out.println("Name of test method started:" + Result.getName() );

}
// When Test case get passed, this method is called.

public void onTestSuccess(ITestResult Result)

System.out.println("Name of test method sucessfully executed:" +


Result.getName() );

test = reports.createTest(Result.getName());

test.log(Status.PASS, MarkupHelper.createLabel("Name of the passed test case is: "


+ Result.getName() ,ExtentColor.GREEN));

public void onTestFailedButWithinSuccessPercentage(ITestResult Result)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy