fix(接口自动化): 修复导入jmx JSON 提取参数问题

This commit is contained in:
fit2-zhao 2021-03-03 17:28:05 +08:00
parent eae9359892
commit a30c790a41
1 changed files with 15 additions and 5 deletions

View File

@ -48,6 +48,7 @@ import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.assertions.*; import org.apache.jmeter.assertions.*;
import org.apache.jmeter.config.ConfigTestElement; import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.control.ForeachController; import org.apache.jmeter.control.ForeachController;
@ -439,11 +440,20 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
extract.getXpath().add(xPath); extract.getXpath().add(xPath);
} else if (key instanceof JSONPostProcessor) { } else if (key instanceof JSONPostProcessor) {
JSONPostProcessor jsonPostProcessor = (JSONPostProcessor) key; JSONPostProcessor jsonPostProcessor = (JSONPostProcessor) key;
MsExtractJSONPath jsonPath = new MsExtractJSONPath(); String[] names = StringUtils.isNotEmpty(jsonPostProcessor.getRefNames()) ? jsonPostProcessor.getRefNames().split(";") : null;
jsonPath.setVariable(jsonPostProcessor.getRefNames()); String[] values = StringUtils.isNotEmpty(jsonPostProcessor.getJsonPathExpressions()) ? jsonPostProcessor.getJsonPathExpressions().split(";") : null;
jsonPath.setExpression(jsonPostProcessor.getJsonPathExpressions()); if (names != null) {
extract.setName(jsonPostProcessor.getName()); for (int i = 0; i < names.length; i++) {
extract.getJson().add(jsonPath); MsExtractJSONPath jsonPath = new MsExtractJSONPath();
jsonPath.setVariable(names[i]);
if (values != null && values.length > i) {
jsonPath.setExpression(values[i]);
}
jsonPath.setMultipleMatching(jsonPostProcessor.getComputeConcatenation());
extract.setName(jsonPostProcessor.getName());
extract.getJson().add(jsonPath);
}
}
} }
} }