fix(接口测试): 脚本断言不生效

This commit is contained in:
AgAngle 2024-03-28 15:05:02 +08:00 committed by Craftsman
parent 289b1471ec
commit 9c8a7ff16e
3 changed files with 14 additions and 1 deletions

View File

@ -21,4 +21,5 @@ public class JmeterAlias {
public static final String HEADER_PANEL = "HeaderPanel";
public static final String AUTH_PANEL = "AuthPanel";
public static final String ARGUMENTS_PANEL = "ArgumentsPanel";
public static final String BEAN_SHELL_ASSERTION_GUI = "BeanShellAssertionGui";
}

View File

@ -9,4 +9,5 @@ public class JmeterProperty {
public static final String CACHE_KEY = "cacheKey";
public static final String SCRIPT_LANGUAGE = "scriptLanguage";
public final static String ASS_OPTION = "ASS_OPTION";
public final static String BEAN_SHELL_ASSERTION_QUERY = "BeanShellAssertion.query";
}

View File

@ -1,5 +1,7 @@
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.plugin.api.dto.ParameterConfig;
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.jmeter.assertions.BeanShellAssertion;
import org.apache.jmeter.assertions.JSR223Assertion;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
@ -25,13 +28,21 @@ public class ScriptAssertionConverter extends AssertionConverter<MsScriptAsserti
return;
}
TestElement assertion = new JSR223Assertion();
TestElement assertion;
if (isJSR233(msAssertion)) {
assertion = new JSR223Assertion();
} else {
assertion = new BeanShellAssertion();
}
ScriptProcessor scriptProcessor = BeanUtils.copyBean(new ScriptProcessor(), msAssertion);
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))
.ifPresent(hashTree::add);