fix(UI自动化): 用例状态通过,但是测试报告状态为ERROR

--bug=1016682 --user=张大海 【UI测试】github#17821,UI自动化执行成功,用例状态也是通过,但是测试报告状态为ERROR https://www.tapd.cn/55049933/s/1242333
This commit is contained in:
zhangdahai112 2022-09-13 19:00:22 +08:00 committed by f2c-ci-robot[bot]
parent b8d2750088
commit bc6ed06cce
1 changed files with 27 additions and 6 deletions

View File

@ -964,12 +964,7 @@ public class ApiScenarioReportService {
//类型为ui时的统计
if (StringUtils.isNotEmpty(dto.getRunMode()) && dto.getRunMode().startsWith("UI")) {
try {
errorSize = dto.getRequestResults().stream().filter(requestResult ->
StringUtils.isNotEmpty(requestResult.getResponseResult().getHeaders())
&& JSONArray.parseArray(requestResult.getResponseResult().getHeaders()).stream().filter(
r -> ((JSONObject) r).containsKey("success") && !((JSONObject) r).getBoolean("success")
).count() > 0)
.count();
errorSize = getUiErrorSize(dto);
} catch (Exception e) {
// UI 返回的结果在 headers 里面格式不符合规范的直接认定结果为失败
errorSize = 1;
@ -989,6 +984,32 @@ public class ApiScenarioReportService {
return status;
}
/**
* 主流程或者有断言失败的就算失败
*
* @param dto
* @return
*/
private long getUiErrorSize(ResultDTO dto) {
int errorSize = 0;
for (RequestResult r : dto.getRequestResults()) {
if (StringUtils.isNotEmpty(r.getResponseResult().getHeaders())) {
JSONArray responseArr = JSONArray.parseArray(r.getResponseResult().getHeaders());
for (int i = 0; i < responseArr.size(); i++) {
JSONObject stepResult = responseArr.getJSONObject(i);
if (stepResult.containsKey("success") && !stepResult.getBoolean("success")) {
if ((stepResult.containsKey("processType") && StringUtils.equalsIgnoreCase("MAIN", stepResult.getString("processType")))
|| (stepResult.containsKey("cmdName")
&& ((stepResult.getString("cmdName").startsWith("verify")) || stepResult.getString("cmdName").startsWith("assert")))) {
errorSize++;
}
}
}
}
}
return errorSize;
}
public List<PlanReportCaseDTO> selectForPlanReport(List<String> reportIds) {
return extApiScenarioReportMapper.selectForPlanReport(reportIds);
}