From 3dfd699e0d7e1ffe84f0798b895ddb4f765fcc1e Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 23 Sep 2024 10:23:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=89=8D=E5=90=8E=E7=BD=AE=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046165 --user=赵勇 【接口测试】github#32999,复制的场景用例在复制的环境下执行时,变量 __metersphere_env_id 取到的环境ID不正确 https://www.tapd.cn/55049933/s/1583241 Signed-off-by: fit2-zhao --- .../request/processors/post/MsJSR223PostProcessor.java | 5 ++++- .../request/processors/pre/MsJSR223PreProcessor.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java index 7fbc96a05b..5a31690d1f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java @@ -47,7 +47,10 @@ public class MsJSR223PostProcessor extends MsTestElement { return; } } - + // 复制脚本环境ID未改变情况下,使用父级环境ID + if (this.getParent() != null && !StringUtils.equals(this.getParent().getEnvironmentId(), this.getEnvironmentId())) { + this.setEnvironmentId(this.getParent().getEnvironmentId()); + } this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config, this.getProjectId())); TestElement processor = new BeanShellPostProcessor(); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java index 237d1dd770..25cc313990 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java @@ -48,6 +48,10 @@ public class MsJSR223PreProcessor extends MsTestElement { } } ScriptFilter.verify(this.getScriptLanguage(), this.getName(), script); + // 复制脚本环境ID未改变情况下,使用父级环境ID + if (this.getParent() != null && !StringUtils.equals(this.getParent().getEnvironmentId(), this.getEnvironmentId())) { + this.setEnvironmentId(this.getParent().getEnvironmentId()); + } this.setEnvironmentId(ElementUtil.getScriptEnv(this.getEnvironmentId(), config, this.getProjectId())); final HashTree jsr223PreTree = tree.add(getShellProcessor());