虽然TestNG自身提供了简洁的测试报告,可能我们想自己编写漂亮的测试,
@AfterMethod
public void cleanTestCase(ITestResult testResult) {
System.out.println("testResult.getName():"+testResult.getName());
System.out.println("testResult.getTestName():"+testResult.getTestName());
System.out.println("testResult.getTestContext():"+testResult.getTestContext());
System.out.println("testResult.getInstanceName():"+testResult.getInstanceName());
System.out.println("testResult.getInstance():"+testResult.getInstance());
System.out.println("testResult.getThrowable():"+testResult.getThrowable());
那么怎么获取测试过程中的相关测试数据呢?
可以直接调用ITestResult中的api,
例如:
}
控制台打印可见:
testResult.getName():testLogin
testResult.getTestName():null
testResult.getTestContext():org.testng.TestRunner@5a330c39
testResult.getInstanceName():com.lu.automation.mobile.testcases.TestLoginPage
testResult.getInstance():com.lu.automation.mobile.testcases.TestLoginPage@38b3b029
testResult.getThrowable():org.openqa.selenium.TimeoutException: Timed out after 60 seconds waiting for element to no longer be visible: By.id: title_bar_right_tv
ITestResult.getName() 是测试用例名
ITestResult.getStatus() 测试执行结果: ITestResult.SUCCESS,ITestResult.FAILURE,ITestResult.SKIP
ITestResult.getThrowable() 测试的报错信息