diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 45e177624d..91178520bb 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -42,7 +42,6 @@ public class JMeterService { Object scriptWrapper = SaveService.loadElement(is); HashTree testPlan = getHashTree(scriptWrapper); addBackendListener(testId, debugReportId, testPlan); - LocalRunner runner = new LocalRunner(testPlan); runner.run(); } catch (Exception e) { diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java index 380fd0078f..8839acf52d 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java @@ -2,14 +2,24 @@ package io.metersphere.api.jmeter; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads.JMeterVariables; +import org.springframework.util.StringUtils; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; public class JMeterVars { public static Map variables = new HashMap<>(); - public static void addVars(String testId, JMeterVariables vars) { - variables.put(testId, vars); + public static void addVars(String testId, JMeterVariables vars, String extract) { + JMeterVariables vs = new JMeterVariables(); + if (!StringUtils.isEmpty(extract) && vars != null) { + List extracts = Arrays.asList(extract.split(";")); + extracts.forEach(item -> { + vs.put(item, vars.get(item)); + }); + } + variables.put(testId, vs); } } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index cf6b065263..c2dacf960c 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit cf6b06526324326a563d933e07118fac014a63b4 +Subproject commit c2dacf960cdb1ed35664bdd3432120b1203b73d8 diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 4c247d0874..23f25856e9 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -1208,6 +1208,25 @@ class JMXGenerator { sampler.put(new JSR223PreProcessor(name, request.jsr223PreProcessor)); } if (request.jsr223PostProcessor && request.jsr223PostProcessor.script) { + // 增加一段后置脚步,获取 提取变量的内容 + let vars = []; + if (request.extract.regex) { + for (let i = 0; i < request.extract.regex.length; i++) { + vars.push(request.extract.regex[i].variable); + } + } + if (request.extract.json) { + for (let i = 0; i < request.extract.json.length; i++) { + vars.push(request.extract.json[i].variable); + } + } + if (request.extract.xpath) { + for (let i = 0; i < request.extract.xpath.length; i++) { + vars.push(request.extract.xpath[i].variable); + } + } + request.jsr223PostProcessor.script += "\n" + "io.metersphere.api.jmeter.JMeterVars.addVars(org.apache.jmeter.threads.JMeterContextService.getContext().getThread().getThreadName(),vars," + "\"" + vars.join(";") + "\"" + ");" + sampler.put(new JSR223PostProcessor(name, request.jsr223PostProcessor)); } }