fix(接口自动化): 修复特殊URL执行问题,如url结尾时?执行时 ?丢失

This commit is contained in:
fit2-zhao 2021-07-19 18:32:43 +08:00 committed by 刘瑞斌
parent 9a52ccc629
commit 102b895943
3 changed files with 23 additions and 14 deletions

View File

@ -312,7 +312,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setPort(urlObject.getPort());
}
sampler.setProtocol(urlObject.getProtocol());
sampler.setPath(URLDecoder.decode(URLEncoder.encode(urlObject.getPath(), "UTF-8"), "UTF-8"));
sampler.setPath(URLDecoder.decode(URLEncoder.encode(urlObject.getFile(), "UTF-8"), "UTF-8"));
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
}
@ -324,7 +324,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
String envPath = "";
if (!isCustomizeReqCompleteUrl(this.path)) {
URL urlObject = new URL(url);
envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile();
if (StringUtils.isNotBlank(this.getPath())) {
envPath += this.getPath();
}
@ -338,7 +338,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setPort(httpConfig.getPort());
} else {
URL urlObject = new URL(this.path);
envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile();
sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8"));
sampler.setProtocol(urlObject.getProtocol());
}
@ -385,7 +385,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setPort(urlObject.getPort());
}
sampler.setProtocol(urlObject.getProtocol());
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getFile();
sampler.setPath(envPath);
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
envPath = getRestParameters(URLDecoder.decode(URLEncoder.encode(envPath, "UTF-8"), "UTF-8"));

View File

@ -1040,7 +1040,9 @@ public class ApiAutomationService {
public void run() {
List<String> reportIds = new LinkedList<>();
for (APIScenarioReportResult key : map.keySet()) {
key.setExecuteType(ExecuteType.Marge.name());
if (StringUtils.isNotEmpty(serialReportId)) {
key.setExecuteType(ExecuteType.Marge.name());
}
apiScenarioReportMapper.insert(key);
reportIds.add(key.getId());
try {

View File

@ -13,7 +13,7 @@
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
</el-select>
</el-input>
<el-checkbox v-if="isCustomizeReq" class="is-ref-environment" v-model="request.isRefEnvironment">{{$t('api_test.request.refer_to_environment')}}</el-checkbox>
<el-checkbox v-if="isCustomizeReq" class="is-ref-environment" v-model="request.isRefEnvironment">{{ $t('api_test.request.refer_to_environment') }}</el-checkbox>
</div>
<div v-if="request.protocol === 'TCP' && isCustomizeReq">
@ -45,6 +45,7 @@ export default {
data() {
return {
reqOptions: REQ_METHOD,
isUrl: false,
}
},
mounted() {
@ -69,20 +70,25 @@ export default {
},
methods: {
pathChange() {
this.isUrl = false;
if (!this.request.path || this.request.path.indexOf('?') === -1) return;
let url = this.getURL(this.addProtocol(this.request.path));
if (url) {
if (url && this.isUrl) {
this.request.path = decodeURIComponent(this.request.path.substr(0, this.request.path.indexOf("?")));
}
},
urlChange() {
this.isUrl = false;
if (this.isCustomizeReq) {
this.request.path = this.request.url;
}
if (!this.request.url || this.request.url.indexOf('?') === -1) return;
let url = this.getURL(this.addProtocol(this.request.url));
if (url) {
this.request.url = decodeURIComponent(this.request.url.substr(0, this.request.url.indexOf("?")));
let paramUrl = this.request.url.substr(this.request.url.indexOf("?") + 1);
if (paramUrl && this.isUrl) {
this.request.url = decodeURIComponent(this.request.url.substr(0, this.request.url.indexOf("?")));
}
}
},
addProtocol(url) {
@ -98,6 +104,7 @@ export default {
let url = new URL(urlStr);
url.searchParams.forEach((value, key) => {
if (key && value) {
this.isUrl = true;
this.request.arguments.splice(0, 0, new KeyValue({name: key, required: false, value: value}));
}
});
@ -111,11 +118,11 @@ export default {
</script>
<style scoped>
.server-input {
width: 50%;
}
.server-input {
width: 50%;
}
.is-ref-environment {
margin-left: 15px;
}
.is-ref-environment {
margin-left: 15px;
}
</style>