refactor(接口测试): 导入jmx文件优化,支持多线程组
--story=1011083 --user=赵勇 【Bug转需求】接口自动化支持导入多线程的jmx文件 https://www.tapd.cn/55049933/s/1329318
This commit is contained in:
parent
273d8113b6
commit
a2a2bd0571
|
@ -29,6 +29,7 @@ import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndServ
|
||||||
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
|
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
|
||||||
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
|
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
|
||||||
import io.metersphere.api.dto.definition.request.unknown.MsJmeterElement;
|
import io.metersphere.api.dto.definition.request.unknown.MsJmeterElement;
|
||||||
|
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||||
import io.metersphere.api.dto.scenario.Body;
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
|
@ -37,10 +38,7 @@ import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
import io.metersphere.base.domain.ApiTestEnvironmentExample;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.*;
|
||||||
import io.metersphere.commons.constants.LoopConstants;
|
|
||||||
import io.metersphere.commons.constants.PropertyConstant;
|
|
||||||
import io.metersphere.commons.constants.RequestTypeConstants;
|
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
import io.metersphere.environment.service.BaseEnvironmentService;
|
||||||
|
@ -48,8 +46,10 @@ import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.request.BodyFile;
|
import io.metersphere.request.BodyFile;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.assertions.*;
|
import org.apache.jmeter.assertions.*;
|
||||||
|
import org.apache.jmeter.config.Argument;
|
||||||
import org.apache.jmeter.config.ConfigTestElement;
|
import org.apache.jmeter.config.ConfigTestElement;
|
||||||
import org.apache.jmeter.control.ForeachController;
|
import org.apache.jmeter.control.ForeachController;
|
||||||
import org.apache.jmeter.control.LoopController;
|
import org.apache.jmeter.control.LoopController;
|
||||||
|
@ -75,6 +75,7 @@ import org.apache.jmeter.save.SaveService;
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jmeter.testelement.TestPlan;
|
import org.apache.jmeter.testelement.TestPlan;
|
||||||
import org.apache.jmeter.testelement.property.JMeterProperty;
|
import org.apache.jmeter.testelement.property.JMeterProperty;
|
||||||
|
import org.apache.jmeter.threads.ThreadGroup;
|
||||||
import org.apache.jmeter.timers.ConstantTimer;
|
import org.apache.jmeter.timers.ConstantTimer;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
|
@ -105,7 +106,27 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||||
|
|
||||||
MsScenario scenario = new MsScenario();
|
MsScenario scenario = new MsScenario();
|
||||||
scenario.setReferenced("IMPORT");
|
scenario.setReferenced("IMPORT");
|
||||||
formatHashTree(testPlan, scenario);
|
|
||||||
|
TestPlan plan = (TestPlan) testPlan.getArray()[0];
|
||||||
|
if (plan.getArguments() != null) {
|
||||||
|
List<ScenarioVariable> variables = new LinkedList<>();
|
||||||
|
plan.getArguments().forEach(item -> {
|
||||||
|
ScenarioVariable scenarioVariable = new ScenarioVariable();
|
||||||
|
scenarioVariable.setId(UUID.randomUUID().toString());
|
||||||
|
scenarioVariable.setName(item.getName());
|
||||||
|
if (ObjectUtils.isNotEmpty(item.getObjectValue())) {
|
||||||
|
Argument arg = (Argument) item.getObjectValue();
|
||||||
|
scenarioVariable.setValue(arg.getValue());
|
||||||
|
}
|
||||||
|
scenarioVariable.setType(VariableTypeConstants.CONSTANT.name());
|
||||||
|
variables.add(scenarioVariable);
|
||||||
|
});
|
||||||
|
scenario.setVariables(variables);
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(scenario.getHashTree())) {
|
||||||
|
scenario.setHashTree(new LinkedList<>());
|
||||||
|
}
|
||||||
|
formatHashTree(testPlan.getTree(plan), scenario);
|
||||||
this.projectId = request.getProjectId();
|
this.projectId = request.getProjectId();
|
||||||
ScenarioImport scenarioImport = new ScenarioImport();
|
ScenarioImport scenarioImport = new ScenarioImport();
|
||||||
scenarioImport.setData(parseObj(scenario, request));
|
scenarioImport.setData(parseObj(scenario, request));
|
||||||
|
@ -697,11 +718,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||||
}
|
}
|
||||||
// 测试计划
|
// 测试计划
|
||||||
if (key instanceof TestPlan) {
|
if (key instanceof TestPlan) {
|
||||||
scenario.setName(((TestPlan) key).getName());
|
continue;
|
||||||
elementNode = new MsJmeterElement();
|
|
||||||
elementNode.setName(((TestPlan) key).getName());
|
|
||||||
((MsJmeterElement) elementNode).setJmeterElement(objToXml(key));
|
|
||||||
((MsJmeterElement) elementNode).setElementType(key.getClass().getSimpleName());
|
|
||||||
}
|
}
|
||||||
// 线程组
|
// 线程组
|
||||||
else if (key instanceof ThreadGroup) {
|
else if (key instanceof ThreadGroup) {
|
||||||
|
|
|
@ -582,7 +582,6 @@ import {getEnvironmentByProjectId} from 'metersphere-frontend/src/api/environmen
|
||||||
import { useApiStore } from '@/store';
|
import { useApiStore } from '@/store';
|
||||||
import { getDefaultVersion, setLatestVersionById } from 'metersphere-frontend/src/api/version';
|
import { getDefaultVersion, setLatestVersionById } from 'metersphere-frontend/src/api/version';
|
||||||
|
|
||||||
|
|
||||||
const store = useApiStore();
|
const store = useApiStore();
|
||||||
|
|
||||||
let jsonPath = require('jsonpath');
|
let jsonPath = require('jsonpath');
|
||||||
|
@ -790,7 +789,7 @@ export default {
|
||||||
debugReportId: '',
|
debugReportId: '',
|
||||||
isPreventReClick: false,
|
isPreventReClick: false,
|
||||||
latestVersionId: '',
|
latestVersionId: '',
|
||||||
hasLatest: false
|
hasLatest: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -923,6 +922,9 @@ export default {
|
||||||
if (!array) {
|
if (!array) {
|
||||||
array = this.scenarioDefinition;
|
array = this.scenarioDefinition;
|
||||||
}
|
}
|
||||||
|
if (!array) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let isLeaf = true;
|
let isLeaf = true;
|
||||||
let nodeType = '';
|
let nodeType = '';
|
||||||
if (node) {
|
if (node) {
|
||||||
|
@ -2489,8 +2491,7 @@ export default {
|
||||||
if (!hasLicense()) {
|
if (!hasLicense()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getDefaultVersion(this.projectId)
|
getDefaultVersion(this.projectId).then((response) => {
|
||||||
.then(response => {
|
|
||||||
this.latestVersionId = response.data;
|
this.latestVersionId = response.data;
|
||||||
this.getVersionHistory();
|
this.getVersionHistory();
|
||||||
});
|
});
|
||||||
|
@ -2507,7 +2508,7 @@ export default {
|
||||||
}
|
}
|
||||||
let latestVersionData = response.data.filter((v) => v.versionId === this.latestVersionId);
|
let latestVersionData = response.data.filter((v) => v.versionId === this.latestVersionId);
|
||||||
if (latestVersionData.length > 0) {
|
if (latestVersionData.length > 0) {
|
||||||
this.hasLatest = false
|
this.hasLatest = false;
|
||||||
} else {
|
} else {
|
||||||
this.hasLatest = true;
|
this.hasLatest = true;
|
||||||
}
|
}
|
||||||
|
@ -2567,8 +2568,8 @@ export default {
|
||||||
projectId: this.projectId,
|
projectId: this.projectId,
|
||||||
type: 'SCENARIO',
|
type: 'SCENARIO',
|
||||||
versionId: row.id,
|
versionId: row.id,
|
||||||
resourceId: this.currentScenario.id
|
resourceId: this.currentScenario.id,
|
||||||
}
|
};
|
||||||
setLatestVersionById(param).then(() => {
|
setLatestVersionById(param).then(() => {
|
||||||
this.$success(this.$t('commons.modify_success'));
|
this.$success(this.$t('commons.modify_success'));
|
||||||
this.checkout(row);
|
this.checkout(row);
|
||||||
|
|
Loading…
Reference in New Issue