我在我的测试项目中运行黄瓜硒范围报告。我想知道如何将类名+方法名添加到范围报告中以获取通过/失败测试结果。下面是我的代码:
@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();
}
}
问题:
- 是否在@Test 中添加捕获方法名称?使用 Cucumber 来实现这一点怎么样?
- 将范围报告与 Cucumber runner 类集成的最佳设计方法是什么?
请帮忙。希望有人能真正帮助我。