fix(接口测试): 脚本断言不生效
This commit is contained in:
parent
289b1471ec
commit
9c8a7ff16e
|
@ -21,4 +21,5 @@ public class JmeterAlias {
|
||||||
public static final String HEADER_PANEL = "HeaderPanel";
|
public static final String HEADER_PANEL = "HeaderPanel";
|
||||||
public static final String AUTH_PANEL = "AuthPanel";
|
public static final String AUTH_PANEL = "AuthPanel";
|
||||||
public static final String ARGUMENTS_PANEL = "ArgumentsPanel";
|
public static final String ARGUMENTS_PANEL = "ArgumentsPanel";
|
||||||
|
public static final String BEAN_SHELL_ASSERTION_GUI = "BeanShellAssertionGui";
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,5 @@ public class JmeterProperty {
|
||||||
public static final String CACHE_KEY = "cacheKey";
|
public static final String CACHE_KEY = "cacheKey";
|
||||||
public static final String SCRIPT_LANGUAGE = "scriptLanguage";
|
public static final String SCRIPT_LANGUAGE = "scriptLanguage";
|
||||||
public final static String ASS_OPTION = "ASS_OPTION";
|
public final static String ASS_OPTION = "ASS_OPTION";
|
||||||
|
public final static String BEAN_SHELL_ASSERTION_QUERY = "BeanShellAssertion.query";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package io.metersphere.api.parser.jmeter.processor.assertion;
|
package io.metersphere.api.parser.jmeter.processor.assertion;
|
||||||
|
|
||||||
|
import io.metersphere.api.parser.jmeter.constants.JmeterAlias;
|
||||||
|
import io.metersphere.api.parser.jmeter.constants.JmeterProperty;
|
||||||
import io.metersphere.api.parser.jmeter.processor.ScriptProcessorConverter;
|
import io.metersphere.api.parser.jmeter.processor.ScriptProcessorConverter;
|
||||||
import io.metersphere.plugin.api.dto.ParameterConfig;
|
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||||
import io.metersphere.project.api.assertion.MsScriptAssertion;
|
import io.metersphere.project.api.assertion.MsScriptAssertion;
|
||||||
|
@ -9,6 +11,7 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.assertions.BeanShellAssertion;
|
import org.apache.jmeter.assertions.BeanShellAssertion;
|
||||||
import org.apache.jmeter.assertions.JSR223Assertion;
|
import org.apache.jmeter.assertions.JSR223Assertion;
|
||||||
|
import org.apache.jmeter.save.SaveService;
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
|
@ -25,13 +28,21 @@ public class ScriptAssertionConverter extends AssertionConverter<MsScriptAsserti
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestElement assertion = new JSR223Assertion();
|
TestElement assertion;
|
||||||
if (isJSR233(msAssertion)) {
|
if (isJSR233(msAssertion)) {
|
||||||
|
assertion = new JSR223Assertion();
|
||||||
|
} else {
|
||||||
assertion = new BeanShellAssertion();
|
assertion = new BeanShellAssertion();
|
||||||
}
|
}
|
||||||
ScriptProcessor scriptProcessor = BeanUtils.copyBean(new ScriptProcessor(), msAssertion);
|
ScriptProcessor scriptProcessor = BeanUtils.copyBean(new ScriptProcessor(), msAssertion);
|
||||||
ScriptProcessorConverter.parse(assertion, scriptProcessor, config);
|
ScriptProcessorConverter.parse(assertion, scriptProcessor, config);
|
||||||
|
|
||||||
|
if (!isJSR233(msAssertion)) {
|
||||||
|
// beanshell 断言参数名有区别,替换一下
|
||||||
|
assertion.setProperty(JmeterProperty.BEAN_SHELL_ASSERTION_QUERY, assertion.getProperty(JmeterProperty.SCRIPT).getStringValue());
|
||||||
|
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.BEAN_SHELL_ASSERTION_GUI));
|
||||||
|
}
|
||||||
|
|
||||||
// 添加公共脚本的参数
|
// 添加公共脚本的参数
|
||||||
Optional.ofNullable(ScriptProcessorConverter.getScriptArguments(scriptProcessor))
|
Optional.ofNullable(ScriptProcessorConverter.getScriptArguments(scriptProcessor))
|
||||||
.ifPresent(hashTree::add);
|
.ifPresent(hashTree::add);
|
||||||
|
|
Loading…
Reference in New Issue