From c0660e8827104f613f07f58e9a88eacccfb9c828 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 19 Dec 2024 18:42:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=9C=BA=E6=99=AF=E5=85=A8=E5=B1=80=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【测试跟踪】github#34733,重新导入场景,全局前置脚本不执行】 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001050667 --- .../dto/definition/request/MsScenario.java | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 8d91e360f6..2644d28755 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -166,29 +166,38 @@ public class MsScenario extends MsTestElement { && (this.mixEnable == null || BooleanUtils.isFalse(this.mixEnable)); } - private void setGlobProcessor(ParameterConfig config, HashTree scenarioTree, boolean isPre) { - if (config.getConfig() != null && (this.variableEnable == null || this.variableEnable)) { - config.getConfig().forEach((k, environmentConfig) -> { - if (environmentConfig != null) { - EnvJSR223Processor envProcessor = isPre ? environmentConfig.getPreStepProcessor() : environmentConfig.getPostStepProcessor(); - MsJSR223Processor processor = new MsJSR223Processor(); - if (envProcessor != null) { - BeanUtils.copyBean(processor, envProcessor); - } - if (StringUtils.isNotEmpty(processor.getScript())) { - processor.setType(ElementConstants.JSR223); - processor.setClazzName(MsJSR223Processor.class.getCanonicalName()); - boolean isConnScenarioPre = false; - if (environmentConfig.getGlobalScriptConfig() != null) { - isConnScenarioPre = isPre ? environmentConfig.getGlobalScriptConfig().isConnScenarioPreScript() : - environmentConfig.getGlobalScriptConfig().isConnScenarioPostScript(); - } - String name = isPre ? "PRE_PROCESSOR_ENV_" : "POST_PROCESSOR_ENV_"; - processor.setName(name + isConnScenarioPre); - processor.toHashTree(scenarioTree, processor.getHashTree(), config); - } + private void setConfig(ParameterConfig config, HashTree scenarioTree, boolean isPre) { + config.getConfig().forEach((k, environmentConfig) -> { + if (environmentConfig != null) { + EnvJSR223Processor envProcessor = isPre ? environmentConfig.getPreStepProcessor() : environmentConfig.getPostStepProcessor(); + MsJSR223Processor processor = new MsJSR223Processor(); + if (envProcessor != null) { + BeanUtils.copyBean(processor, envProcessor); } - }); + if (StringUtils.isNotEmpty(processor.getScript())) { + processor.setType(ElementConstants.JSR223); + processor.setClazzName(MsJSR223Processor.class.getCanonicalName()); + boolean isConnScenarioPre = false; + if (environmentConfig.getGlobalScriptConfig() != null) { + isConnScenarioPre = isPre ? environmentConfig.getGlobalScriptConfig().isConnScenarioPreScript() : + environmentConfig.getGlobalScriptConfig().isConnScenarioPostScript(); + } + String name = isPre ? "PRE_PROCESSOR_ENV_" : "POST_PROCESSOR_ENV_"; + processor.setName(name + isConnScenarioPre); + processor.toHashTree(scenarioTree, processor.getHashTree(), config); + } + } + }); + } + + private void setGlobProcessor(ParameterConfig config, HashTree scenarioTree, boolean isPre) { + if (config.getConfig() != null) { + if (StringUtils.equals(this.getId(), config.getScenarioId())) { + setConfig(config, scenarioTree, isPre); + } else if (this.variableEnable == null || this.variableEnable) { + setConfig(config, scenarioTree, isPre); + } + } } @@ -222,7 +231,7 @@ public class MsScenario extends MsTestElement { return false; } - private void setNewConfig( ParameterConfig newConfig) { + private void setNewConfig(ParameterConfig newConfig) { Map envConfig = new HashMap<>(); if (this.isEnvironmentEnable()) { ApiScenarioMapper apiScenarioMapper = CommonBeanFactory.getBean(ApiScenarioMapper.class);