From 80a56448bf7dade2d1506e8ae7acc6b6e344bd59 Mon Sep 17 00:00:00 2001 From: zhangdahai112 Date: Tue, 13 Sep 2022 19:00:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(UI=E8=87=AA=E5=8A=A8=E5=8C=96):=20=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E7=8A=B6=E6=80=81=E9=80=9A=E8=BF=87=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AF=E6=B5=8B=E8=AF=95=E6=8A=A5=E5=91=8A=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=BAERROR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016682 --user=张大海 【UI测试】github#17821,UI自动化执行成功,用例状态也是通过,但是测试报告状态为ERROR https://www.tapd.cn/55049933/s/1242333 --- .../api/service/ApiScenarioReportService.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index e466a612ea..137a0c5be8 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -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 selectForPlanReport(List reportIds) { return extApiScenarioReportMapper.selectForPlanReport(reportIds); }