我已经使用多个测试套件生成了范围报告。 但是它仅在范围报告中显示最后一个测试套件。 这是我的代码 要生成报告,我将以下代码用于每个测试用例。 和 它仅在范围报告中显示第二个套件结果。 建议我如何在范围报告中添加所有测试套件结果。 答案 0 :(得分:1) 将您的@BeforeSuite
public void beforeSuite() {
htmlReporter = new ExtentHtmlReporter(Utils.getReportDir() + "/report.html");
htmlReporter.loadXMLConfig(String.valueOf(new File("src/test/java/extentreports/extent-config.xml")));
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS Name", System.getProperty("os.name"));
extent.setSystemInfo("OS Version", System.getProperty("os.version"));
extent.setSystemInfo("Java Version", System.getProperty("java.version"));
extent.setSystemInfo("User Name", System.getProperty("user.name"));
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("Automation");
htmlReporter.config().setReportName("Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
@AfterMethod
public void getResult(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " Test case FAILED due to below issues:", ExtentColor.RED));
test.fail(result.getThrowable());
String screenShotPath = MobileActions.Screenshot("Failed");
try {
test.addScreenCaptureFromPath(screenShotPath);
} catch (IOException e) {
e.printStackTrace();
}
} else if (result.getStatus() == ITestResult.SUCCESS) {
test.log(Status.PASS, MarkupHelper.createLabel(result.getName() + " Test Case PASSED", ExtentColor.GREEN));
} else {
test.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " Test Case SKIPPED", ExtentColor.ORANGE));
test.skip(result.getThrowable());
}
}
@AfterSuite
public void flushReport() {
extent.flush();
loginAndroid.quitTest();
}
test = extent.createTest("Add Image on Canvas");
testng.xml
如下。 <suite-files>
<suite-file path="Font_Module.xml"></suite-file>
<suite-file path="Image_Module.xml"></suite-file>
</suite-files>
1 个答案:
@BeforeSuite
更改为@BeforeTest
并且
@AfterSuite
至@AfterTest
,它应该可以正常工作。