Create an extent-config.xml file like below:
<?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>G15AutomationProject</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName></reportName>
<!-- report headline - displayed at top-nav, after reportHeadline -->
<reportHeadline>G15APIAutomation</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>
2. Create method to read extent-config.xml
public class ExtentReport {
public static ExtentReports extentreport = null;
public static ExtentTest extentlog;
public static void initialize(String path) {
if (extentreport == null) {
extentreport = new ExtentReports(path, true);
extentreport.addSystemInfo("Host Name", System.getProperty("user.name"));
extentreport.addSystemInfo("Environment", Helper.propertyReader(Helper.commonFilePath, "executionEnv"));
extentreport.loadConfig(new File(System.getProperty("user.dir") + "/extent-config.xml"));
}
}
}
3. Integrate the testing result with Extent report in the basest class
https://automationreinvented.blogspot.com/2020/05/how-to-log-test-case-execution-status.html
@AfterMethod(alwaysRun = true)
public void getResult(ITestResult result) {
if (result.getStatus() == ITestResult.SUCCESS) {
ExtentReport.extentlog.log(LogStatus.PASS, "Test Case : "+ result.getName()+" is passed ");
} else if (result.getStatus() == ITestResult.FAILURE) {
ExtentReport.extentlog.log(LogStatus.FAIL, "Test case : "+ result.getName()+" is failed ");
ExtentReport.extentlog.log(LogStatus.FAIL, "Test case is failed due to: " + result.getThrowable());
} else if (result.getStatus() == ITestResult.SKIP) {
ExtentReport.extentlog.log(LogStatus.SKIP, "Test case is Skiped " + result.getName());
}
ExtentReport.extentreport.endTest(ExtentReport.extentlog);
}
@AfterSuite(alwaysRun = true)
public void endReport() {
//ExtentReport.extentreport.flush();
ExtentReport.extentreport.close();
//Logging.setinstanceNull();
}
4. Call extent report in the test script
public static void verifySC404() {
ExtentReport.extentlog = ExtentReport.extentreport.startTest("verifySC404",
"Validate 404 status code - negative testcase”);// first parameter will be the name and second parameter will have the description about the test case
String baseUrl = Helper.propertyReader(Helper.commonFilePath, "baseUrl");
System.out.println(baseUrl);
Response resp = given().
when().get("https://reqres.in/apiusers?page=2");
assertEquals(resp.getStatusCode(),404);
}
No comments:
Post a Comment