From 0283f7b38dd6deabdd1d46a6f175f5e81f9bdf6c Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 10 Jan 2022 17:34:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=A5=E5=91=8A=E5=9C=BA=E6=99=AF=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E8=B0=83=E8=AF=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1009281 --user=赵勇 [github#8902]接口自动化中部分引用场景会存在执行后无执行记录 https://www.tapd.cn/55049933/s/1090091 --- .../request/sampler/MsDubboSampler.java | 2 +- .../request/sampler/MsHTTPSamplerProxy.java | 2 +- .../request/sampler/MsJDBCSampler.java | 2 +- .../request/sampler/MsTCPSampler.java | 2 +- .../ApiScenarioReportStructureService.java | 10 +++--- .../automation/report/SysnApiReportDetail.vue | 5 ++- .../automation/scenario/EditApiScenario.vue | 18 +++++----- .../scenario/component/ApiComponent.vue | 1 + .../component/ApiScenarioComponent.vue | 33 ++++++++++++++++++- 9 files changed, 57 insertions(+), 18 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index a0d1c4eb18..3d9e212334 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -154,7 +154,7 @@ public class MsDubboSampler extends MsTestElement { sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui")); sampler.setProperty("MS-ID", this.getId()); String indexPath = this.getIndex(); - sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath)); + sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath)); List id_names = new LinkedList<>(); ElementUtil.getScenarioSet(this, id_names); sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names)); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index e1a8c9dc44..cd32eb5985 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -200,7 +200,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui")); sampler.setProperty("MS-ID", this.getId()); String indexPath = this.getIndex(); - sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath)); + sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath)); List id_names = new LinkedList<>(); ElementUtil.getScenarioSet(this, id_names); sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names)); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index 3e50d472d2..1e91ae1055 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -302,7 +302,7 @@ public class MsJDBCSampler extends MsTestElement { sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); sampler.setProperty("MS-ID", this.getId()); String indexPath = this.getIndex(); - sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath)); + sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath)); List id_names = new LinkedList<>(); ElementUtil.getScenarioSet(this, id_names); sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names)); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 5f76443206..cddc101bfb 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -244,7 +244,7 @@ public class MsTCPSampler extends MsTestElement { tcpSampler.setName(this.getName()); tcpSampler.setProperty("MS-ID", this.getId()); String indexPath = this.getIndex(); - tcpSampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath)); + tcpSampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath)); List id_names = new LinkedList<>(); ElementUtil.getScenarioSet(this, id_names); tcpSampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names)); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java index b8340dc711..982e7bf708 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java @@ -79,6 +79,7 @@ public class ApiScenarioReportStructureService { StepTreeDTO dto = null; if (element != null && element.getBoolean("enable")) { String referenced = element.getString("referenced"); + String type = element.getString("type"); if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) { if (StringUtils.equals(element.getString("type"), "scenario")) { ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id")); @@ -87,10 +88,10 @@ public class ApiScenarioReportStructureService { } } } - String resourceId = element.getString("resourceId"); + String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id"); if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { if (StringUtils.isNotEmpty(resourceId) && StringUtils.isNotEmpty(apiScenario.getId()) && !resourceId.contains(apiScenario.getId())) { - resourceId = apiScenario.getId() + "=" + element.getString("resourceId"); + resourceId = apiScenario.getId() + "=" + resourceId; } } dto = new StepTreeDTO(apiScenario.getName(), resourceId, element.getString("type"), 1); @@ -116,10 +117,11 @@ public class ApiScenarioReportStructureService { } } } - String resourceId = element.getString("resourceId"); + String type = element.getString("type"); + String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id"); if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { if (StringUtils.isNotEmpty(resourceId) && StringUtils.isNotEmpty(id) && !resourceId.contains(id)) { - resourceId = id + "=" + element.getString("resourceId"); + resourceId = id + "=" + resourceId; } } StepTreeDTO children = new StepTreeDTO(element.getString("name"), resourceId, element.getString("type"), element.getIntValue("index")); diff --git a/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue b/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue index d05b851cfc..b6d1c6f21b 100644 --- a/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue +++ b/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue @@ -162,7 +162,10 @@ export default { if (item.enable) { item.parentIndex = fullPath ? fullPath + "_" + item.index : item.index; let name = item.name ? item.name : this.getType(item.type); - let obj = {pid: pid, resId: item.resourceId + "_" + item.parentIndex, index: Number(item.index), label: name, value: {name: name, responseResult: {}, unexecute: true, testing: false}, children: [], unsolicited: true}; + let obj = { + pid: pid, resId: (item.type === 'JSR223Processor' ? item.resourceId : item.id) + "_" + item.parentIndex, index: Number(item.index), label: name, + value: {name: name, responseResult: {}, unexecute: true, testing: false}, children: [], unsolicited: true + }; tree.children.push(obj); if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1) { obj.unsolicited = false; diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index d88ab8ba33..cb7d53d7be 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -730,7 +730,7 @@ export default { }, resultEvaluationChild(arr, resourceId, status) { arr.forEach(item => { - if (item.data.resourceId + "_" + item.data.parentIndex === resourceId) { + if (item.data.id + "_" + item.data.parentIndex === resourceId) { item.data.testing = false; this.evaluationParent(item.parent, status); } @@ -742,7 +742,7 @@ export default { resultEvaluation(resourceId, status) { if (this.$refs.stepTree && this.$refs.stepTree.root) { this.$refs.stepTree.root.childNodes.forEach(item => { - if (item.data.resourceId + "_" + item.data.parentIndex === resourceId) { + if (item.data.id + "_" + item.data.parentIndex === resourceId) { item.data.testing = false; } if (item.childNodes && item.childNodes.length > 0) { @@ -774,7 +774,7 @@ export default { let data = JSON.parse(resultData.substring(7)); if (data.method === 'Request' && data.subRequestResults && data.subRequestResults.length > 0) { data.subRequestResults.forEach(subItem => { - if (item.data && item.data.resourceId + "_" + item.data.parentIndex === subItem.resourceId) { + if (item.data && item.data.id + "_" + item.data.parentIndex === subItem.resourceId) { subItem.requestResult.console = data.responseResult.console; item.data.requestResult.push(subItem); // 更新父节点状态 @@ -783,14 +783,15 @@ export default { item.data.debug = true; } }) - } else if (item.data && item.data.resourceId + "_" + item.data.parentIndex === data.resourceId) { + } else if ((item.data && item.data.id + "_" + item.data.parentIndex === data.resourceId) + || (item.data && item.data.resourceId + "_" + item.data.parentIndex === data.resourceId)) { item.data.requestResult.push(data); // 更新父节点状态 this.resultEvaluation(data.resourceId, data.success); item.data.testing = false; item.data.debug = true; } - } else if (item.data && item.data.resourceId + "_" + item.data.parentIndex === resultData) { + } else if (item.data && item.data.id + "_" + item.data.parentIndex === resultData) { item.data.testing = true; this.runningEditParent(item.parent); } @@ -802,13 +803,13 @@ export default { runningEvaluation(resultData) { if (this.$refs.stepTree && this.$refs.stepTree.root) { this.$refs.stepTree.root.childNodes.forEach(item => { - if (item.data && item.data.resourceId + "_" + item.data.parentIndex === resultData) { + if (item.data && item.data.id + "_" + item.data.parentIndex === resultData) { item.data.testing = true; } else if (resultData && resultData.startsWith("result_")) { let data = JSON.parse(resultData.substring(7)); if (data.method === 'Request' && data.subRequestResults && data.subRequestResults.length > 0) { data.subRequestResults.forEach(subItem => { - if (item.data && item.data.resourceId + "_" + item.data.parentIndex === subItem.resourceId) { + if (item.data && item.data.id + "_" + item.data.parentIndex === subItem.resourceId) { item.data.requestResult.push(subItem); // 更新父节点状态 this.resultEvaluation(subItem.resourceId, subItem.success); @@ -816,7 +817,8 @@ export default { item.data.debug = true; } }) - } else if (item.data && item.data.resourceId + "_" + item.data.parentIndex === data.resourceId) { + } else if (item.data && item.data.id + "_" + item.data.parentIndex === data.resourceId + || (item.data && item.data.resourceId + "_" + item.data.parentIndex === data.resourceId)) { item.data.requestResult.push(data); // 更新父节点状态 this.resultEvaluation(data.resourceId, data.success); diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index 19139b669e..a122f1a555 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -466,6 +466,7 @@ export default { this.mergeHashTree(req.hashTree); } this.initDataSource(); + this.forStatus(); this.sort(); this.reload(); } diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue index 4d4130664e..5135cd9548 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue @@ -71,6 +71,7 @@ import MsDubboBasisParameters from "../../../definition/components/request/dubbo import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm"; import ApiBaseComponent from "../common/ApiBaseComponent"; import {getCurrentProjectID, getCurrentWorkspaceId, getUUID, strMapToObj} from "@/common/js/utils"; +import {STEP} from "@/business/components/api/automation/scenario/Setting"; export default { name: "ApiScenarioComponent", @@ -116,6 +117,9 @@ export default { this.scenario.projectId = getCurrentProjectID(); } if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) { + let scenarios = JSON.parse(JSON.stringify(this.scenario.hashTree)); + let map = new Map(); + this.formatResult(map, scenarios); this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => { if (response.data) { this.scenario.loaded = true; @@ -124,6 +128,7 @@ export default { obj = JSON.parse(response.data.scenarioDefinition); this.scenario.hashTree = obj.hashTree; } + this.setResult(this.scenario.hashTree, map); this.scenario.projectId = response.data.projectId; const pro = this.projectList.find(p => p.id === response.data.projectId); if (!pro) { @@ -168,7 +173,8 @@ export default { loading: false, isShowInput: false, isShowNum: false, - isSameSpace: true + isSameSpace: true, + stepFilter: new STEP, } }, computed: { @@ -189,6 +195,31 @@ export default { runScenario.hashTree = [this.scenario]; this.$emit('runScenario', runScenario); }, + formatResult(map, scenarios) { + scenarios.forEach(item => { + if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1 && item.requestResult) { + let key = (item.id ? item.id : item.resourceId) + "_" + item.index; + if (map.has(key)) { + map.get(key).push(... item.requestResult); + } else { + map.set(key, item.requestResult); + } + } + if (item.hashTree && item.hashTree.length > 0) { + this.formatResult(map, item.hashTree); + } + }) + }, + setResult(array, scenarios) { + if (array && scenarios) { + array.forEach(item => { + let key = (item.id ? item.id : item.resourceId) + "_" + item.index; + if (scenarios.has(key)) { + item.requestResult = scenarios.get(key); + } + }) + } + }, stop() { this.scenario.run = false; this.$emit('stopScenario');