下面是我的代码,立即获得异常,它应该触发一次执行时间但没有执行。如果不尝试,则捕获它正在执行,但是将代码放入尝试并捕获后,RetryAnalyzer无法按预期工作,请任何人帮助我如何在try,catch块中实现RetryAnalyzer
@Test(priority=4,enabled=true,retryAnalyzer=RetryAnalyzer.class)
public void TC_04() throws InterruptedException
{
try
{
extent=new
ExtentReports("/Users/anakin/workspace/Reports/MKE.html");
Login_Objects.Switch_PB2U(driver).click();
String screenshot_path = Screenshot.createScreenshot(driver);
String image = log.addScreenCapture(screenshot_path);
log.log(LogStatus.PASS, "To Stocks",image);
extent.endTest(log);
driver.closeApp();
}
catch(Exception e)
{
String screenshot_path = Screenshot.createScreenshot(driver);
String image = log.addScreenCapture(screenshot_path);
log.log(LogStatus.FAIL, "Verify Suggest Stocks ", image);
extent.endTest(log);
}
}
答案 0 :(得分:0)
在完整的测试代码中捕获异常是一种不好的做法。即使您遇到故障时仍在捕获屏幕截图, you should use listener than catching exception.
由于重试分析器适用于失败的测试,并且您正在处理异常并因此抑制了错误,因此可能会给人一种印象,即您的测试从未失败,因此retryAnalyzer无法正常工作。
解决方案: Move code in Exception to Listeners and remove unnecessary Exception handling.