fix(接口测试): 支持Dubbo协议和sql 提取值
This commit is contained in:
parent
1fa53170cc
commit
6336d33330
|
@ -1,10 +1,12 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
|
||||
import org.apache.jmeter.extractor.JSR223PostProcessor;
|
||||
import org.apache.jmeter.extractor.RegexExtractor;
|
||||
import org.apache.jmeter.extractor.XPath2Extractor;
|
||||
import org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor;
|
||||
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
|
||||
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
|
||||
import org.apache.jmeter.threads.JMeterVariables;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
@ -22,6 +24,7 @@ public class JMeterVars {
|
|||
// 线程执行过程调用提取变量值
|
||||
public static void addVars(Integer testId, JMeterVariables vars, String extract) {
|
||||
JMeterVariables vs = new JMeterVariables();
|
||||
|
||||
if (!StringUtils.isEmpty(extract) && vars != null) {
|
||||
List<String> extracts = Arrays.asList(extract.split(";"));
|
||||
Optional.ofNullable(extracts).orElse(new ArrayList<>()).forEach(item -> {
|
||||
|
@ -29,14 +32,15 @@ public class JMeterVars {
|
|||
});
|
||||
vs.remove("TESTSTART.MS"); // 标示变量移除
|
||||
}
|
||||
|
||||
variables.put(testId, vs);
|
||||
}
|
||||
|
||||
// 递归处理所有请求,对有提取变量的增加后置脚本
|
||||
// 处理所有请求,有提取变量的请求增加后置脚本提取变量值
|
||||
public static void addJSR223PostProcessor(HashTree tree) {
|
||||
for (Object key : tree.keySet()) {
|
||||
HashTree node = tree.get(key);
|
||||
if (key instanceof HTTPSamplerProxy) {
|
||||
if (key instanceof HTTPSamplerProxy || key instanceof DubboSample || key instanceof JDBCSampler) {
|
||||
StringJoiner extract = new StringJoiner(";");
|
||||
for (Object child : node.keySet()) {
|
||||
if (child instanceof RegexExtractor) {
|
||||
|
@ -50,6 +54,7 @@ public class JMeterVars {
|
|||
extract.add(regexExtractor.getRefNames());
|
||||
}
|
||||
}
|
||||
|
||||
if (Optional.ofNullable(extract).orElse(extract).length() > 0) {
|
||||
JSR223PostProcessor shell = new JSR223PostProcessor();
|
||||
shell.setEnabled(true);
|
||||
|
@ -57,6 +62,7 @@ public class JMeterVars {
|
|||
node.add(shell);
|
||||
}
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
addJSR223PostProcessor(node);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue