请在下方找到 的完整代码testNGlistner。好心检查。包pom;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
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.MediaEntityBuilder;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;
import generic.BaseTest;
public class testNgListners extends BaseTest implements ITestListener {
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest logger;
@Override
public void onTestStart(ITestResult result) {
}
@Override
public void onTestSuccess(ITestResult result) {
logger = extent.createTest(result.getName());
logger.log(Status.PASS, MarkupHelper.createLabel(result.getName(), ExtentColor.GREEN));
}
@Override
public void onTestFailure(ITestResult result) {
System.out.println("hii");
logger = extent.createTest(result.getName());
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName(), ExtentColor.RED));
if (result.getStatus() == ITestResult.FAILURE) {
TakesScreenshot take = (TakesScreenshot) driver;
File srcFile = take.getScreenshotAs(OutputType.FILE);
}
}
}
万千封印
相关分类