fix(接口定义): 部分缺陷修复

This commit is contained in:
fit2-zhao 2020-12-09 12:25:15 +08:00
parent d3040ee9df
commit 48c69444c7
11 changed files with 60 additions and 22 deletions

View File

@ -102,7 +102,7 @@ public class MsTestElement {
public HashTree generateHashTree() {
HashTree jmeterTestPlanHashTree = new ListedHashTree();
this.toHashTree(jmeterTestPlanHashTree, this.hashTree, null);
this.toHashTree(jmeterTestPlanHashTree, this.hashTree, new ParameterConfig());
return jmeterTestPlanHashTree;
}

View File

@ -28,7 +28,11 @@ import org.apache.jorphan.collections.HashTree;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Data
@EqualsAndHashCode(callSuper = true)
@ -112,8 +116,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
envPath += this.getPath();
}
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
sampler.setPath(getRestParameters(URLDecoder.decode(envPath, "UTF-8")));
} else {
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"));
sampler.setPath(envPath);
}
if (CollectionUtils.isNotEmpty(this.getArguments())) {
sampler.setPath(getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8")));
}
} else {
@ -128,19 +134,22 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
} else {
}
if (CollectionUtils.isNotEmpty(this.getArguments())) {
sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
}
}
} catch (Exception e) {
LogUtil.error(e);
}
// REST参数
if (CollectionUtils.isNotEmpty(this.getArguments())) {
sampler.setArguments(httpArguments(this.getRest()));
}
// 请求参数
if (CollectionUtils.isNotEmpty(this.getArguments())) {
sampler.setArguments(httpArguments(this.getArguments()));
}
// 请求体
if (!StringUtils.equals(this.getMethod(), "GET")) {
List<KeyValue> bodyParams = this.body.getBodyParams(sampler, this.getId());
@ -168,10 +177,22 @@ public class MsHTTPSamplerProxy extends MsTestElement {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(path);
stringBuffer.append("/");
Map<String, String> keyValueMap = new HashMap<>();
this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue ->
stringBuffer.append(keyValue.getValue()).append("/")
keyValueMap.put(keyValue.getName(), keyValue.getValue())
);
return stringBuffer.substring(0, stringBuffer.length() - 1);
Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})");
Matcher m = p.matcher(path);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String group = m.group(2);
//替换并且把替换好的值放到sb中
m.appendReplacement(sb, keyValueMap.get(group));
}
//把符合的数据追加到sb尾
m.appendTail(sb);
return sb.toString();
}
private String getPostQueryParameters(String path) {
@ -214,4 +235,5 @@ public class MsHTTPSamplerProxy extends MsTestElement {
private boolean isRest() {
return this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).toArray().length > 0;
}
}

View File

