From 415900370e6e31800d19011dd4d4c27cb2468f4a Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 8 Feb 2021 11:34:32 +0800 Subject: [PATCH 1/5] =?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=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E8=83=BD=E6=B7=BB=E5=8A=A0=20=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4=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/EditApiScenario.vue | 2 +- .../components/api/definition/components/extract/ApiExtract.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 21ffb284f9..f443d1c6c2 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -503,7 +503,7 @@ this.sort(); }, nodeClick(data, node) { - if (data.referenced != 'REF' && data.referenced != 'Deleted') { + if (data.referenced != 'REF' && data.referenced != 'Deleted' && !data.disabled) { this.operatingElements = ELEMENTS.get(data.type); } else { this.operatingElements = []; diff --git a/frontend/src/business/components/api/definition/components/extract/ApiExtract.vue b/frontend/src/business/components/api/definition/components/extract/ApiExtract.vue index d8637ff3e6..728d9a0ebe 100644 --- a/frontend/src/business/components/api/definition/components/extract/ApiExtract.vue +++ b/frontend/src/business/components/api/definition/components/extract/ApiExtract.vue @@ -26,7 +26,7 @@ - Add + {{$t('commons.add')}} From 5eb34cbae48c1630546abe3a0f8e16fc429c758e Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 8 Feb 2021 14:12:07 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E5=9C=BA=E6=99=AF=E5=8F=98=E9=87=8F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=AF=B7=E6=B1=82=E5=A4=B4=EF=BC=8C=E5=B9=B6=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AF=B7=E6=B1=82=E5=A4=B4=E6=95=B0=E6=8D=AE=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/request/MsScenario.java | 11 +- .../service/HistoricalDataUpgradeService.java | 1 + .../automation/scenario/EditApiScenario.vue | 30 ++- .../scenario/component/ApiComponent.vue | 4 +- .../scenario/component/LoopController.vue | 4 +- .../scenario/variable/VariableList.vue | 189 +++++++++++++----- 6 files changed, 177 insertions(+), 62 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 4e37a95699..3686898bde 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 @@ -49,6 +49,9 @@ public class MsScenario extends MsTestElement { @JSONField(ordinal = 24) private boolean enableCookieShare; + @JSONField(ordinal = 26) + private List headers; + private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; @Override @@ -87,7 +90,7 @@ public class MsScenario extends MsTestElement { } // 场景变量和环境变量 tree.add(arguments(config)); - //this.addCsvDataSet(tree, variables); + this.addCsvDataSet(tree, variables); this.addCounter(tree, variables); this.addRandom(tree, variables); if (CollectionUtils.isNotEmpty(hashTree)) { @@ -131,6 +134,12 @@ public class MsScenario extends MsTestElement { arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") ); } + if (CollectionUtils.isNotEmpty(this.headers)) { + this.headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> + arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") + ); + } + return arguments; } diff --git a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java index 0033018d34..580b8d470f 100644 --- a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java +++ b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java @@ -84,6 +84,7 @@ public class HistoricalDataUpgradeService { scenario.setReferenced("Upgrade"); scenario.setId(oldScenario.getId()); scenario.setResourceId(UUID.randomUUID().toString()); + scenario.setHeaders(oldScenario.getHeaders()); LinkedList testElements = new LinkedList<>(); int index = 1; for (Request request : oldScenario.getRequests()) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index f443d1c6c2..98c9d61247 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -106,7 +106,7 @@ {{$t('api_test.automation.scenario_total')}} - :{{this.currentScenario.variables!=undefined?this.currentScenario.variables.length: 0}} + :{{getVariableSize()}} 共享cookie @@ -427,8 +427,9 @@ getIdx(index) { return index - 0.33 }, - setVariables(v) { + setVariables(v, headers) { this.currentScenario.variables = v; + this.currentScenario.headers = headers; if (this.path.endsWith("/update")) { // 直接更新场景防止编辑内容丢失 this.editScenario(); @@ -679,7 +680,7 @@ this.editScenario(); this.debugData = { id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario", - variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, + variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, headers: this.currentScenario.headers, environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition }; this.reportId = getUUID().substring(0, 8); @@ -863,6 +864,9 @@ if (!this.currentScenario.variables) { this.currentScenario.variables = []; } + if (!this.currentScenario.headers) { + this.currentScenario.headers = []; + } if (this.currentScenario.id) { this.result = this.$get("/api/automation/getApiScenario/" + this.currentScenario.id, response => { if (response.data) { @@ -887,6 +891,9 @@ } }) } + if (obj.headers) { + this.currentScenario.headers = obj.headers; + } this.enableCookieShare = obj.enableCookieShare; this.scenarioDefinition = obj.hashTree; } @@ -905,8 +912,9 @@ this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId); // 构建一个场景对象 方便引用处理 let scenario = { - id: this.currentScenario.id, enableCookieShare: this.enableCookieShare, name: this.currentScenario.name, variables: this.currentScenario.variables, - type: "scenario", referenced: 'Created', environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition + id: this.currentScenario.id, enableCookieShare: this.enableCookieShare, name: this.currentScenario.name, type: "scenario", + variables: this.currentScenario.variables, headers: this.currentScenario.headers, + referenced: 'Created', environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition }; this.currentScenario.scenarioDefinition = scenario; if (this.currentScenario.tags instanceof Array) { @@ -924,7 +932,7 @@ this.loading = false; }, showScenarioParameters() { - this.$refs.scenarioParameters.open(this.currentScenario.variables); + this.$refs.scenarioParameters.open(this.currentScenario.variables, this.currentScenario.headers); }, apiImport(importData) { if (importData && importData.data) { @@ -934,6 +942,16 @@ this.sort(); this.reload(); } + }, + getVariableSize() { + let size = 0; + if (this.currentScenario.variables) { + size += this.currentScenario.variables.length; + } + if (this.currentScenario.headers && this.currentScenario.headers.length > 1) { + size += this.currentScenario.headers.length - 1; + } + return size; } } } 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 6ea4c3543c..625008a29f 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -248,8 +248,8 @@ this.request.customizeReq = this.isCustomizeReq; let debugData = { id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario", - variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, - environmentId: this.currentEnvironmentId, hashTree: [this.request] + variables: this.currentScenario.variables, referenced: 'Created', headers: this.currentScenario.headers, + enableCookieShare: this.enableCookieShare, environmentId: this.currentEnvironmentId, hashTree: [this.request] }; this.runData.push(debugData); /*触发执行操作*/ diff --git a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue index be8df59a1e..4ad787b7af 100644 --- a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue +++ b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue @@ -205,8 +205,8 @@ this.loading = true; this.debugData = { id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario", - variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, - environmentId: this.currentEnvironmentId, hashTree: [this.controller] + variables: this.currentScenario.variables, headers: this.currentScenario.headers, + referenced: 'Created', enableCookieShare: this.enableCookieShare, environmentId: this.currentEnvironmentId, hashTree: [this.controller] }; this.reportId = getUUID().substring(0, 8); }, diff --git a/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue b/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue index 8253a019e0..21026fd8d5 100644 --- a/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue +++ b/frontend/src/business/components/api/automation/scenario/variable/VariableList.vue @@ -1,57 +1,89 @@