feat(场景步骤、环境配置): 场景变量、环境配置 支持mock参数 (#1566)
* feat(测试跟踪): 测试用例下载模版增加标签列 * fix(接口定义): 扩大请求头键长度 * feat(场景步骤、环境配置): 场景变量、环境配置支持mock参数
This commit is contained in:
parent
f1c021e9cc
commit
595a594d50
|
@ -15,6 +15,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService;
|
|||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.ScriptEngineUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -132,7 +133,7 @@ public class MsScenario extends MsTestElement {
|
|||
// 场景变量和环境变量
|
||||
Arguments arguments = arguments(config);
|
||||
if (arguments != null) {
|
||||
tree.add(arguments);
|
||||
tree.add(config.valueSupposeMock(arguments));
|
||||
}
|
||||
this.addCsvDataSet(tree, variables);
|
||||
this.addCounter(tree, variables);
|
||||
|
|
|
@ -2,7 +2,9 @@ package io.metersphere.api.dto.definition.request;
|
|||
|
||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||
import io.metersphere.commons.utils.ScriptEngineUtils;
|
||||
import lombok.Data;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -37,4 +39,13 @@ public class ParameterConfig {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public Arguments valueSupposeMock(Arguments arguments) {
|
||||
for(int i = 0; i < arguments.getArguments().size(); ++i) {
|
||||
String argValue = arguments.getArgument(i).getValue();
|
||||
arguments.getArgument(i).setValue(ScriptEngineUtils.calculate(argValue));
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
}
|
|
@ -122,7 +122,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
// 添加环境中的公共变量
|
||||
Arguments arguments = this.addArguments(config);
|
||||
if (arguments != null) {
|
||||
tree.add(arguments);
|
||||
tree.add(config.valueSupposeMock(arguments));
|
||||
}
|
||||
try {
|
||||
if (config.isEffective(this.getProjectId())) {
|
||||
|
|
|
@ -1,30 +1,68 @@
|
|||
<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')" ref="nameInput"></el-input>
|
||||
</el-form-item>
|
||||
<div>
|
||||
<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')" ref="nameInput"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('commons.description')" prop="description">
|
||||
<el-input class="ms-http-textarea"
|
||||
v-model="editData.description"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 2, maxRows: 10}"
|
||||
:rows="2" size="small"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('commons.description')" prop="description">
|
||||
<el-input class="ms-http-textarea"
|
||||
v-model="editData.description"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 2, maxRows: 10}"
|
||||
:rows="2" size="small"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('api_test.value')" prop="value">
|
||||
<el-input v-model="editData.value" :placeholder="$t('api_test.value')"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-form-item :label="$t('api_test.value')" prop="value">
|
||||
<el-col class="item">
|
||||
<el-autocomplete
|
||||
size="small"
|
||||
:placeholder="$t('api_test.value')"
|
||||
style="width: 100%;"
|
||||
v-model="editData.value"
|
||||
value-key="name"
|
||||
:fetch-suggestions="funcSearch"
|
||||
highlight-first-item>
|
||||
<i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced"></i>
|
||||
</el-autocomplete>
|
||||
</el-col>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<ms-api-variable-advance ref="variableAdvance"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {JMETER_FUNC, MOCKJS_FUNC} from "@/common/js/constants";
|
||||
import MsApiVariableAdvance from "../../../test/components/ApiVariableAdvance";
|
||||
|
||||
export default {
|
||||
name: "MsEditConstant",
|
||||
components: {},
|
||||
components: {MsApiVariableAdvance},
|
||||
props: {
|
||||
editData: {},
|
||||
},
|
||||
methods: {
|
||||
advanced() {
|
||||
this.$refs.variableAdvance.open();
|
||||
},
|
||||
createFilter(queryString) {
|
||||
return (variable) => {
|
||||
return (variable.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
|
||||
};
|
||||
},
|
||||
funcFilter(queryString) {
|
||||
return (func) => {
|
||||
return (func.name.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
|
||||
};
|
||||
},
|
||||
funcSearch(queryString, cb) {
|
||||
let funcs = MOCKJS_FUNC.concat(JMETER_FUNC);
|
||||
let results = queryString ? funcs.filter(this.funcFilter(queryString)) : funcs;
|
||||
// 调用 callback 返回建议列表的数据
|
||||
cb(results);
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.$nextTick(() => {
|
||||
this.$refs.nameInput.focus();
|
||||
|
|
|
@ -15,8 +15,15 @@
|
|||
:placeholder="$t('api_test.variable_name')" show-word-limit/>
|
||||
</el-col>
|
||||
<el-col>
|
||||
<el-input :disabled="isReadOnly" v-model="item.value" size="small" @change="change"
|
||||
:placeholder="$t('api_test.value')" show-word-limit/>
|
||||
<el-autocomplete
|
||||
size="small"
|
||||
v-model="item.value"
|
||||
:fetch-suggestions="funcSearch"
|
||||
:placeholder="$t('api_test.value')"
|
||||
value-key="name"
|
||||
highlight-first-item>
|
||||
<i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced"></i>
|
||||
</el-autocomplete>
|
||||
</el-col>
|
||||
<el-col>
|
||||
<el-input v-model="item.description" size="small" maxlength="200"
|
||||
|
@ -33,16 +40,19 @@
|
|||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
<ms-api-variable-advance ref="variableAdvance"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {KeyValue} from "../model/ApiTestModel";
|
||||
import MsApiVariableInput from "./ApiVariableInput";
|
||||
import {JMETER_FUNC, MOCKJS_FUNC} from "@/common/js/constants";
|
||||
import MsApiVariableAdvance from "../../test/components/ApiVariableAdvance";
|
||||
|
||||
export default {
|
||||
name: "MsApiScenarioVariables",
|
||||
components: {MsApiVariableInput},
|
||||
components: {MsApiVariableInput, MsApiVariableAdvance},
|
||||
props: {
|
||||
description: String,
|
||||
items: Array,
|
||||
|
@ -94,7 +104,26 @@
|
|||
},
|
||||
isDisable: function (index) {
|
||||
return this.items.length - 1 === index;
|
||||
}
|
||||
},
|
||||
advanced() {
|
||||
this.$refs.variableAdvance.open();
|
||||
},
|
||||
createFilter(queryString) {
|
||||
return (variable) => {
|
||||
return (variable.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
|
||||
};
|
||||
},
|
||||
funcFilter(queryString) {
|
||||
return (func) => {
|
||||
return (func.name.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
|
||||
};
|
||||
},
|
||||
funcSearch(queryString, cb) {
|
||||
let funcs = MOCKJS_FUNC.concat(JMETER_FUNC);
|
||||
let results = queryString ? funcs.filter(this.funcFilter(queryString)) : funcs;
|
||||
// 调用 callback 返回建议列表的数据
|
||||
cb(results);
|
||||
},
|
||||
},
|
||||
|
||||
created() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<el-dialog :title="$t('api_test.request.parameters_advance')"
|
||||
:visible.sync="itemValueVisible"
|
||||
class="advanced-item-value"
|
||||
:append-to-body="true"
|
||||
width="70%">
|
||||
<el-tabs tab-position="top" style="height: 50vh;" @tab-click="selectTab">
|
||||
<el-tab-pane :label="$t('api_test.request.parameters_advance_mock')">
|
||||
|
|
Loading…
Reference in New Issue