@ -1,6 +1,6 @@
<template>
<div>
<el-card class="table-card" v-loading="result.loading">
<el-card class="table-card" v-loading="loading">
<template v-slot:header>
<ms-table-header :condition.sync="condition" @search="search" title=""
:show-create="false"/>
@ -45,7 +45,7 @@
</el-table-column>
<el-table-column prop="passRate" :label="$t('api_test.automation.passing_rate')"
show-overflow-tooltip/>
<el-table-column :label="$t('commons.operating')" width="200px">
<el-table-column :label="$t('commons.operating')" width="200px" v-if="!referenced">
<template v-slot:default="{row}">
<el-button type="text" @click="edit(row)">{{ $t('api_test.automation.edit') }}</el-button>
<el-button type="text" @click="execute(row)">{{ $t('api_test.automation.execute') }}</el-button>
@ -53,12 +53,10 @@
<el-button type="text" @click="remove(row)">{{ $t('api_test.automation.remove') }}</el-button>
<ms-scenario-extend-buttons :row="row"/>
</template>
</el-table-column>
</el-table>
<ms-table-pagination :change="search" :current-page.sync="currentPage" :page-size.sync="pageSize"
:total="total"/>
<div>
<!-- 执行结果 -->
<el-drawer :visible.sync="runVisible" :destroy-on-close="true" direction="ltr" :withHeader="false" :title="$t('test_track.plan_view.test_result')" :modal="false" size="90%">
@ -87,10 +85,14 @@
props: {
currentProject: Object,
currentModule: Object,
referenced: {
type: Boolean,
default: false,
}
},
data() {
return {
result: {},
loading: false,
condition: {},
currentScenario: {},
schedule: {},
@ -123,6 +125,7 @@
},
methods: {
search() {
this.loading = true;
this.condition.filters = ["Prepare", "Underway", "Completed"];
if (this.currentModule != null) {
if (this.currentModule.id === "root") {
@ -139,10 +142,11 @@
}
let url = "/api/automation/list/" + this.currentPage + "/" + this.pageSize;
this.result = this.$post(url, this.condition, response => {
this.$post(url, this.condition, response => {
let data = response.data;
this.total = data.itemCount;
this.tableData = data.listObject;
this.loading = false;
});
},
handleCommand(cmd) {
@ -167,7 +171,7 @@
let scenarioIds = this.selection;
run.id = getUUID();
run.scenarioIds = scenarioIds;
this.result = this.$post(url, run, response => {
this.$post(url, run, response => {
let data = response.data;
this.runVisible = true;
this.reportId = run.id;
@ -194,7 +198,7 @@
scenarioIds.push(row.id);
run.id = getUUID();
run.scenarioIds = scenarioIds;
this.result = this.$post(url, run, response => {
this.$post(url, run, response => {
let data = response.data;
this.runVisible = true;
this.reportId = run.id;

View File

@ -342,7 +342,7 @@
debugVisible: false,
customizeRequest: {protocol: "HTTP", type: "API", hashTree: [], referenced: 'Created', active: false},
operatingElements: [],
currentRow: {cases: [], apis: []},
currentRow: {cases: [], apis: [], referenced: true},
selectedTreeNode: undefined,
expandedNode: [],
scenarioDefinition: [],

View File

@ -10,6 +10,7 @@
:current-module="currentModule"
@edit="editScenario"
@selection="setData"
:referenced="true"
ref="apiScenarioList"/>
<el-button style="float: right;margin: 10px" @click="importApiScenario" type="primary">{{ $t('api_test.scenario.reference') }}</el-button>

View File

@ -193,7 +193,7 @@
},
editApi(row) {
this.currentApi = row;
this.handleTabsEdit(row.name, "add");
this.handleTabsEdit(this.$t('api_test.definition.request.edit_api') + "-" + row.name, "add");
},
handleCase(testCase) {
this.currentApi = testCase;
@ -219,7 +219,7 @@
for (let index in this.apiTabs) {
let tab = this.apiTabs[index];
if (tab.name === this.apiDefaultTab) {
tab.title = data.name;
tab.title = this.$t('api_test.definition.request.edit_api') + "-" + data.name;
break;
}
}

View File

@ -402,6 +402,9 @@
test.request = JSON.parse(test.request);
}
this.apiCaseList = response.data;
if (this.apiCaseList.length == 0) {
this.addCase();
}
});
},
validate(row) {

View File

@ -73,9 +73,14 @@
<el-table-column :label="$t('commons.operating')" min-width="130" align="center">
<template v-slot:default="scope">
<el-button type="text" @click="editApi(scope.row)">编辑</el-button>
<el-button type="text" @click="handleTestCase(scope.row)">用例</el-button>
<el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C">删除</el-button>
<div v-if="currentRow!=undefined && currentRow.referenced">
<el-button type="text" @click="handleTestCase(scope.row)">用例</el-button>
</div>
<div v-else>
<el-button type="text" @click="editApi(scope.row)">编辑</el-button>
<el-button type="text" @click="handleTestCase(scope.row)">用例</el-button>
<el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>

View File

@ -529,6 +529,7 @@ export default {
post_script: "Postscript",
extract_param: "Extract parameters",
add_module: "Add module",
edit_api: "Edit Api",
}
},
automation: {

View File

@ -528,6 +528,7 @@ export default {
post_script: "后置脚本",
extract_param: "提取参数",
add_module: "创建模块",
edit_api: "编辑接口",
}
},
automation: {

View File

@ -528,6 +528,7 @@ export default {
post_script: "後置腳本",
extract_param: "提取參數",
add_module: "創建模塊",
edit_api: "编辑接口",
}
},
automation: {