I have made a script to generate an extent report, but HTML is not generated.
Please check below code:
Report.java:
package report;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
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.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;
public class Report {
ExtentHtmlReporter htmlReporter;
static ExtentReports extent;
static ExtentTest logger;
@BeforeTest
public void startReport(){
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/STMExtentReport.html");
extent = new ExtentReports ();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("Host Name", "SoftwareTestingMaterial");
extent.setSystemInfo("Environment", "Automation Testing");
extent.setSystemInfo("User Name", "Rajkumar SM");
htmlReporter.config().setDocumentTitle("Title of the Report Comes here");
htmlReporter.config().setReportName("Name of the Report Comes here");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
}
@Test
public void passTest(){
logger = extent.createTest("passTest");
Assert.assertTrue(true);
logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is passTest", ExtentColor.GREEN));
}
@Test
public void failTest(){
logger = extent.createTest("failTest");
Assert.assertTrue(false);
logger.log(Status.PASS, "Test Case (failTest) Status is passed");
logger.log(Status.PASS, MarkupHelper.createLabel("Test Case (failTest) Status is passed", ExtentColor.GREEN));
}
@Test
public void skipTest(){
logger = extent.createTest("skipTest");
throw new SkipException("Skipping - This is not ready for testing ");
}
@AfterMethod
public void getResult(ITestResult result){
if(result.getStatus() == ITestResult.FAILURE){
//logger.log(Status.FAIL, "Test Case Failed is "+result.getName());
//MarkupHelper is used to display the output in different colors
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " - Test Case Failed", ExtentColor.RED));
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED));
}else if(result.getStatus() == ITestResult.SKIP){
//logger.log(Status.SKIP, "Test Case Skipped is "+result.getName());
logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " - Test Case Skipped", ExtentColor.ORANGE));
}
}
@AfterTest
public void endReport(){
extent.flush();
}
}
The .xml file :
<?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>Extent</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName>Automation Report</reportName>
<!-- location of charts in the test view -->
<!-- top, bottom -->
<testViewChartLocation>bottom</testViewChartLocation>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
startReport()
method is@BeforeTest
so it will execute before each test class and each time it will override the old HTML file, and your lastTest
is throwing skipexception.