fix(接口测试): 修复提取参数无法使用all的缺陷
--bug=1038519 --user=王孝刚 【接口测试】提取的数组用于下面的接口测试,用不了 https://www.tapd.cn/55049933/s/1490194
This commit is contained in:
parent
6829df6aa9
commit
72267841f2
|
@ -3,16 +3,14 @@ package io.metersphere.api.parser.jmeter;
|
|||
import io.metersphere.api.dto.request.controller.LoopType;
|
||||
import io.metersphere.api.dto.request.controller.MsLoopController;
|
||||
import io.metersphere.api.dto.request.controller.WhileConditionType;
|
||||
import io.metersphere.api.parser.jmeter.processor.ScriptFilter;
|
||||
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
||||
import io.metersphere.project.constants.ScriptLanguageType;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.control.*;
|
||||
import org.apache.jmeter.modifiers.JSR223PreProcessor;
|
||||
import org.apache.jmeter.protocol.java.sampler.JSR223Sampler;
|
||||
import org.apache.jmeter.sampler.TestAction;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jmeter.timers.ConstantTimer;
|
||||
|
@ -43,6 +41,21 @@ public class MsLoopControllerConverter extends AbstractJmeterElementConverter<Ms
|
|||
|
||||
parseChild(groupTree, element, config);
|
||||
|
||||
//如果是while循环,需要添加一个循环控制器超时处理
|
||||
if (StringUtils.equals(element.getLoopType(), LoopType.WHILE.name()) && element.getWhileController() != null) {
|
||||
String ifCondition = "${__jexl3(${__time(,)} - ${\"" + element.getCurrentTime() + "\"} >" + element.getWhileController().getTimeout() + ")}";
|
||||
IfController ifController = ifController(ifCondition, element.getEnable());
|
||||
TestAction testAction = new TestAction();
|
||||
testAction.setEnabled(true);
|
||||
testAction.setName("结束循环");
|
||||
testAction.setProperty("ActionProcessor.action", 5);
|
||||
testAction.setProperty(TestElement.TEST_CLASS, TestAction.class.getName());
|
||||
testAction.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestActionGui"));
|
||||
testAction.setProperty("ActionProcessor.target",0);
|
||||
|
||||
groupTree.add(ifController, testAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,23 +77,9 @@ public class MsLoopControllerConverter extends AbstractJmeterElementConverter<Ms
|
|||
condition = element.getWhileController().getMsWhileScript().getScriptValue();
|
||||
}
|
||||
String ifCondition = "${__jexl3(" + condition + ")}";
|
||||
String whileCondition = "${__jexl3(" + condition + " && \"${" + element.getCurrentTime() + "}\" !=\"stop\")}";
|
||||
HashTree ifHashTree = tree.add(ifController(ifCondition, element.getEnable()));
|
||||
addPreProc(ifHashTree, element);
|
||||
|
||||
HashTree hashTree = ifHashTree.add(initWhileController(element, whileCondition));
|
||||
// 添加超时处理,防止死循环
|
||||
JSR223PreProcessor jsr223PreProcessor = new JSR223PreProcessor();
|
||||
jsr223PreProcessor.setName("While 循环控制器超时处理脚本");
|
||||
jsr223PreProcessor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
|
||||
jsr223PreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||
jsr223PreProcessor.setProperty("scriptLanguage", ScriptLanguageType.BEANSHELL.name().toLowerCase());
|
||||
|
||||
ScriptFilter.verify(ScriptLanguageType.BEANSHELL.name().toLowerCase(), element.getName(), script(element));
|
||||
|
||||
jsr223PreProcessor.setProperty("script", script(element));
|
||||
hashTree.add(jsr223PreProcessor);
|
||||
return hashTree;
|
||||
return ifHashTree.add(initWhileController(element, ifCondition));
|
||||
}
|
||||
if (StringUtils.equals(element.getLoopType(), LoopType.FOREACH.name()) && element.getForEachController() != null) {
|
||||
return tree.add(initForeachController(element));
|
||||
|
@ -93,43 +92,13 @@ public class MsLoopControllerConverter extends AbstractJmeterElementConverter<Ms
|
|||
return null;
|
||||
}
|
||||
|
||||
private static String script(MsLoopController element) {
|
||||
String script = """
|
||||
|
||||
import java.util.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import org.apache.jmeter.threads.JMeterContextService;
|
||||
|
||||
// 循环控制器超时后结束循环
|
||||
try{
|
||||
String ms_current_timer = vars.get("%s");
|
||||
long _nowTime = System.currentTimeMillis();
|
||||
if(ms_current_timer == null ){
|
||||
vars.put("%s",_nowTime.toString());
|
||||
}
|
||||
long time = Long.parseLong(vars.get("%s"));
|
||||
if((_nowTime - time) > %s ){
|
||||
vars.put("%s", "stop");
|
||||
log.info( "结束循环");
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.info( e.getMessage());
|
||||
vars.put("%s", "stop");
|
||||
}
|
||||
|
||||
""";
|
||||
|
||||
return String.format(script, element.getCurrentTime(), element.getCurrentTime(), element.getCurrentTime(), element.getWhileController().getTimeout(), element.getCurrentTime(), element.getCurrentTime());
|
||||
}
|
||||
|
||||
private void addPreProc(HashTree hashTree, MsLoopController element) {
|
||||
JSR223Sampler sampler = new JSR223Sampler();
|
||||
sampler.setName("MS_CLEAR_LOOPS_VAR_" + element.getCurrentTime());
|
||||
sampler.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
|
||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||
sampler.setProperty("scriptLanguage", ScriptLanguageType.BEANSHELL.name().toLowerCase());
|
||||
ScriptFilter.verify(ScriptLanguageType.BEANSHELL.name().toLowerCase(), element.getName(), script(element));
|
||||
sampler.setProperty("script", "vars.put(\"" + element.getCurrentTime() + "\", null);");
|
||||
sampler.setProperty("script", "${__time(,\"" + element.getCurrentTime() + "\")};");
|
||||
hashTree.add(sampler);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public class JSONPathExtractConverter extends ExtractConverter<JSONPathExtract>
|
|||
extractor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JSON_POST_PROCESSOR_GUI));
|
||||
extractor.setRefNames(msExtract.getVariableName());
|
||||
extractor.setJsonPathExpressions(msExtract.getExpression());
|
||||
extractor.setProperty("JSONPostProcessor.compute_concat", true);
|
||||
// 处理匹配多条等匹配规则
|
||||
extractor.setMatchNumbers(parseResultMatchingRule(msExtract).toString());
|
||||
extractor.setEnabled(msExtract.getEnable());
|
||||
|
|
|
@ -238,6 +238,9 @@ public class ApiReportService {
|
|||
List<ApiReportStepDTO> apiReportSteps = new ArrayList<>();
|
||||
apiReportSteps.add(apiReportStepDTO);
|
||||
apiReportDTO.setChildren(apiReportSteps);
|
||||
} else {
|
||||
apiReportDTO.setTotal(1L);
|
||||
apiReportDTO.setPendingCount(1L);
|
||||
}
|
||||
return apiReportDTO;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.github.pagehelper.page.PageMethod;
|
|||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.Organization;
|
||||
import io.metersphere.system.domain.Schedule;
|
||||
|
@ -23,7 +22,6 @@ import org.quartz.*;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -205,25 +203,10 @@ public class TaskCenterService {
|
|||
|
||||
public void enable(String id) {
|
||||
Schedule schedule = checkScheduleExit(id);
|
||||
//根据全路径获取类 通过反射获取类
|
||||
schedule.setEnable(!schedule.getEnable());
|
||||
scheduleService.editSchedule(schedule);
|
||||
try {
|
||||
String className = schedule.getJob();
|
||||
Class<?> clazz = Class.forName(className);
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
// 调用无参方法
|
||||
Method method = clazz.getMethod("getTriggerKey", String.class);
|
||||
Object result = method.invoke(instance, schedule.getResourceId());
|
||||
|
||||
Method method1 = clazz.getMethod("getJobKey", String.class);
|
||||
Object result1 = method1.invoke(instance, schedule.getResourceId());
|
||||
|
||||
scheduleService.addOrUpdateCronJob(schedule, (JobKey) result1, (TriggerKey) result, clazz);
|
||||
} catch (Exception e) {
|
||||
LogUtils.error("enable schedule error", e);
|
||||
}
|
||||
scheduleService.addOrUpdateCronJob(schedule, new JobKey(schedule.getKey(), schedule.getJob()),
|
||||
new TriggerKey(schedule.getKey(),schedule.getJob()), schedule.getJob().getClass());
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -339,6 +339,7 @@
|
|||
:min="0"
|
||||
:precision="0"
|
||||
:max="600000"
|
||||
:default-value="1000"
|
||||
class="w-[160px]"
|
||||
model-event="input"
|
||||
/>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</a-radio>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
<div v-if="props.isShowResultMatchRules" class="mb-[16px]">
|
||||
<div class="mb-[16px]">
|
||||
<div class="mb-[8px] text-[14px] text-[var(--color-text-1)]">
|
||||
{{ t('apiTestDebug.resultMatchRule') }}
|
||||
</div>
|
||||
|
@ -116,7 +116,6 @@
|
|||
const props = defineProps<{
|
||||
config: ExpressionConfig;
|
||||
isPopover?: boolean; // 是否是弹出框展示,弹出框展示时才显示表达式类型
|
||||
isShowResultMatchRules?: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:config', config: ExpressionConfig): void;
|
||||
|
|
|
@ -48,7 +48,7 @@ export const defaultConditionController = {
|
|||
|
||||
// 条件控制器
|
||||
export const defaultTimeController = {
|
||||
delay: 0, // 等待时间
|
||||
delay: 1000, // 等待时间
|
||||
};
|
||||
|
||||
// 场景配置
|
||||
|
|
Loading…
Reference in New Issue