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 21ffb284f9..cfc4671a5e 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 @@ -196,7 +196,7 @@ - + @@ -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(); @@ -503,7 +504,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 = []; @@ -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; } } } @@ -1066,4 +1084,7 @@ content: "\e722"; font-size: 20px; } + .ms-sc-variable-header >>> .el-dialog__body { + padding: 0px 20px; + } 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..4976588862 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,88 @@