Java 如何在数据块报告中不显示未知/跳过的结果
我在selenium代码中使用RetryAnalyzer,其中,如果测试用例在第一次执行中失败,RetryAnalyzer将再次执行它。在我的例子中,如果第一次执行失败,第二次执行通过,我只想在数据块报告中显示第二次执行的结果。但是我在报告中得到了这两个测试用例的结果Java 如何在数据块报告中不显示未知/跳过的结果,java,extentreports,extent,Java,Extentreports,Extent,我在selenium代码中使用RetryAnalyzer,其中,如果测试用例在第一次执行中失败,RetryAnalyzer将再次执行它。在我的例子中,如果第一次执行失败,第二次执行通过,我只想在数据块报告中显示第二次执行的结果。但是我在报告中得到了这两个测试用例的结果 if (result.getStatus() == ITestResult.FAILURE && firstTry == true) { } 下面是我的代码 ExtentTest test; int maxRet
if (result.getStatus() == ITestResult.FAILURE && firstTry == true) { }
下面是我的代码
ExtentTest test;
int maxRetryCount = 1;
@AfterMethod
protected void afterMethod(ITestResult result) {
boolean firstTry = true;
if(maxRetryCount>0){
if (result.getStatus() == ITestResult.FAILURE && firstTry == true) {
firstTry = false;
} else if (result.getStatus() == ITestResult.SKIP) {
test.log(LogStatus.SKIP, "Test skipped " + result.getThrowable());
} else if (result.getStatus() == ITestResult.FAILURE && firstTry == false) {
test.log(LogStatus.ERROR, test.addScreenCapture(imgPath));
test.log(LogStatus.FAIL, result.getThrowable());
} else {
test.log(LogStatus.PASS, "Test passed");
}
}else{
if (result.getStatus() == ITestResult.FAILURE) {
test.log(LogStatus.ERROR, test.addScreenCapture(imgPath));
test.log(LogStatus.FAIL, result.getThrowable());
} else if (result.getStatus() == ITestResult.SKIP) {
test.log(LogStatus.SKIP, "Test skipped " + result.getThrowable());
} else {
test.log(LogStatus.PASS, "Test passed");
}
}
}
在这种情况下,如果测试用例在第一次执行中失败,它将该测试用例的状态显示为“未知”,并且假设执行在重试(第二次执行)中通过,则通过百分比显示为50%,而不是100%,因为它也计算未知的百分比
在下面的循环条件下,我应该做哪些更改,以使此测试用例的结果不会显示在报告中
if (result.getStatus() == ITestResult.FAILURE && firstTry == true) { }
请建议。如果测试状态为跳过,则可以删除当前测试节点。像这样的东西会有用的
@BeforeMethod(alwaysRun=true)
public void beforeMethod(){
//be sure to create node in the BeforeMethod
HtmlReporter.createNode("CurrentTest");
}
@AfterMethod(alwaysRun = true)
public void afterMethod(ITestResult result) {
if (result.getStatus() == ITestResult.SKIP) {
HtmlReporter.removeCurrentNode();
}
删除当前节点的代码如下所示:
public static synchronized void removeCurrentNode() {
_report.removeTest(getNode());
}
public static synchronized ExtentTest getNode() {
return extentTestMap.get("node_" + Thread.currentThread().getId());
}
是否有帮助?此链接与数据块报告无关。我在数据块报告中显示结果时遇到问题。您好,您找到解决方案了吗?