Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
33e05223e9
|
@ -20,9 +20,6 @@ import lombok.EqualsAndHashCode;
|
|||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.config.CSVDataSet;
|
||||
import org.apache.jmeter.config.RandomVariableConfig;
|
||||
import org.apache.jmeter.modifiers.CounterConfig;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
@ -68,7 +65,8 @@ public class MsScenario extends MsTestElement {
|
|||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
ApiScenarioWithBLOBs scenario = apiAutomationService.getApiScenario(this.getId());
|
||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
|
||||
hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {});
|
||||
hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -88,9 +86,9 @@ public class MsScenario extends MsTestElement {
|
|||
}
|
||||
// 场景变量和环境变量
|
||||
tree.add(arguments(config));
|
||||
addCsvDataSet(tree);
|
||||
addCounter(tree);
|
||||
addRandom(tree);
|
||||
this.addCsvDataSet(tree, variables);
|
||||
this.addCounter(tree, variables);
|
||||
this.addRandom(tree, variables);
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
for (MsTestElement el : hashTree) {
|
||||
el.toHashTree(tree, el.getHashTree(), config);
|
||||
|
@ -133,71 +131,5 @@ public class MsScenario extends MsTestElement {
|
|||
return arguments;
|
||||
}
|
||||
|
||||
private void addCsvDataSet(HashTree tree) {
|
||||
if (CollectionUtils.isNotEmpty(this.getVariables())) {
|
||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
CSVDataSet csvDataSet = new CSVDataSet();
|
||||
csvDataSet.setEnabled(true);
|
||||
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
||||
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||
csvDataSet.setName(item.getName());
|
||||
csvDataSet.setProperty("fileEncoding", item.getEncoding());
|
||||
csvDataSet.setProperty("variableNames", item.getName());
|
||||
if (CollectionUtils.isNotEmpty(item.getFiles())) {
|
||||
csvDataSet.setProperty("filename", BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName());
|
||||
}
|
||||
csvDataSet.setIgnoreFirstLine(false);
|
||||
csvDataSet.setProperty("delimiter", item.getDelimiter());
|
||||
csvDataSet.setComment(item.getDescription());
|
||||
tree.add(csvDataSet);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCounter(HashTree tree) {
|
||||
if (CollectionUtils.isNotEmpty(this.getVariables())) {
|
||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
CounterConfig counterConfig = new CounterConfig();
|
||||
counterConfig.setEnabled(true);
|
||||
counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName());
|
||||
counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui"));
|
||||
counterConfig.setName(item.getName());
|
||||
counterConfig.setStart(item.getStartNumber());
|
||||
counterConfig.setEnd(item.getEndNumber());
|
||||
counterConfig.setVarName(item.getName());
|
||||
counterConfig.setIncrement(item.getIncrement());
|
||||
counterConfig.setFormat(item.getValue());
|
||||
counterConfig.setComment(item.getDescription());
|
||||
tree.add(counterConfig);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addRandom(HashTree tree) {
|
||||
if (CollectionUtils.isNotEmpty(this.getVariables())) {
|
||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isRandom).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
RandomVariableConfig randomVariableConfig = new RandomVariableConfig();
|
||||
randomVariableConfig.setEnabled(true);
|
||||
randomVariableConfig.setProperty(TestElement.TEST_CLASS, RandomVariableConfig.class.getName());
|
||||
randomVariableConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||
randomVariableConfig.setName(item.getName());
|
||||
randomVariableConfig.setProperty("variableName", item.getName());
|
||||
randomVariableConfig.setProperty("outputFormat", item.getValue());
|
||||
randomVariableConfig.setProperty("minimumValue", item.getMinNumber());
|
||||
randomVariableConfig.setProperty("maximumValue", item.getMaxNumber());
|
||||
randomVariableConfig.setComment(item.getDescription());
|
||||
tree.add(randomVariableConfig);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
|||
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
|
||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
|
@ -33,6 +34,9 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import lombok.Data;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.config.CSVDataSet;
|
||||
import org.apache.jmeter.config.RandomVariableConfig;
|
||||
import org.apache.jmeter.modifiers.CounterConfig;
|
||||
import org.apache.jmeter.protocol.http.control.AuthManager;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
|
@ -42,6 +46,7 @@ import org.apache.jorphan.collections.ListedHashTree;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
|
||||
@JsonSubTypes({
|
||||
|
@ -91,6 +96,7 @@ public abstract class MsTestElement {
|
|||
@JSONField(ordinal = 10)
|
||||
private LinkedList<MsTestElement> hashTree;
|
||||
|
||||
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
|
||||
// 公共环境逐层传递,如果自身有环境 以自身引用环境为准否则以公共环境作为请求环境
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||
for (MsTestElement el : hashTree) {
|
||||
|
@ -166,6 +172,74 @@ public abstract class MsTestElement {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void addCsvDataSet(HashTree tree,List<ScenarioVariable> variables) {
|
||||
if (CollectionUtils.isNotEmpty(variables)) {
|
||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
CSVDataSet csvDataSet = new CSVDataSet();
|
||||
csvDataSet.setEnabled(true);
|
||||
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
||||
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||
csvDataSet.setName(item.getName());
|
||||
csvDataSet.setProperty("fileEncoding", item.getEncoding());
|
||||
csvDataSet.setProperty("variableNames", item.getName());
|
||||
if (CollectionUtils.isNotEmpty(item.getFiles())) {
|
||||
csvDataSet.setProperty("filename", BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName());
|
||||
}
|
||||
csvDataSet.setIgnoreFirstLine(false);
|
||||
csvDataSet.setProperty("delimiter", item.getDelimiter());
|
||||
csvDataSet.setComment(item.getDescription());
|
||||
tree.add(csvDataSet);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addCounter(HashTree tree,List<ScenarioVariable> variables) {
|
||||
if (CollectionUtils.isNotEmpty(variables)) {
|
||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
CounterConfig counterConfig = new CounterConfig();
|
||||
counterConfig.setEnabled(true);
|
||||
counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName());
|
||||
counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui"));
|
||||
counterConfig.setName(item.getName());
|
||||
counterConfig.setStart(item.getStartNumber());
|
||||
counterConfig.setEnd(item.getEndNumber());
|
||||
counterConfig.setVarName(item.getName());
|
||||
counterConfig.setIncrement(item.getIncrement());
|
||||
counterConfig.setFormat(item.getValue());
|
||||
counterConfig.setComment(item.getDescription());
|
||||
tree.add(counterConfig);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addRandom(HashTree tree,List<ScenarioVariable> variables) {
|
||||
if (CollectionUtils.isNotEmpty(variables)) {
|
||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isRandom).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
RandomVariableConfig randomVariableConfig = new RandomVariableConfig();
|
||||
randomVariableConfig.setEnabled(true);
|
||||
randomVariableConfig.setProperty(TestElement.TEST_CLASS, RandomVariableConfig.class.getName());
|
||||
randomVariableConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||
randomVariableConfig.setName(item.getName());
|
||||
randomVariableConfig.setProperty("variableName", item.getName());
|
||||
randomVariableConfig.setProperty("outputFormat", item.getValue());
|
||||
randomVariableConfig.setProperty("minimumValue", item.getMinNumber());
|
||||
randomVariableConfig.setProperty("maximumValue", item.getMaxNumber());
|
||||
randomVariableConfig.setComment(item.getDescription());
|
||||
tree.add(randomVariableConfig);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -60,6 +60,12 @@ public class MsLoopController extends MsTestElement {
|
|||
config.setStepType("LOOP");
|
||||
|
||||
final HashTree groupTree = controller(tree);
|
||||
if (CollectionUtils.isNotEmpty(config.getVariables())) {
|
||||
this.addCsvDataSet(groupTree, config.getVariables());
|
||||
this.addCounter(groupTree, config.getVariables());
|
||||
this.addRandom(groupTree, config.getVariables());
|
||||
}
|
||||
|
||||
// 循环下都增加一个计数器,用于结果统计
|
||||
groupTree.add(addCounterConfig());
|
||||
// 不打开执行成功后轮询功能,则成功后就停止循环
|
||||
|
|
|
@ -150,6 +150,7 @@ public class TestPlanService {
|
|||
public List<TestPlan> getTestPlanByName(String name) {
|
||||
TestPlanExample example = new TestPlanExample();
|
||||
example.createCriteria().andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId())
|
||||
.andProjectIdEqualTo(SessionUtils.getCurrentProjectId())
|
||||
.andNameEqualTo(name);
|
||||
return testPlanMapper.selectByExample(example);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
v-if="!readOnly"
|
||||
class="tag-input el-input"
|
||||
v-model="newTag"
|
||||
placeholder="输入回车添加"
|
||||
placeholder="$t('commons.tag_tip)"
|
||||
@keydown.delete.stop="removeLastTag"
|
||||
@keydown="addNew"
|
||||
@blur="addNew"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form">
|
||||
<el-form-item :label="$t('api_test.variable_name')" prop="name">
|
||||
<el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')"></el-input>
|
||||
<el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')" ref="nameInput"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('commons.description')" prop="description">
|
||||
|
@ -25,6 +25,17 @@
|
|||
props: {
|
||||
editData: {},
|
||||
},
|
||||
created() {
|
||||
this.$nextTick(() => {
|
||||
this.$refs.nameInput.focus();
|
||||
});
|
||||
},
|
||||
watch: {
|
||||
editData() {
|
||||
this.$refs.nameInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<div style="margin:20px">
|
||||
<el-button style="margin-right:10px" @click="deleteVariable">{{$t('commons.delete')}}</el-button>
|
||||
|
||||
<el-dropdown split-button type="primary" @command="handleClick" placement="top-end">
|
||||
<el-dropdown split-button type="primary" @command="handleClick" @click="handleClick('CONSTANT')" placement="top-end">
|
||||
{{$t('commons.add')}}
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="CONSTANT">常量</el-dropdown-item>
|
||||
|
|
|
@ -132,6 +132,7 @@ export default {
|
|||
batch_add: "Batch add",
|
||||
check_project_tip: "Create or select the project first",
|
||||
auth_redirect_tip: 'Jump to the authentication source page for authentication',
|
||||
tag_tip: "Enter Enter to Add Label",
|
||||
table: {
|
||||
select_tip: "Item {0} data is selected"
|
||||
},
|
||||
|
|
|
@ -133,6 +133,7 @@ export default {
|
|||
batch_add: "批量添加",
|
||||
check_project_tip: "请先创建或选择项目",
|
||||
auth_redirect_tip: '即将跳转到认证源页面进行认证',
|
||||
tag_tip: "输入回车添加标签",
|
||||
table: {
|
||||
select_tip: "已选中 {0} 条数据"
|
||||
},
|
||||
|
|
|
@ -133,6 +133,7 @@ export default {
|
|||
batch_add: "批量添加",
|
||||
check_project_tip: "請先創建或選擇項目",
|
||||
auth_redirect_tip: '即將跳轉到認證源頁面進行認證',
|
||||
tag_tip: "輸入回車添加標簽",
|
||||
table: {
|
||||
select_tip: "已选中 {0} 条数据"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue