From ad85f0814f1b5f616217268ba0483209f3d397ea Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 16 Jun 2021 11:30:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=BA=E6=99=AF=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B7=B3=E8=BD=AC=E5=8A=9F=E8=83=BD=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AD=A5=E9=AA=A4=E7=BB=9F=E8=AE=A1=E7=BA=AC?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 场景报告增加跳转功能、增加步骤统计纬度 --- .../api/jmeter/APIBackendListenerClient.java | 16 ++--- .../io/metersphere/api/jmeter/TestResult.java | 66 ++++++++++++++++--- .../api/service/ApiScenarioReportService.java | 3 + .../automation/report/ApiReportViewHeader.vue | 30 ++++++++- .../report/components/MetricChart.vue | 29 ++++++-- .../automation/scenario/EditApiScenario.vue | 1 + 6 files changed, 122 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 2ab2df8e41..eb18673f8e 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -131,11 +131,11 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl LogUtil.error("testPlanApiCaseService is required"); } apiEnvironmentRunningParamService = CommonBeanFactory.getBean(ApiEnvironmentRunningParamService.class); - if (apiEnvironmentRunningParamService == null) { + if(apiEnvironmentRunningParamService == null){ LogUtil.error("apiEnvironmentRunningParamService is required"); } testPlanTestCaseService = CommonBeanFactory.getBean(TestPlanTestCaseService.class); - if (testPlanTestCaseService == null) { + if(testPlanTestCaseService == null){ LogUtil.error("testPlanTestCaseService is required"); } super.setupTest(context); @@ -151,17 +151,16 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl public void teardownTest(BackendListenerContext context) throws Exception { TestResult testResult = new TestResult(); testResult.setTestId(testId); - testResult.setTotal(queue.size()); testResult.setConsole(getConsole()); - + testResult.setTotal(0); // 一个脚本里可能包含多个场景(ThreadGroup),所以要区分开,key: 场景Id final Map scenarios = new LinkedHashMap<>(); queue.forEach(result -> { // 线程名称: <场景名> <场景Index>-<请求Index>, 例如:Scenario 2-1 - if (StringUtils.equals(result.getSampleLabel(), RunningParamKeys.RUNNING_DEBUG_SAMPLER_NAME)) { + if(StringUtils.equals(result.getSampleLabel(), RunningParamKeys.RUNNING_DEBUG_SAMPLER_NAME)){ String evnStr = result.getResponseDataAsString(); apiEnvironmentRunningParamService.parseEvn(evnStr); - } else { + }else { String scenarioName = StringUtils.substringBeforeLast(result.getThreadName(), THREAD_SPLIT); String index = StringUtils.substringAfterLast(result.getThreadName(), THREAD_SPLIT); String scenarioId = StringUtils.substringBefore(index, ID_SPLIT); @@ -193,11 +192,12 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl testResult.addPassAssertions(requestResult.getPassAssertions()); testResult.addTotalAssertions(requestResult.getTotalAssertions()); - + testResult.setTotal(testResult.getTotal()+1); scenarioResult.addPassAssertions(requestResult.getPassAssertions()); scenarioResult.addTotalAssertions(requestResult.getTotalAssertions()); } }); + testResult.getScenarios().addAll(scenarios.values()); testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId)); ApiTestReport report = null; @@ -297,7 +297,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl //环境 ApiScenarioWithBLOBs apiScenario = apiAutomationService.getDto(scenarioReport.getScenarioId()); String name = ""; - if (apiScenario != null) { + if(apiScenario!= null ) { String executionEnvironment = apiScenario.getScenarioDefinition(); JSONObject json = JSONObject.parseObject(executionEnvironment); if (json != null && json.getString("environmentMap") != null && json.getString("environmentMap").length() > 2) { diff --git a/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java b/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java index 06327f3f25..d082098b37 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java @@ -1,6 +1,7 @@ package io.metersphere.api.jmeter; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import io.metersphere.commons.constants.DelimiterConstants; import lombok.Data; import org.apache.commons.collections.CollectionUtils; @@ -40,12 +41,15 @@ public class TestResult { private String console; - private String runningDebugSampler; - private List scenarios = new ArrayList<>(); private Map margeScenariMap = new HashMap<>(); + private Map scenarioStepMap = new HashMap<>(); + + private int scenarioStepSuccess = 0; + private int scenarioStepError = 0; + private int scenarioStepTotal = 0; public void addError(int count) { this.error += count; } @@ -74,12 +78,33 @@ public class TestResult { } } + private void setStepStatus(String step_names, boolean status) { + if (!scenarioStepMap.containsKey(step_names) || status) { + scenarioStepMap.put(step_names, status); + } + } + + public void addScenario(ScenarioResult result) { if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) { result.getRequestResults().forEach(item -> { + String itemScenarioName = ""; if (StringUtils.isNotEmpty(item.getScenario())) { - List id_names = JSON.parseObject(item.getScenario(), List.class); - this.setStatus(id_names, item.getError() > 0); + List all_id_names = JSON.parseObject(item.getScenario(), List.class); + if(all_id_names.size()>1){ + List id_names = new ArrayList<>(); + all_id_names.forEach(name -> { + if(!name.endsWith(result.getName())){ + id_names.add(name); + } + }); + this.setStatus(id_names, item.getError() > 0); + itemScenarioName = JSONArray.toJSONString(id_names); + }else{ + this.setStatus(all_id_names, item.getError() > 0); + itemScenarioName = JSONArray.toJSONString(all_id_names); + } + } if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) { String array[] = item.getName().split(SEPARATOR); @@ -102,17 +127,38 @@ public class TestResult { } }); } + this.setStepStatus(item.getName()+itemScenarioName,item.getError()>0); }); scenarios.add(result); } - for (String key : margeScenariMap.keySet()) { - if (margeScenariMap.get(key)) { - this.scenarioError++; + /** + * 1.10.2 场景成功/失败统计,不再按照请求为纬度,按照场景为纬度, + */ + for (String key : scenarioStepMap.keySet()) { + if (scenarioStepMap .get(key)) { + this.scenarioStepError++; } else { - this.scenarioSuccess++; + this.scenarioStepSuccess++; } } - this.setScenarioTotal(this.margeScenariMap.size()); + boolean hasError = false; + for (String key : margeScenariMap.keySet()) { + if (margeScenariMap.get(key)) { + hasError = true; + break; + } + } + if(!margeScenariMap.isEmpty()){ + if(hasError){ + this.scenarioError ++; + }else { + this.scenarioSuccess++; + } + this.scenarioTotal++; + } + + + this.setScenarioStepTotal(this.scenarioStepMap.size()); } -} +} \ No newline at end of file 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 d0268221ca..5739f81baf 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -384,6 +384,9 @@ public class ApiScenarioReportService { testResult.setScenarioSuccess(testResult.getScenarioSuccess() + scenarioResult.getScenarioSuccess()); testResult.setScenarioError(testResult.getScenarioError() + scenarioResult.getScenarioError()); testResult.setConsole(scenarioResult.getConsole()); + testResult.setScenarioStepError(scenarioResult.getScenarioStepError()+testResult.getScenarioStepError()); + testResult.setScenarioStepSuccess(scenarioResult.getScenarioStepSuccess()+testResult.getScenarioStepSuccess()); + testResult.setScenarioStepTotal(scenarioResult.getScenarioStepTotal()+testResult.getScenarioStepTotal()); } catch (Exception e) { LogUtil.error(e.getMessage()); } diff --git a/frontend/src/business/components/api/automation/report/ApiReportViewHeader.vue b/frontend/src/business/components/api/automation/report/ApiReportViewHeader.vue index 1ec68ac2c4..6f58caa422 100644 --- a/frontend/src/business/components/api/automation/report/ApiReportViewHeader.vue +++ b/frontend/src/business/components/api/automation/report/ApiReportViewHeader.vue @@ -2,7 +2,19 @@
- + + + + + + {{ report.name }} + + + {{ report.name }} + + + + {{ report.createTime | timestampFormatDate }} @@ -30,10 +42,26 @@ path() { return "/api/test/edit?id=" + this.report.testId; }, + scenarioId(){ + if(typeof this.report.scenarioId === 'string'){ + return this.report.scenarioId; + }else { + return ""; + } + }, + isSingleScenario(){ + try { + JSON.parse(this.report.scenarioId); + return false; + } catch(e){ + return true; + } + } }, data() { return { isReadOnly: false, + nameIsEdit:false, } }, created() { 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 add6a6d5f0..5e251f9489 100644 --- a/frontend/src/business/components/api/automation/report/components/MetricChart.vue +++ b/frontend/src/business/components/api/automation/report/components/MetricChart.vue @@ -38,22 +38,43 @@
-
+ +
{{ content.scenarioTotal ? content.scenarioTotal : 0}}
{{ $t('api_test.scenario.scenario') }}
- +
{{ content.scenarioSuccess ? content.scenarioSuccess: 0 }}
{{ $t('api_report.success') }}
-
- + +
{{ content.scenarioError ? content.scenarioError : 0 }}
{{ $t('api_report.fail') }}
+ + + +
+
{{ content.scenarioStepTotal ? content.scenarioStepTotal : 0}}
+
{{ $t('test_track.plan_view.step') }}
+
+ +
+
{{ content.scenarioStepSuccess ? content.scenarioStepSuccess: 0 }}
+
{{ $t('api_report.success') }}
+
+ + +
+
{{ content.scenarioStepError ? content.scenarioStepError : 0 }}
+
{{ $t('api_report.fail') }}
+
+
+
diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index f74f1ed9c3..0188ffa5c6 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -318,6 +318,7 @@ export default { data() { return { onSampleError: false, + showConfigButtonWithOutPermission:false, props: { label: "label", children: "hashTree"