fix(接口测试): 兼容录制的接口导入到场景url被截取问题
This commit is contained in:
parent
de7efd1ee0
commit
aa139a0e21
|
@ -56,7 +56,7 @@ public class MsScenarioParser extends MsAbstractParser<ScenarioImport> {
|
|||
protected ApiScenarioWithBLOBs parsePluginFormat(JSONObject testObject, ApiTestImportRequest importRequest) {
|
||||
LinkedList<MsTestElement> results = new LinkedList<>();
|
||||
testObject.keySet().forEach(tag -> {
|
||||
results.addAll(parseMsHTTPSamplerProxy(testObject, tag));
|
||||
results.addAll(parseMsHTTPSamplerProxy(testObject, tag, true));
|
||||
});
|
||||
MsScenario msScenario = new MsScenario();
|
||||
msScenario.setName(importRequest.getFileName());
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
}
|
||||
}
|
||||
|
||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null ) {// metersphere 格式导入
|
||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null) {// metersphere 格式导入
|
||||
return parseMsFormat(testStr, request);
|
||||
} else { // chrome 插件录制格式导入
|
||||
request.setPlatform(ApiImportPlatform.Plugin.name());
|
||||
|
@ -56,7 +56,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
if (isCreateModule) {
|
||||
moduleId = ApiDefinitionImportUtil.buildModule(this.selectModule, tag, this.projectId).getId();
|
||||
}
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag);
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag, false);
|
||||
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(), msHTTPSamplerProxy.getPath(), msHTTPSamplerProxy.getMethod(), importRequest);
|
||||
apiDefinition.setModuleId(moduleId);
|
||||
|
@ -161,7 +161,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
String path = apiDefinition.getModulePath() == null ? "" : apiDefinition.getModulePath();
|
||||
if (StringUtils.isNotBlank(this.selectModulePath)) {
|
||||
apiDefinition.setModulePath(this.selectModulePath + path);
|
||||
} else if (StringUtils.isBlank(importRequest.getModuleId())){
|
||||
} else if (StringUtils.isBlank(importRequest.getModuleId())) {
|
||||
apiDefinition.setModulePath("/未规划接口" + path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ import java.util.*;
|
|||
|
||||
public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
||||
|
||||
protected List<MsHTTPSamplerProxy> parseMsHTTPSamplerProxy(JSONObject testObject, String tag) {
|
||||
protected List<MsHTTPSamplerProxy> parseMsHTTPSamplerProxy(JSONObject testObject, String tag, boolean isSetUrl) {
|
||||
JSONObject requests = testObject.getJSONObject(tag);
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = new ArrayList<>();
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = new ArrayList<>();
|
||||
requests.keySet().forEach(requestName -> {
|
||||
JSONObject requestObject = requests.getJSONObject(requestName);
|
||||
String path = requestObject.getString("url");
|
||||
|
@ -27,6 +27,9 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
|||
parseBody(requestObject, request.getBody());
|
||||
parseHeader(requestObject, request.getHeaders());
|
||||
parsePath(request);
|
||||
if (isSetUrl) {
|
||||
request.setUrl(path);
|
||||
}
|
||||
msHTTPSamplerProxies.add(request);
|
||||
});
|
||||
return msHTTPSamplerProxies;
|
||||
|
@ -59,6 +62,7 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseHeader(JSONObject requestObject, List<KeyValue> msHeaders) {
|
||||
JSONArray headers = requestObject.getJSONArray("headers");
|
||||
if (CollectionUtils.isNotEmpty(headers)) {
|
||||
|
@ -100,6 +104,7 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
|||
|
||||
/**
|
||||
* 删除没有用例的节点
|
||||
*
|
||||
* @param nodeTree
|
||||
* @param ids
|
||||
* @return
|
||||
|
|
|
@ -5,10 +5,12 @@ import io.metersphere.base.domain.*;
|
|||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -33,13 +35,6 @@ public class RemakeReportService {
|
|||
|
||||
public void remake(JmeterRunRequestDTO request) {
|
||||
try {
|
||||
if (StringUtils.equals(request.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdEqualTo(request.getQueueId()).andTestIdEqualTo(request.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueDetailMapper.class).deleteByExample(example);
|
||||
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).handleQueue(request.getQueueId(), request.getTestId());
|
||||
}
|
||||
// 清理零时报告
|
||||
if (StringUtils.equalsAnyIgnoreCase(request.getRunMode(), ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
||||
ApiDefinitionExecResult result = execResultMapper.selectByPrimaryKey(request.getReportId());
|
||||
|
@ -113,6 +108,17 @@ public class RemakeReportService {
|
|||
}
|
||||
}
|
||||
}
|
||||
// 处理队列
|
||||
if (StringUtils.equals(request.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdEqualTo(request.getQueueId()).andTestIdEqualTo(request.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueDetailMapper.class).deleteByExample(example);
|
||||
ResultDTO dto = new ResultDTO();
|
||||
BeanUtils.copyBean(dto, request);
|
||||
dto.setQueueId(request.getQueueId());
|
||||
dto.setTestId(request.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
<template>
|
||||
<div>
|
||||
<div v-if="request.protocol === 'HTTP'">
|
||||
<div v-if="request.url || isCustomizeReq">
|
||||
<div v-if="isCustomizeReq">
|
||||
<el-select v-model="request.method" class="ms-select" size="small" :disabled="request.disabled">
|
||||
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
|
||||
</el-select>
|
||||
<el-input v-model="request.domain" v-if="request.isRefEnvironment && request.domain" size="small" readonly class="ms-input"/>
|
||||
|
||||
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="request.path"
|
||||
style="width: 50%" size="small" @blur="urlChange" :disabled="request.disabled" v-if="request.isRefEnvironment"/>
|
||||
|
||||
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="request.url"
|
||||
style="width: 50%" size="small" @blur="urlChange" :disabled="request.disabled">
|
||||
</el-input>
|
||||
style="width: 50%" size="small" @blur="urlChange" :disabled="request.disabled" v-else/>
|
||||
<el-checkbox v-if="isCustomizeReq" class="is-ref-environment" v-model="request.isRefEnvironment" @change="setDomain" :disabled="request.disabled">
|
||||
{{ $t('api_test.request.refer_to_environment') }}
|
||||
</el-checkbox>
|
||||
|
@ -55,26 +58,6 @@ export default {
|
|||
isUrl: false,
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.isCustomizeReq) {
|
||||
if (this.request.isRefEnvironment === undefined || this.request.isRefEnvironment === null) {
|
||||
// 兼容旧数据
|
||||
if (this.request.url) {
|
||||
this.$set(this.request, 'isRefEnvironment', false);
|
||||
} else {
|
||||
this.$set(this.request, 'isRefEnvironment', true);
|
||||
}
|
||||
}
|
||||
// url和path设置成一样,根据是否引用环境判断用哪个
|
||||
if (this.request.url) {
|
||||
this.$set(this.request, 'path', this.request.url);
|
||||
|
||||
} else {
|
||||
this.$set(this.request, 'url', this.request.path);
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
pathChange() {
|
||||
this.isUrl = false;
|
||||
|
|
|
@ -256,8 +256,6 @@ export default {
|
|||
this.isShowNum = false;
|
||||
}
|
||||
if (this.request.protocol === 'HTTP') {
|
||||
this.setUrl(this.request.url);
|
||||
this.setUrl(this.request.path);
|
||||
// 历史数据 auth 处理
|
||||
if (this.request.hashTree) {
|
||||
for (let index in this.request.hashTree) {
|
||||
|
|
Loading…
Reference in New Issue