fix(接口定义): 修复自定义请求执行缺陷
This commit is contained in:
parent
37c426c8bc
commit
b9143716f7
|
@ -116,11 +116,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (config != null && config.getConfig() != null) {
|
if (config != null && config.getConfig() != null) {
|
||||||
String url = "";
|
String url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket();
|
||||||
sampler.setDomain(config.getConfig().getHttpConfig().getDomain());
|
|
||||||
sampler.setPort(config.getConfig().getHttpConfig().getPort());
|
|
||||||
sampler.setProtocol(config.getConfig().getHttpConfig().getProtocol());
|
|
||||||
url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket();
|
|
||||||
// 补充如果是完整URL 则用自身URL
|
// 补充如果是完整URL 则用自身URL
|
||||||
boolean isUrl = false;
|
boolean isUrl = false;
|
||||||
if (StringUtils.isNotEmpty(this.getUrl()) && isURL(this.getUrl())) {
|
if (StringUtils.isNotEmpty(this.getUrl()) && isURL(this.getUrl())) {
|
||||||
|
@ -128,12 +124,21 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
isUrl = true;
|
isUrl = true;
|
||||||
}
|
}
|
||||||
URL urlObject = new URL(url);
|
URL urlObject = new URL(url);
|
||||||
|
if (isUrl) {
|
||||||
|
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8"));
|
||||||
|
sampler.setPort(urlObject.getPort());
|
||||||
|
sampler.setProtocol(urlObject.getProtocol());
|
||||||
|
} else {
|
||||||
|
sampler.setDomain(config.getConfig().getHttpConfig().getDomain());
|
||||||
|
sampler.setPort(config.getConfig().getHttpConfig().getPort());
|
||||||
|
sampler.setProtocol(config.getConfig().getHttpConfig().getProtocol());
|
||||||
|
}
|
||||||
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
|
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
|
||||||
if (StringUtils.isNotBlank(this.getPath()) && !isUrl) {
|
if (StringUtils.isNotBlank(this.getPath()) && !isUrl) {
|
||||||
envPath += this.getPath();
|
envPath += this.getPath();
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||||
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"));
|
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"), config);
|
||||||
sampler.setPath(envPath);
|
sampler.setPath(envPath);
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
||||||
|
@ -150,7 +155,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
sampler.setProtocol(urlObject.getProtocol());
|
sampler.setProtocol(urlObject.getProtocol());
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||||
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"), config));
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
||||||
sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
||||||
|
@ -193,7 +198,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRestParameters(String path) {
|
private String getRestParameters(String path, ParameterConfig config) {
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer.append(path);
|
stringBuffer.append(path);
|
||||||
stringBuffer.append("/");
|
stringBuffer.append("/");
|
||||||
|
@ -201,14 +206,31 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue ->
|
this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue ->
|
||||||
keyValueMap.put(keyValue.getName(), keyValue.getValue())
|
keyValueMap.put(keyValue.getName(), keyValue.getValue())
|
||||||
);
|
);
|
||||||
|
// 这块是否使用jmeter自身机制?
|
||||||
|
Map<String, String> pubKeyValueMap = new HashMap<>();
|
||||||
|
if (config != null && config.getVariables() != null) {
|
||||||
|
config.getVariables().stream().forEach(keyValue -> {
|
||||||
|
pubKeyValueMap.put(keyValue.getName(), keyValue.getValue());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (String key : keyValueMap.keySet()) {
|
||||||
|
if (keyValueMap.get(key) != null && keyValueMap.get(key).startsWith("$")) {
|
||||||
|
String pubKey = keyValueMap.get(key).substring(2, keyValueMap.get(key).length() - 1);
|
||||||
|
keyValueMap.put(key, pubKeyValueMap.get(pubKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})");
|
Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})");
|
||||||
Matcher m = p.matcher(path);
|
Matcher m = p.matcher(path);
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
while (m.find()) {
|
try {
|
||||||
String group = m.group(2);
|
while (m.find()) {
|
||||||
//替换并且把替换好的值放到sb中
|
String group = m.group(2);
|
||||||
m.appendReplacement(sb, keyValueMap.get(group));
|
//替换并且把替换好的值放到sb中
|
||||||
|
m.appendReplacement(sb, keyValueMap.get(group));
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
//把符合的数据追加到sb尾
|
//把符合的数据追加到sb尾
|
||||||
m.appendTail(sb);
|
m.appendTail(sb);
|
||||||
|
|
|
@ -2,14 +2,15 @@
|
||||||
<div class="text-container">
|
<div class="text-container">
|
||||||
<el-collapse-transition>
|
<el-collapse-transition>
|
||||||
<el-tabs v-model="activeName" v-show="isActive">
|
<el-tabs v-model="activeName" v-show="isActive">
|
||||||
<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
|
|
||||||
<pre>{{ response.headers }}</pre>
|
|
||||||
</el-tab-pane>
|
|
||||||
|
|
||||||
<el-tab-pane :class="'body-pane'" :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
|
<el-tab-pane :class="'body-pane'" :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
|
||||||
<ms-sql-result-table v-if="isSqlType" :body="response.body"/>
|
<ms-sql-result-table v-if="isSqlType" :body="response.body"/>
|
||||||
<ms-code-edit v-if="!isSqlType" :mode="mode" :read-only="true" :data="response.body" :modes="modes" ref="codeEdit"/>
|
<ms-code-edit v-if="!isSqlType" :mode="mode" :read-only="true" :data="response.body" :modes="modes" ref="codeEdit"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
|
||||||
|
<pre>{{ response.headers }}</pre>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
<el-tab-pane :label="$t('api_test.definition.request.console')" name="console" class="pane">
|
<el-tab-pane :label="$t('api_test.definition.request.console')" name="console" class="pane">
|
||||||
<pre>{{response.console}}</pre>
|
<pre>{{response.console}}</pre>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
|
@ -336,7 +336,6 @@
|
||||||
this.operatingElements = ELEMENTS.get("ALL");
|
this.operatingElements = ELEMENTS.get("ALL");
|
||||||
this.getMaintainerOptions();
|
this.getMaintainerOptions();
|
||||||
this.getApiScenario();
|
this.getApiScenario();
|
||||||
this.getEnvironments();
|
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
watch: {}
|
watch: {}
|
||||||
|
@ -680,6 +679,16 @@
|
||||||
this.environments.forEach(environment => {
|
this.environments.forEach(environment => {
|
||||||
parseEnvironment(environment);
|
parseEnvironment(environment);
|
||||||
});
|
});
|
||||||
|
let hasEnvironment = false;
|
||||||
|
for (let i in this.environments) {
|
||||||
|
if (this.environments[i].id === this.currentEnvironmentId) {
|
||||||
|
hasEnvironment = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasEnvironment) {
|
||||||
|
this.currentEnvironmentId = '';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -812,8 +821,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
,
|
|
||||||
getApiScenario() {
|
getApiScenario() {
|
||||||
if (this.currentScenario.tags != undefined && !(this.currentScenario.tags instanceof Array)) {
|
if (this.currentScenario.tags != undefined && !(this.currentScenario.tags instanceof Array)) {
|
||||||
this.currentScenario.tags = JSON.parse(this.currentScenario.tags);
|
this.currentScenario.tags = JSON.parse(this.currentScenario.tags);
|
||||||
|
@ -835,6 +843,7 @@
|
||||||
this.path = "/api/automation/create";
|
this.path = "/api/automation/create";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.getEnvironments();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,7 @@
|
||||||
},
|
},
|
||||||
saveApi(data) {
|
saveApi(data) {
|
||||||
this.setTabTitle(data);
|
this.setTabTitle(data);
|
||||||
this.$refs.apiList[0].initTable(data);
|
this.refresh(data);
|
||||||
},
|
},
|
||||||
|
|
||||||
showExecResult(row) {
|
showExecResult(row) {
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
<div class="text-container">
|
<div class="text-container">
|
||||||
|
|
||||||
<el-tabs v-model="activeName" v-show="isActive">
|
<el-tabs v-model="activeName" v-show="isActive">
|
||||||
<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
|
|
||||||
<pre>{{ response.responseResult.headers }}</pre>
|
|
||||||
</el-tab-pane>
|
|
||||||
<el-tab-pane :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
|
<el-tab-pane :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
|
||||||
<ms-sql-result-table v-if="isSqlType" :body="response.responseResult.body"/>
|
<ms-sql-result-table v-if="isSqlType" :body="response.responseResult.body"/>
|
||||||
<ms-code-edit v-if="!isSqlType" :mode="mode" :read-only="true" :modes="modes" :data.sync="response.responseResult.body" ref="codeEdit"/>
|
<ms-code-edit v-if="!isSqlType" :mode="mode" :read-only="true" :modes="modes" :data.sync="response.responseResult.body" ref="codeEdit"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
|
||||||
|
<pre>{{ response.responseResult.headers }}</pre>
|
||||||
|
</el-tab-pane>
|
||||||
<!--<el-tab-pane label="Cookie" name="cookie" class="pane cookie">-->
|
<!--<el-tab-pane label="Cookie" name="cookie" class="pane cookie">-->
|
||||||
<!--<pre>{{response.cookies}}</pre>-->
|
<!--<pre>{{response.cookies}}</pre>-->
|
||||||
<!--</el-tab-pane>-->
|
<!--</el-tab-pane>-->
|
||||||
|
@ -80,7 +81,7 @@
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
activeName: "headers",
|
activeName: "body",
|
||||||
modes: ['text', 'json', 'xml', 'html'],
|
modes: ['text', 'json', 'xml', 'html'],
|
||||||
sqlModes: ['text', 'table'],
|
sqlModes: ['text', 'table'],
|
||||||
mode: BODY_FORMAT.TEXT
|
mode: BODY_FORMAT.TEXT
|
||||||
|
|
|
@ -217,6 +217,7 @@
|
||||||
let url = "/api/definition/update";
|
let url = "/api/definition/update";
|
||||||
let bodyFiles = this.getBodyUploadFiles();
|
let bodyFiles = this.getBodyUploadFiles();
|
||||||
this.api.method = this.api.request.method;
|
this.api.method = this.api.request.method;
|
||||||
|
this.api.path = this.api.request.path;
|
||||||
this.$fileUpload(url, null, bodyFiles, this.api, () => {
|
this.$fileUpload(url, null, bodyFiles, this.api, () => {
|
||||||
this.$success(this.$t('commons.save_success'));
|
this.$success(this.$t('commons.save_success'));
|
||||||
this.$emit('saveApi', this.api);
|
this.$emit('saveApi', this.api);
|
||||||
|
@ -273,7 +274,7 @@
|
||||||
environmentConfigClose() {
|
environmentConfigClose() {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
},
|
||||||
refresh(){
|
refresh() {
|
||||||
this.$emit('refresh');
|
this.$emit('refresh');
|
||||||
},
|
},
|
||||||
getResult() {
|
getResult() {
|
||||||
|
|
Loading…
Reference in New Issue