diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiExecuteResourceController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiExecuteResourceController.java index 49906f1e62..fb7a018512 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiExecuteResourceController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiExecuteResourceController.java @@ -41,7 +41,7 @@ public class ApiExecuteResourceController { @GetMapping("script") public String getScript(@RequestParam("reportId") String reportId, @RequestParam("testId") String testId) { String key = apiExecuteService.getScriptRedisKey(reportId, testId); - LogUtils.info("获取执行脚本: ", key); + LogUtils.info("获取执行脚本: {}", key); String script = stringRedisTemplate.opsForValue().get(key); stringRedisTemplate.delete(key); apiReportService.updateReportStatus(reportId, ApiReportStatus.RERUNNING.name()); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/JmeterTestElementParser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/JmeterTestElementParser.java index 7194f7cf55..a84889b6dc 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/JmeterTestElementParser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/JmeterTestElementParser.java @@ -45,12 +45,13 @@ public class JmeterTestElementParser implements TestElementParser { name = msTestElement.getName(); final HashTree testPlanTree = hashTree.add(testPlan); final HashTree groupTree = testPlanTree.add(getThreadGroup()); - // 添加 debugSampler - groupTree.add(getDebugSampler()); // 解析 msTestElement JmeterElementConverterRegister.getConverter(msTestElement.getClass()).toHashTree(groupTree, msTestElement, config); + // 添加 debugSampler,放最后才能采集到变量信息 + groupTree.add(getDebugSampler()); + return getJmx(hashTree); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommentScriptElementConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommentScriptElementConverter.java index 0fac8b5b4f..a4bc015fba 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommentScriptElementConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommentScriptElementConverter.java @@ -53,7 +53,7 @@ public class MsCommentScriptElementConverter extends AbstractJmeterElementConver } else { scriptElement = new BeanShellSampler(); } - ScriptProcessorConverter.parse(scriptElement, scriptProcessor); + ScriptProcessorConverter.parse(scriptElement, scriptProcessor, config); // 添加公共脚本的参数 Optional.ofNullable(ScriptProcessorConverter.getScriptArguments(scriptProcessor)) .ifPresent(hashTree::add); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioScriptProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioScriptProcessorConverter.java index c1340322d9..332fea97f5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioScriptProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScenarioScriptProcessorConverter.java @@ -22,6 +22,7 @@ public class ScenarioScriptProcessorConverter extends ScriptProcessorConverter { if (!needParse(scriptProcessor, config) || !scriptProcessor.isValid()) { return; } + EnvScenarioScriptProcessor scenarioScriptProcessor = (EnvScenarioScriptProcessor) scriptProcessor; Boolean associateScenarioResult = scenarioScriptProcessor.getAssociateScenarioResult(); @@ -32,7 +33,7 @@ public class ScenarioScriptProcessorConverter extends ScriptProcessorConverter { processor = new BeanShellSampler(); } - parse(processor, scriptProcessor); + parse(processor, scriptProcessor, config); // 添加公共脚本的参数 Optional.ofNullable(getScriptArguments(scriptProcessor)) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPostProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPostProcessorConverter.java index 963ee1ed01..efc6b13d9f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPostProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPostProcessorConverter.java @@ -25,7 +25,7 @@ public class ScriptPostProcessorConverter extends ScriptProcessorConverter { } else { processor = new BeanShellPostProcessor(); } - parse(processor, scriptProcessor); + parse(processor, scriptProcessor, config); // 添加公共脚本的参数 Optional.ofNullable(getScriptArguments(scriptProcessor)) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPreProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPreProcessorConverter.java index 60b6425cb8..84e9f1411e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPreProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptPreProcessorConverter.java @@ -25,7 +25,7 @@ public class ScriptPreProcessorConverter extends ScriptProcessorConverter { } else { processor = new BeanShellPreProcessor(); } - parse(processor, scriptProcessor); + parse(processor, scriptProcessor, config); // 添加公共脚本的参数 Optional.ofNullable(getScriptArguments(scriptProcessor)) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java index d566945745..293da3e862 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/ScriptProcessorConverter.java @@ -1,13 +1,16 @@ package io.metersphere.api.parser.jmeter.processor; +import io.metersphere.api.dto.ApiParamConfig; import io.metersphere.api.parser.jmeter.JmeterTestElementParserHelper; import io.metersphere.api.parser.jmeter.constants.JmeterAlias; import io.metersphere.api.parser.jmeter.constants.JmeterProperty; import io.metersphere.plugin.api.constants.ElementProperty; +import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.project.api.KeyValueParam; import io.metersphere.project.api.processor.ScriptProcessor; import io.metersphere.project.constants.ScriptLanguageType; import io.metersphere.project.dto.CommonScriptInfo; +import io.metersphere.project.dto.environment.EnvironmentInfoDTO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -27,7 +30,7 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter { if (needParse(variableAssertionItem, config)) { - JSR223Assertion jsr223Assertion = parse2JSR233Assertion(variableAssertionItem); + JSR223Assertion jsr223Assertion = parse2JSR233Assertion(variableAssertionItem, config); jsr223Assertion.setEnabled(variableAssertionItem.getEnable()); if (BooleanUtils.isFalse(globalEnable)) { // 如果整体禁用,则禁用 @@ -45,7 +45,7 @@ public class VariableAssertionConverter extends AssertionConverter