fix(接口测试): 引用的公共脚本,无法设置环境变量

--bug=1045905 --user=陈建星 【接口测试】github#32861,公共脚本处设置环境参数,在用例前置里引用报错。 https://www.tapd.cn/55049933/s/1578918
This commit is contained in:
AgAngle 2024-09-14 15:47:38 +08:00 committed by jianxing
parent bfaa4994d8
commit a885cbefd5
1 changed files with 11 additions and 10 deletions

View File

@ -38,16 +38,6 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
String name = StringUtils.isEmpty(scriptProcessor.getName()) ? scriptProcessor.getClass().getSimpleName() : scriptProcessor.getName();
testElement.setName(name);
// 设置环境变量
ApiParamConfig apiParamConfig = (ApiParamConfig) config;
EnvironmentInfoDTO envConfig = apiParamConfig.getEnvConfig(scriptProcessor.getProjectId());
if (envConfig != null) {
String envId = envConfig.getId();
if (StringUtils.isNotEmpty(scriptProcessor.getScript())) {
scriptProcessor.setScript(StringUtils.replace(scriptProcessor.getScript(), ENV_VARIABLE_EXPRESSION, "\"" + MS_RUNNING_ENV_PREFIX + envId + ".\""));
}
}
// python js cache 打开
boolean cacheKey = StringUtils.equalsAny(scriptProcessor.getScriptLanguage(), ScriptLanguageType.PYTHON.name(), ScriptLanguageType.JAVASCRIPT.name());
testElement.setProperty(JmeterProperty.CACHE_KEY, cacheKey);
@ -64,6 +54,17 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
scriptLanguage = scriptProcessor.getCommonScriptInfo().getScriptLanguage();
script = scriptProcessor.getCommonScriptInfo().getScript();
}
// 设置环境变量
ApiParamConfig apiParamConfig = (ApiParamConfig) config;
EnvironmentInfoDTO envConfig = apiParamConfig.getEnvConfig(scriptProcessor.getProjectId());
if (envConfig != null) {
String envId = envConfig.getId();
if (StringUtils.isNotEmpty(script)) {
script = StringUtils.replace(script, ENV_VARIABLE_EXPRESSION, "\"" + MS_RUNNING_ENV_PREFIX + envId + ".\"");
}
}
if (scriptLanguage == null || StringUtils.equalsIgnoreCase(scriptLanguage, ScriptLanguageType.BEANSHELL_JSR233.name())) {
scriptLanguage = ScriptLanguageType.BEANSHELL.name();
}