From 3dade654bb455502843d59eda171bd64c5f1f949 Mon Sep 17 00:00:00 2001 From: zhangdahai112 Date: Wed, 7 Sep 2022 17:12:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(UI=20=E8=87=AA=E5=8A=A8=E5=8C=96)=20ui?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8A=A5=E5=91=8A=E8=AE=A1=E6=95=B0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016623 --user=张大海 【UI测试】当成功的步骤为0时-通过率计算错误 https://www.tapd.cn/55049933/s/1240131 --bug=1016626 --user=张大海 【UI测试】生成报告-步骤统计-未执行统计错误 https://www.tapd.cn/55049933/s/1240133 --- .../api/service/utils/PassRateUtil.java | 32 +++++++++++++------ .../report/components/MetricChart.vue | 9 +++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java b/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java index 2e1fd1a7b1..031a10a4d8 100644 --- a/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java +++ b/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java @@ -28,8 +28,6 @@ import java.util.stream.Collectors; */ public class PassRateUtil { - private final static String UISCENARIO_TYPE_NAME = "scenario"; - public static String calculatePassRate(List requestResults, ApiScenarioReport report) { if (CollectionUtils.isEmpty(requestResults)) { return "0"; @@ -70,11 +68,15 @@ public class PassRateUtil { AtomicLong atomicLong = new AtomicLong(); stepList.forEach(stepFather -> { stepFather.getChildren().forEach(step -> { - if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) { + //scenario 拥有 hashtree 的控制语句 + if (CollectionUtils.isNotEmpty(step.getChildren())) { AtomicLong failCount = new AtomicLong(); + AtomicLong unExecuteCount = new AtomicLong(); getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount); + getUIUnExecuteStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), unExecuteCount); + //复制或者嵌套场景的成功只算 1 次 - if (failCount.get() == 0) { + if (failCount.get() == 0 && unExecuteCount.get() == 0) { atomicLong.getAndAdd(1); } } else { @@ -93,16 +95,28 @@ public class PassRateUtil { * * @param stepTrees * @param resultIdMap - * @param failCount + * @param count * @return */ - private static void getUIFailStepCount(Map> resultIdMap, List stepTrees, AtomicLong failCount) { + private static void getUIFailStepCount(Map> resultIdMap, List stepTrees, AtomicLong count) { stepTrees.forEach(step -> { - if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) { - getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount); + if (CollectionUtils.isNotEmpty(step.getChildren())) { + getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), count); } else { if (resultIdMap.containsKey(step.getResourceId()) && CollectionUtils.isNotEmpty(resultIdMap.get(step.getResourceId()))) { - calculateCount(resultIdMap, failCount, step, ScenarioStatus.Fail.name()); + calculateCount(resultIdMap, count, step, ScenarioStatus.Fail.name()); + } + } + }); + } + + private static void getUIUnExecuteStepCount(Map> resultIdMap, List stepTrees, AtomicLong count) { + stepTrees.forEach(step -> { + if (CollectionUtils.isNotEmpty(step.getChildren())) { + getUIUnExecuteStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), count); + } else { + if (!resultIdMap.containsKey(step.getResourceId())) { + count.getAndIncrement(); } } }); diff --git a/frontend/src/business/components/api/automation/report/components/MetricChart.vue b/frontend/src/business/components/api/automation/report/components/MetricChart.vue index 05bfb22524..1e34a0faa7 100644 --- a/frontend/src/business/components/api/automation/report/components/MetricChart.vue +++ b/frontend/src/business/components/api/automation/report/components/MetricChart.vue @@ -129,7 +129,7 @@
{{ - content.scenarioStepUnExecuteReport ? content.scenarioStepUnExecuteReport : 0 + uiUnExecuteCount }}
{{ $t('api_test.home_page.detail_card.unexecute') }}
@@ -310,6 +310,13 @@ export default { return (this.content.scenarioStepUnExecuteReport && this.content.scenarioStepUnExecuteReport > 0) || (this.content.scenarioUnExecute && this.content.scenarioUnExecute > 0) || (this.content.unExecute && this.content.unExecute > 0); }, + uiUnExecuteCount() { + if (this.content.scenarioStepTotal) { + return this.content.scenarioStepTotal - (this.content.scenarioStepSuccess || 0) - (this.content.scenarioStepError || 0); + } else { + return 0; + } + } }, }