feat(接口测试): 计数器支持变量参数

--story=1010670 --user=赵勇 【接口测试】场景变量-计数器支持参数化(环境&接口测试) https://www.tapd.cn/55049933/s/1309282
This commit is contained in:
fit2-zhao 2022-12-01 11:20:57 +08:00 committed by CaptainB
parent 470945e9d7
commit a15b425206
7 changed files with 71 additions and 58 deletions

View File

@ -189,7 +189,7 @@ public class ElementUtil {
}
}
public static void addCounter(HashTree tree, List<ScenarioVariable> variables, boolean isInternal) {
public static void addCounter(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).filter(ScenarioVariable::isEnable).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -199,11 +199,7 @@ public class ElementUtil {
counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName());
counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui"));
counterConfig.setName(item.getName());
if (isInternal) {
counterConfig.setStart((item.getStartNumber() + 1));
} else {
counterConfig.setStart(item.getStartNumber());
}
counterConfig.setEnd(item.getEndNumber());
counterConfig.setVarName(item.getName());
counterConfig.setIncrement(item.getIncrement());
@ -814,7 +810,7 @@ public class ElementUtil {
config.getConfig().get(projectId).getCommonConfig().getVariables(),
config, "shareMode.group");
ElementUtil.addCounter(httpSamplerTree,
config.getConfig().get(projectId).getCommonConfig().getVariables(), false);
config.getConfig().get(projectId).getCommonConfig().getVariables());
ElementUtil.addRandom(httpSamplerTree,
config.getConfig().get(projectId).getCommonConfig().getVariables());
}

View File

@ -125,7 +125,7 @@ public class MsScenario extends MsTestElement {
}
if (this.variableEnable == null || this.variableEnable) {
ElementUtil.addCsvDataSet(scenarioTree, variables, this.isEnvironmentEnable() ? newConfig : config, "shareMode.group");
ElementUtil.addCounter(scenarioTree, variables, false);
ElementUtil.addCounter(scenarioTree, variables);
ElementUtil.addRandom(scenarioTree, variables);
if (CollectionUtils.isNotEmpty(this.headers)) {
if (this.isEnvironmentEnable()) {

View File

@ -53,7 +53,7 @@ public class MsLoopController extends MsTestElement {
// 自身场景
if (CollectionUtils.isNotEmpty(config.getVariables())) {
ElementUtil.addCsvDataSet(groupTree, config.getVariables(), config, "shareMode.thread");
ElementUtil.addCounter(groupTree, config.getVariables(), true);
ElementUtil.addCounter(groupTree, config.getVariables());
ElementUtil.addRandom(groupTree, config.getVariables());
}
// 当前引用场景
@ -73,7 +73,7 @@ public class MsLoopController extends MsTestElement {
if (CollectionUtils.isNotEmpty(variables)) {
ElementUtil.addCsvDataSet(groupTree, variables, config, "shareMode.thread");
ElementUtil.addCounter(groupTree, variables, true);
ElementUtil.addCounter(groupTree, variables);
ElementUtil.addRandom(groupTree, variables);
}
}

View File

@ -32,9 +32,9 @@ public class ScenarioVariable {
/**
* counter
*/
private int startNumber;
private int endNumber;
private int increment;
private String startNumber;
private String endNumber;
private String increment;
/**
* random
*/

View File

@ -16,34 +16,13 @@
</el-form-item>
<el-form-item :label="$t('variables.start')" prop="startNumber">
<el-input-number
:disabled="disabled"
size="small"
v-model="editData.startNumber"
placeholder="0"
style="width: 100%"
:max="1000 * 10000000"
:min="0" />
<el-input :disabled="disabled" size="small" v-model="editData.startNumber" placeholder="0" style="width: 100%" />
</el-form-item>
<el-form-item :label="$t('variables.end')" prop="endNumber">
<el-input-number
:disabled="disabled"
size="small"
v-model="editData.endNumber"
placeholder="10"
style="width: 100%"
:max="1000 * 10000000"
:min="0" />
<el-input :disabled="disabled" size="small" v-model="editData.endNumber" placeholder="10" style="width: 100%" />
</el-form-item>
<el-form-item :label="$t('variables.increment')" prop="increment">
<el-input-number
:disabled="disabled"
size="small"
v-model="editData.increment"
placeholder="1"
style="width: 100%"
:max="1000 * 10000000"
:min="0" />
<el-input :disabled="disabled" size="small" v-model="editData.increment" placeholder="1" style="width: 100%" />
</el-form-item>
<el-form-item :label="$t('variables.format')" prop="value">
<el-input :disabled="disabled" v-model="editData.value" :placeholder="$t('variables.counter_info')"></el-input>

View File

@ -1,28 +1,64 @@
<template>
<el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form2" :rules="rules">
<el-form
:model="editData"
label-position="right"
label-width="80px"
size="small"
ref="form2"
:rules="rules"
>
<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')"
></el-input>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea"
<el-input
class="ms-http-textarea"
v-model="editData.description"
type="textarea"
:autosize="{ minRows: 2, maxRows: 10}"
:rows="2" size="small" :disabled="disabled"/>
:autosize="{ minRows: 2, maxRows: 10 }"
:rows="2"
size="small"
:disabled="disabled"
/>
</el-form-item>
<el-form-item :label="$t('variables.start')" prop="startNumber">
<el-input-number :disabled="disabled" size="small" v-model="editData.startNumber" placeholder="0" style="width: 100%" :max="1000*10000000" :min="0"/>
<el-input
:disabled="disabled"
size="small"
v-model="editData.startNumber"
placeholder="0"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('variables.end')" prop="endNumber">
<el-input-number :disabled="disabled" size="small" v-model="editData.endNumber" placeholder="10" style="width: 100%" :max="1000*10000000" :min="0"/>
<el-input
:disabled="disabled"
size="small"
v-model="editData.endNumber"
placeholder="10"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('variables.increment')" prop="increment">
<el-input-number :disabled="disabled" size="small" v-model="editData.increment" placeholder="1" style="width: 100%" :max="1000*10000000" :min="0"/>
<el-input
:disabled="disabled"
size="small"
v-model="editData.increment"
placeholder="1"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('variables.format')" prop="value">
<el-input :disabled="disabled" v-model="editData.value" :placeholder="$t('variables.counter_info')"></el-input>
<el-input
:disabled="disabled"
v-model="editData.value"
:placeholder="$t('variables.counter_info')"
></el-input>
</el-form-item>
</el-form>
</template>
@ -37,20 +73,22 @@ export default {
computed: {
disabled() {
return !(this.editData.name && this.editData.name !== "");
}
},
},
data() {
return {
rules: {
name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{
required: true,
message: this.$t("test_track.case.input_name"),
trigger: "blur",
},
],
},
}
};
},
}
};
</script>
<style scoped>
</style>
<style scoped></style>

View File

@ -32,9 +32,9 @@ public class ScenarioVariable {
/**
* counter
*/
private int startNumber;
private int endNumber;
private int increment;
private String startNumber;
private String endNumber;
private String increment;
/**
* random
*/