问题描述
我为此创建了单独的侦听器类,如下所示:
public class TestListeners implements ITestListener {
@Override
public void onTestSkipped(ITestResult result) {
System.out.println("The name of the testcase Skipped is :"
+ result.getName());
BaseClass.test1.log(Status.INFO,"The name of the testcase Skipped is :" + result.getName());
BaseClass.test1.log(Status.SKIP,MarkupHelper.createLabel(result.getName(),ExtentColor.YELLOW));
BaseClass.test1.log(Status.SKIP,result.getThrowable());
BaseClass.extent.flush();
}
@Override
public void onTestFailedButWithinSuccesspercentage(ITestResult result) {
// Todo Auto-generated method stub
}
}
此后,我在我的基类中使用了@Listeners(TestListeners.class)。 我的情况是,我必须基于类A中存在的测试用例1的结果来跳过类B中存在的测试用例2,并且我同样使用的是DependsOnGroups。
现在一切正常,但是跳过的测试用例在扩展区报告中不可见,而是仅在Eclipse IDE控制台报告中可见。
@Listeners(TestListeners.class)
public class BaseClass {
public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test1;
public static WebDriver driver;
@BeforeSuite
public static void setup() throws InterruptedException,IOException {
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")
+ "/Report/RegressionSuit_" + util.getFileExtension()
+ ".html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
htmlReporter.config().setChartVisibilityOnopen(true);
htmlReporter.config().setDocumentTitle(
"AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("RegressionSuit");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
}
@AfterMethod
public void getResult(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
test1.log(Status.FAIL,MarkupHelper.createLabel(result.getName()
+ " :Test case Failed due to below issues:",ExtentColor.RED));
test1.log(Status.FAIL,result.getThrowable());
} else if (result.getStatus() == ITestResult.SUCCESS) {
test1.log(
Status.PASS,MarkupHelper.createLabel(result.getName()
+ " :Test Case PASSED",ExtentColor.GREEN));
} else if (result.getStatus() == ITestResult.SKIP) {
test1.log(
Status.SKIP,MarkupHelper.createLabel(result.getName()
+ " :Test Case SKIPPED ",ExtentColor.YELLOW));
}
}
@AfterSuite
public void tearDown() {
extent.flush();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)