[英]Run @AfterMethod only when my @Test is passed, not if @Test fails
我的afterMethod
由以下afterMethod
組成:
@AfterMethod(groups = { "Regression" })
public void afterMethod() {
// Setting driver used to false as this test case is pass
driverUsed.put("supportDriver", false);
System.out.println("Test case is pass");
}
我把驅動程序false
但是我希望只在我的@Test
通過時才運行afterMethod
,而不是@test
失敗時。
引用TestNG的文檔 :
任何
@AfterMethod
方法都可以聲明一個ITestResult
類型的參數,它將反映剛剛運行的測試方法的結果。
您可以使用此參數來檢查測試是否成功:
@AfterMethod(groups = { "Regression" })
public void afterMethod(ITestResult result) {
if (result.getStatus() == ITestResult.SUCCESS) {
// Setting driver used to false as this test case is pass
driverUsed.put("supportDriver", false);
System.out.println("Test case is pass");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.