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 29c5f4e64c..2ba6e2a1ab 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 @@ -145,7 +145,9 @@ public class MsScenario extends MsTestElement { Arguments valueSupposeMock = ParameterConfig.valueSupposeMock(arguments); // 这里加入自定义变量解决ForEach循环控制器取值问题,循环控制器无法从vars中取值 scenarioTree.add(valueSupposeMock); - scenarioTree.add(ElementUtil.argumentsToProcessor(valueSupposeMock)); + if (this.variableEnable != null && this.variableEnable) { + scenarioTree.add(ElementUtil.argumentsToProcessor(valueSupposeMock)); + } } if (this.variableEnable == null || this.variableEnable) { ElementUtil.addCsvDataSet(scenarioTree, variables, this.isEnvironmentEnable() ? newConfig : config, "shareMode.group"); @@ -245,13 +247,17 @@ public class MsScenario extends MsTestElement { ApiScenarioMapper apiScenarioMapper = CommonBeanFactory.getBean(ApiScenarioMapper.class); EnvironmentGroupProjectService environmentGroupProjectService = CommonBeanFactory.getBean(EnvironmentGroupProjectService.class); ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(this.getId()); - String environmentType = scenario.getEnvironmentType(); - String environmentJson = scenario.getEnvironmentJson(); - String environmentGroupId = scenario.getEnvironmentGroupId(); - if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) { - this.environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId); - } else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) { - this.environmentMap = JSON.parseObject(environmentJson, Map.class); + if (scenario != null) { + String environmentType = scenario.getEnvironmentType(); + String environmentJson = scenario.getEnvironmentJson(); + String environmentGroupId = scenario.getEnvironmentGroupId(); + if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) { + this.environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId); + } else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) { + this.environmentMap = JSON.parseObject(environmentJson, Map.class); + } + } else { + this.setEnvironmentEnable(false); } if (this.environmentMap != null && !this.environmentMap.isEmpty()) { @@ -301,6 +307,15 @@ public class MsScenario extends MsTestElement { arguments.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments"); arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName()); arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel")); + // 环境通用变量 + if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null + && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { + config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> + arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") + ); + // 清空变量,防止重复添加 + config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().clear(); + } if (CollectionUtils.isNotEmpty(this.getVariables())) { this.getVariables().stream().filter(ScenarioVariable::isConstantValid).forEach(keyValue -> arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") @@ -314,15 +329,6 @@ public class MsScenario extends MsTestElement { } }); } - // 环境通用变量 - if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null - && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { - config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> - arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") - ); - // 清空变量,防止重复添加 - config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().clear(); - } if (arguments.getArguments() != null && arguments.getArguments().size() > 0) { return arguments; } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/loop/CountController.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/loop/CountController.java index c55db9540d..20780ce295 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/loop/CountController.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/loop/CountController.java @@ -5,7 +5,7 @@ import lombok.Data; @Data public class CountController { private int loops; - private int interval; + private long interval; private boolean proceed; private Object requestResult; 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 a48936b2b4..6ba0ccefdc 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 @@ -475,7 +475,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (StringUtils.isNotEmpty(this.getPort()) && this.getPort().startsWith("${")) { url = url.replace(this.getPort(), "10990"); } - if (url == null) { + if (StringUtils.isEmpty(url)) { MSException.throwException("请重新选择环境"); } URL urlObject = new URL(url); diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 5166af453d..0e0865450a 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -322,6 +322,7 @@ public class ApiScenarioExecuteService { hashTree = request.getTestElement().generateHashTree(config); LogUtil.info(request.getTestElement().getJmx(hashTree)); } catch (Exception e) { + LoggerUtil.error(e); MSException.throwException(e.getMessage()); } if (request.isSaved()) { diff --git a/frontend/src/business/components/api/automation/report/ApiReportDetail.vue b/frontend/src/business/components/api/automation/report/ApiReportDetail.vue index 58e8a7eca2..f0c24735fb 100644 --- a/frontend/src/business/components/api/automation/report/ApiReportDetail.vue +++ b/frontend/src/business/components/api/automation/report/ApiReportDetail.vue @@ -462,22 +462,24 @@ export default { }, handleExport() { if (this.report.reportVersion && this.report.reportVersion > 1) { - if(this.report.reportType === 'API_INTEGRATED'){ + if (this.report.reportType === 'API_INTEGRATED') { let scenario = {name: "", requestResults: []}; this.content.scenarios = [scenario]; this.formatExportApi(this.fullTreeNodes, scenario); - }else { - this.fullTreeNodes.forEach(item => { - if (item.type === "scenario") { - let scenario = {name: item.label, requestResults: []}; - if (this.content.scenarios && this.content.scenarios.length > 0) { - this.content.scenarios.push(scenario); - } else { - this.content.scenarios = [scenario]; + } else { + if (this.fullTreeNodes) { + this.fullTreeNodes.forEach(item => { + if (item.type === "scenario") { + let scenario = {name: item.label, requestResults: []}; + if (this.content.scenarios && this.content.scenarios.length > 0) { + this.content.scenarios.push(scenario); + } else { + this.content.scenarios = [scenario]; + } + this.formatExportApi(item.children, scenario); } - this.formatExportApi(item.children, scenario); - } - }) + }) + } } } this.reportExportVisible = true; diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 2004fc431c..49376e6181 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -362,7 +362,7 @@ :old-on-sample-error="onSampleError" :new-on-sample-error="newOnSampleError" :project-list="projectList" - :type ="type" + :type="type" > @@ -522,10 +522,10 @@ export default { executeType: "", versionData: [], newData: [], - oldData:[], + oldData: [], dialogVisible: false, newScenarioDefinition: [], - oldScenarioDefinition:[], + oldScenarioDefinition: [], currentItem: {}, pluginDelStep: false } @@ -1109,6 +1109,7 @@ export default { } this.resetResourceId(item.hashTree); item.enable === undefined ? item.enable = true : item.enable; + item.variableEnable = item.variableEnable === undefined ? true : item.variableEnable; if (this.selectedTreeNode !== undefined) { this.selectedTreeNode.hashTree.push(item); } else { @@ -1420,12 +1421,12 @@ export default { getApiScenario() { this.loading = true; this.stepEnable = true; - if (this.currentScenario.tags !== undefined && this.currentScenario.tags ) { - if(!(this.currentScenario.tags instanceof Array)){ + if (this.currentScenario.tags !== undefined && this.currentScenario.tags) { + if (!(this.currentScenario.tags instanceof Array)) { this.currentScenario.tags = JSON.parse(this.currentScenario.tags); } - }else{ - this.$set(this.currentScenario,'tags',[]) + } else { + this.$set(this.currentScenario, 'tags', []) } if (!this.currentScenario.variables) { this.currentScenario.variables = []; @@ -1766,64 +1767,64 @@ export default { }); }, compare(row) { - this.$get('/api/automation/get/' + row.id+"/"+this.currentScenario.refId, response => { - this.$get("/api/automation/getApiScenario/" + response.data.id, res => { - if (res.data) { - if(res.data.scenarioDefinition != null){ - let obj = JSON.parse(res.data.scenarioDefinition); - if(obj){ - if(obj.hashTree){ - for (let i = 0; i < obj.hashTree.length; i++) { - if(!obj.hashTree[i].index){ - obj.hashTree[i].index = i+1; - } - obj.hashTree[i].disabled = true; - if (!obj.hashTree[i].requestResult) { - obj.hashTree[i].requestResult = [{responseResult: {}}]; - } + this.$get('/api/automation/get/' + row.id + "/" + this.currentScenario.refId, response => { + this.$get("/api/automation/getApiScenario/" + response.data.id, res => { + if (res.data) { + if (res.data.scenarioDefinition != null) { + let obj = JSON.parse(res.data.scenarioDefinition); + if (obj) { + if (obj.hashTree) { + for (let i = 0; i < obj.hashTree.length; i++) { + if (!obj.hashTree[i].index) { + obj.hashTree[i].index = i + 1; } - this.newEnableCookieShare = obj.enableCookieShare; - if (obj.onSampleError === undefined) { - this.newOnSampleError = true; - } else { - this.newOnSampleError = obj.onSampleError; + obj.hashTree[i].disabled = true; + if (!obj.hashTree[i].requestResult) { + obj.hashTree[i].requestResult = [{responseResult: {}}]; } } - this.dataProcessing(obj.hashTree); - this.newScenarioDefinition = obj.hashTree; - for (let i = 0; i < this.oldScenarioDefinition.length; i++) { - this.oldScenarioDefinition[i].disabled = true; - } - if (response.data.environmentJson) { - this.newProjectEnvMap = objToStrMap(JSON.parse(response.data.environmentJson)); + this.newEnableCookieShare = obj.enableCookieShare; + if (obj.onSampleError === undefined) { + this.newOnSampleError = true; } else { - // 兼容历史数据 - this.newProjectEnvMap.set(this.projectId, obj.environmentId); + this.newOnSampleError = obj.onSampleError; } } + this.dataProcessing(obj.hashTree); + this.newScenarioDefinition = obj.hashTree; + for (let i = 0; i < this.oldScenarioDefinition.length; i++) { + this.oldScenarioDefinition[i].disabled = true; + } + if (response.data.environmentJson) { + this.newProjectEnvMap = objToStrMap(JSON.parse(response.data.environmentJson)); + } else { + // 兼容历史数据 + this.newProjectEnvMap.set(this.projectId, obj.environmentId); + } } - res.data.userName = response.data.userName - this.dealWithTag(res.data); - this.oldData = this.currentScenario; - this.newData = res.data; - this.closeExpansion() } - this.sort(); - this.dialogVisible = true; - }); + res.data.userName = response.data.userName + this.dealWithTag(res.data); + this.oldData = this.currentScenario; + this.newData = res.data; + this.closeExpansion() + } + this.sort(); + this.dialogVisible = true; + }); }) }, - closeDiff(){ + closeDiff() { this.oldScenarioDefinition = [] }, - dealWithTag(newScenario){ - if(newScenario.tags){ - if(Object.prototype.toString.call(newScenario.tags)==="[object String]"){ + dealWithTag(newScenario) { + if (newScenario.tags) { + if (Object.prototype.toString.call(newScenario.tags) === "[object String]") { newScenario.tags = JSON.parse(newScenario.tags); } } - if(this.currentScenario.tags){ - if(Object.prototype.toString.call(this.currentScenario.tags)==="[object String]"){ + if (this.currentScenario.tags) { + if (Object.prototype.toString.call(this.currentScenario.tags) === "[object String]") { this.currentScenario.tags = JSON.parse(this.currentScenario.tags); } } 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 3e55fc46fe..0843eb1eff 100644 --- a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue +++ b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue @@ -22,7 +22,7 @@ {{ $t('loop.loops') }} - + diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index a1d6f51133..4f98351499 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -229,7 +229,7 @@ export default { edit_info: "编辑详情", enable_scene: "原场景环境", variable_scene: "原场景变量", - reference_settings: "引用设置", + reference_settings: "场景设置", enable_scene_info: "启用场景环境:当前步骤使用场景原始环境配置运行", environment: "运行环境", run_success: "执行成功", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 9c538f00de..3ee6b88e8b 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -229,7 +229,7 @@ export default { edit_info: "編輯詳情", enable_scene: "原場景環境", variable_scene: "原場景变量", - reference_settings: "引用设置", + reference_settings: "场景设置", enable_scene_info: "啟用場景環境:當前步驟使用場景原始環境配置運行", environment: "運行環境", run_success: "執行成功",