У меня есть следующий testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suite" verbose="8">
<parameter name="nodeURL" value=""></parameter>
<listeners>
<listener class-name="com.org.CustomExtentReporter"></listener>
</listeners>
<test name="Default test1">
<classes>
<class
name="com.org.SuiteConfiguration">
</class>
<class name="com.org.web.HomePage"> </class>
<class name="com.org.web.Dashboard"> </class>
</classes>
</test>
</suite>
В приведенном выше xml у меня есть два класса, они создадут отчет с 4 тестовыми узлами и его журнал в отчетах по экстентам.
Я хочу, чтобы отчет создавался следующим образом:
Тестовый класс1
- Контрольный пример 1
- Контрольный пример 2
Тестовый класс2
- Контрольный пример 1
- Контрольный пример 2
Теперь, когда пользователь нажимает на контрольный пример 1, журнал / результат отображаются только в соответствии с классом теста.
Можем ли мы сделать это с помощью Extent Reporting? Я использую ITestListener для тестирования отчетов.
public class CustomExtentReporter implements ITestListener {
ExtentReports extent = ExtentManager.getInstance();
public static ExtentTest test;
public void onTestStart(ITestResult result) {
//System.out.println("onTestStart called ...");
test = extent.createTest(result.getMethod().getMethodName());
}
public void onTestSuccess(ITestResult result) {
//test = extent.createTest("passTest");
//System.out.println("onTestSuccess called ...");
test.log(Status.PASS, MarkupHelper.createLabel(result.getMethod().getMethodName() + "Test Case Status is passed", ExtentColor.GREEN));
}
public void onTestFailure(ITestResult result) {
WebDriver driver = (WebDriver) result.getTestContext().getAttribute("driver");
//System.out.println("onTestFailure called ...");
//test.log(Status.FAIL, MarkupHelper.createLabel(result.getMethod().getMethodName() + " - Test Case Failed", ExtentColor.RED));
String screenShotPath = ScreenShotRecorder.captureScreenshot(driver, result.getMethod().getMethodName());
test.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED));
try {
test.fail(result.getThrowable()).addScreenCaptureFromPath(screenShotPath);
} catch (IOException e) {
test.log(Status.FAIL, "!!!!!!!!! Exception occurred while attaching the screenshot to extent report");
}
//test.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED));
}
public void onTestSkipped(ITestResult result) {
test.log(Status.SKIP, MarkupHelper.createLabel(result.getMethod().getMethodName() + " - Test Case Skipped", ExtentColor.ORANGE));
}
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
// TODO Auto-generated method stub
//System.out.println("onTestFailedButWithinSuccessPercentage called ...");
}
public void onStart(ITestContext context) {
//System.out.println("onStart called ...");
//System.out.println("test name ::: "+ context.getName());
//test = extent.createTest(context.getName());
}
public void onFinish(ITestContext context) {
//System.out.println("onFinish called ...");
extent.flush();
extent.removeTest(test);
}