From dc6a960dacb68257bf242c39cae08b63bcab814f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Dec 2020 18:27:14 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E8=AF=B7=E6=B1=82=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/definition/request/MsScenario.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index b70b2f703a..b28ae07451 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -83,9 +83,7 @@ public class MsScenario extends MsTestElement { } } // 场景变量 - if (CollectionUtils.isNotEmpty(this.getVariables())) { - tree.add(arguments(config)); - } + tree.add(arguments(config)); if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { @@ -101,9 +99,11 @@ public class MsScenario extends MsTestElement { arguments.setName(name + "Variables"); arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName()); arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel")); - variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> - arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") - ); + if (CollectionUtils.isNotEmpty(this.getVariables())) { + variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> + arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") + ); + } if (config != null && config.getConfig() != null && config.getConfig().getCommonConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().getCommonConfig().getVariables())) { config.getConfig().getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> From 2ec31650d028e4e1af9becf6eb85e5816ff57e8d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Dec 2020 18:43:31 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E9=80=89=E6=8B=A9=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/api/dto/definition/request/MsScenario.java | 1 - .../components/api/automation/scenario/EditApiScenario.vue | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index b28ae07451..7e2a886767 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -84,7 +84,6 @@ public class MsScenario extends MsTestElement { } // 场景变量 tree.add(arguments(config)); - if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { el.toHashTree(tree, el.getHashTree(), config); diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 9afb060e2e..84a4b5a36d 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -452,7 +452,7 @@ }, outsideClick(e) { e.stopPropagation() - this.operatingElements = ELEMENTS.get("ALL"); + this.showAll(); }, addComponent(type) { switch (type) { @@ -594,7 +594,7 @@ } } , - pushApiOrCase(data, refType, referenced) { + pushApiOrCase(data, refType, referenced) { data.forEach(item => { this.setApiParameter(item, refType, referenced); }); @@ -885,6 +885,7 @@ height: calc(100vh - 196px); overflow-y: auto; } + .ms-scenario-input { width: 100%; } From f9d3e9be95bfc893bd27aabd094842c8ead77358 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Dec 2020 18:51:52 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E5=BC=95=E7=94=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/api/automation/scenario/ApiComponent.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue index 70acb87907..61704533c9 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue @@ -127,10 +127,12 @@ if (this.request.id && this.request.referenced === 'REF') { let requestResult = this.request.requestResult; let url = this.request.refType && this.request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/"; + let enable = this.request.enable; this.$get(url + this.request.id, response => { if (response.data) { Object.assign(this.request, JSON.parse(response.data.request)); this.request.name = response.data.name; + this.request.enable = enable; if (response.data.path && response.data.path != null) { this.request.path = response.data.path; this.request.url = response.data.path; From 8d378c163d2aac8185d158e8bb28fb18e002c2ba Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Dec 2020 19:01:44 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 44 +++++++++---------- .../automation/scenario/ApiScenarioList.vue | 5 +-- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 2f620e1825..0bee475a12 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -24,6 +24,7 @@ import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.DateUtils; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.i18n.Translator; @@ -260,14 +261,14 @@ public class ApiAutomationService { return new ArrayList<>(); } - private void createAPIScenarioReportResult(String id, String scenarioId, String scenarioName, String triggerMode, String execType, String projectId, String userID) { + private void createScenarioReport(String id, String scenarioId, String scenarioName, String triggerMode, String execType, String projectId, String userID) { APIScenarioReportResult report = new APIScenarioReportResult(); report.setId(id); report.setTestId(id); if (StringUtils.isNotEmpty(scenarioName)) { report.setName(scenarioName); } else { - report.setName("零时调试名称"); + report.setName("场景调试"); } report.setCreateTime(System.currentTimeMillis()); report.setUpdateTime(System.currentTimeMillis()); @@ -295,25 +296,21 @@ public class ApiAutomationService { List apiScenarios = extApiScenarioMapper.selectIds(request.getScenarioIds()); MsTestPlan testPlan = new MsTestPlan(); testPlan.setHashTree(new LinkedList<>()); - HashTree jmeterTestPlanHashTree = new ListedHashTree(); - String projectID = request.getProjectId(); - boolean isOne = true; - for (ApiScenarioWithBLOBs item : apiScenarios) { - MsThreadGroup group = new MsThreadGroup(); - group.setLabel(item.getName()); - // 批量执行的结果直接存储为报告 - if (isOne) { - group.setName(request.getId()); - isOne = false; - } else { + HashTree jmeterHashTree = new ListedHashTree(); + try { + for (ApiScenarioWithBLOBs item : apiScenarios) { + MsThreadGroup group = new MsThreadGroup(); + group.setLabel(item.getName()); group.setName(UUID.randomUUID().toString()); - } - projectID = item.getProjectId(); - try { + // 批量执行的结果直接存储为报告 + if (apiScenarios.size() == 1) { + group.setName(request.getId()); + } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JSONObject element = JSON.parseObject(item.getScenarioDefinition()); MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class); + // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { LinkedList elements = mapper.readValue(element.getString("hashTree"), @@ -331,22 +328,23 @@ public class ApiAutomationService { LinkedList scenarios = new LinkedList<>(); scenarios.add(scenario); // 创建场景报告 - createAPIScenarioReportResult(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), - request.getExecuteType(), projectID, request.getReportUserID()); + createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), + request.getExecuteType(), item.getProjectId(), request.getReportUserID()); group.setHashTree(scenarios); testPlan.getHashTree().add(group); - } catch (Exception ex) { - ex.printStackTrace(); + } + } catch (Exception ex) { + LogUtil.error(ex.getMessage()); } - testPlan.toHashTree(jmeterTestPlanHashTree, testPlan.getHashTree(), new ParameterConfig()); + testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig()); String runMode = ApiRunMode.SCENARIO.name(); if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name())) { runMode = ApiRunMode.SCENARIO_PLAN.name(); } // 调用执行方法 - jMeterService.runDefinition(request.getId(), jmeterTestPlanHashTree, request.getReportId(), runMode); + jMeterService.runDefinition(request.getId(), jmeterHashTree, request.getReportId(), runMode); return request.getId(); } @@ -371,7 +369,7 @@ public class ApiAutomationService { HashTree hashTree = request.getTestElement().generateHashTree(config); // 调用执行方法 jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), ApiRunMode.SCENARIO.name()); - createAPIScenarioReportResult(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), + createScenarioReport(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), SessionUtils.getUserId()); return request.getId(); } diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index f8b2f0ca09..2724ac76d3 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -111,7 +111,6 @@ condition: {}, currentScenario: {}, schedule: {}, - selectAll: false, selection: [], tableData: [], currentPage: 1, @@ -120,6 +119,7 @@ reportId: "", batchReportId: "", content: {}, + selectAll: false, infoDb: false, runVisible: false, planVisible: false, @@ -246,9 +246,6 @@ this.batchReportId = run.id; }); }, - selectAllChange() { - this.handleCommand("table"); - }, select(selection) { this.selection = selection.map(s => s.id); this.$emit('selection', selection);