From 8f2c189efe6742bb768f146c3100eeeb61a1d65e Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 11 Jul 2023 20:12:06 +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=8Dbeanshell=E6=96=AD=E8=A8=80=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1027705 --user=王孝刚 【接口测试】github#25504,beanshell 脚本断言,在不勾选 JSR223 时,断言结果恒为真 https://www.tapd.cn/55049933/s/1391820 --- .../definition/request/assertions/MsAssertions.java | 13 ++++++++----- .../exec/scenario/ApiScenarioExecuteService.java | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java index 4941a65a89..ded2e53374 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java @@ -192,18 +192,15 @@ public class MsAssertions extends MsTestElement { } private TestElement jsr223Assertion(MsAssertionJSR223 assertionJSR223) { - TestElement assertion = new BeanShellAssertion(); - if (assertionJSR223.getJsrEnable() == null || BooleanUtils.isTrue(assertionJSR223.getJsrEnable())) { - assertion = new JSR223Assertion(); - } + TestElement assertion = new JSR223Assertion(); assertion.setEnabled(this.isEnable()); if (StringUtils.isNotEmpty(assertionJSR223.getDesc())) { assertion.setName("JSR223" + delimiter + this.getName() + delimiter + assertionJSR223.getDesc() + delimiterScript + assertionJSR223.getScript()); } else { assertion.setName("JSR223" + delimiter + this.getName() + delimiter + "JSR223Assertion" + delimiterScript + assertionJSR223.getScript()); } - assertion.setProperty(TestElement.TEST_CLASS, JSR223Assertion.class.getName()); assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); + assertion.setProperty(TestElement.TEST_CLASS, JSR223Assertion.class.getName()); assertion.setProperty("cacheKey", "false"); String scriptLanguage = assertionJSR223.getScriptLanguage(); if (StringUtils.equals(scriptLanguage, "nashornScript")) { @@ -215,6 +212,12 @@ public class MsAssertions extends MsTestElement { if (StringUtils.equals(scriptLanguage, "javascript")) { scriptLanguage = "rhino"; } + if (StringUtils.equals(scriptLanguage, "beanshell") && BooleanUtils.isFalse(assertionJSR223.getJsrEnable())) { + assertion = new BeanShellAssertion(); + scriptLanguage = "beanshell"; + assertion.setProperty(TestElement.TEST_CLASS, BeanShellAssertion.class.getName()); + assertion.setProperty(BeanShellAssertion.SCRIPT, assertionJSR223.getScript()); + } assertion.setProperty("scriptLanguage", scriptLanguage); assertion.setProperty(ElementConstants.SCRIPT, assertionJSR223.getScript()); return assertion; diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 8c9832f910..56ab4253d0 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -482,6 +482,10 @@ public class ApiScenarioExecuteService { if (testElement != null) { apiScenario.setName(testElement.getName()); apiScenario.setScenarioDefinition(JSON.toJSONString(testElement)); + List projectIdLists = getProjectIds(apiScenario.getScenarioDefinition()); + Map envMap = getProjectEnvMap(projectIdLists, request.getEnvironmentMap()); + request.getConfig().setEnvMap(envMap); + report.setEnvConfig(JSON.toJSONString(request.getConfig())); apiScenarioReportStructureService.save(apiScenario, report.getId(), request.getConfig().getReportType()); } }