我在我的测试项目中运行了Cucumber selenium extent报告。我想知道如何在通过/失败测试结果的范围报告中添加类名+方法名。下面是我的代码:
@CucumberOptions(
features = "src/Feature",
glue = {"Step_Definitions"},
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json",
"rerun:target/cucumber-reports/rerun.txt"
})
public class TestRunner {
private TestNGCucumberRunner testNGCucumberRunner;
private ExtentHtmlReporter htmlReporter;
private ExtentReports extent;
private ExtentTest logger;
@BeforeTest(alwaysRun = true)
public void setUp() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/report/Test-Report.html");
extent = new ExtentReports ();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("Host Name", "MyTest");
extent.setSystemInfo("Environment", "SIT");
extent.setSystemInfo("User Name", "Peter Wong");
htmlReporter.config().setDocumentTitle("Test Report");
htmlReporter.config().setReportName("Test Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
}
@Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "dataProvider")
public void feature(CucumberFeatureWrapper cucumberFeature) {
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}
/*
@Test
public void passTest(){
logger = extent.createTest("passTest");
Assert.assertTrue(true);
logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is passTest", ExtentColor.GREEN));
try {
logger.fail("Pass Details", MediaEntityBuilder.createScreenCaptureFromPath("screenshot.png").build());
} catch (IOException ex) {
LogManager.logger.log(Level.INFO, "Exception: " + ex.getMessage());
}
}
*/
@AfterMethod
public void getResult(ITestResult result){
if(result.getStatus() == ITestResult.FAILURE) {
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, MarkupHelper.createLabel(result.getName() + " - Test Case Skipped", ExtentColor.ORANGE));
}
}
@AfterTest(alwaysRun = true)
public void tearDown() throws Exception {
extent.flush();
testNGCucumberRunner.finish();
}
}
问题: