fix(接口自动化): 修复环境匹配取消,执行优化等 问题
This commit is contained in:
parent
006e382d5e
commit
e968eeac46
|
@ -18,12 +18,14 @@ import io.metersphere.api.service.ApiTestCaseService;
|
|||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.TestPlanApiCase;
|
||||
import io.metersphere.commons.constants.ConditionType;
|
||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.ScriptEngineUtils;
|
||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -203,7 +205,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
if (config.isEffective(this.getProjectId())) {
|
||||
HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig(), tree);
|
||||
if (httpConfig == null) {
|
||||
MSException.throwException("未匹配到环境,请检查环境配置");
|
||||
MSException.throwException(this.getName() + " 未匹配到环境,请检查环境配置");
|
||||
}
|
||||
String url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
|
||||
// 补充如果是完整URL 则用自身URL
|
||||
|
@ -424,6 +426,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
tree.add(headerManager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照环境规则匹配环境
|
||||
*
|
||||
|
@ -444,12 +447,22 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
} else if (item.getType().equals(ConditionType.MODULE.name())) {
|
||||
ApiDefinition apiDefinition;
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
if (StringUtils.isNotEmpty(this.getReferenced()) && this.getReferenced().equals("REF") && StringUtils.isNotEmpty(this.getRefType()) && this.getRefType().equals("CASE")) {
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(this.getId());
|
||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||
} else {
|
||||
apiDefinition = apiDefinitionService.get(this.getId());
|
||||
if (apiDefinition == null) {
|
||||
TestPlanApiCaseService testPlanApiCaseService = CommonBeanFactory.getBean(TestPlanApiCaseService.class);
|
||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(this.getId());
|
||||
if (testPlanApiCase != null) {
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
||||
if (caseWithBLOBs != null) {
|
||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apiDefinition != null) {
|
||||
HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId(), item);
|
||||
|
@ -470,7 +483,9 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (httpConfig != null && (StringUtils.isEmpty(httpConfig.getProtocol()) || StringUtils.isEmpty(httpConfig.getSocket()))) {
|
||||
return null;
|
||||
}
|
||||
// 环境中请求头
|
||||
if (httpConfig != null) {
|
||||
Arguments arguments = arguments(httpConfig.getHeaders());
|
||||
|
|
|
@ -189,20 +189,18 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
public int editNode(DragApiScenarioModuleRequest request) {
|
||||
request.setUpdateTime(System.currentTimeMillis());
|
||||
checkApiScenarioModuleExist(request);
|
||||
List<ApiScenarioDTO> apiScenarios = queryByModuleIds(request);
|
||||
|
||||
apiScenarios.forEach(apiScenario -> {
|
||||
StringBuilder path = new StringBuilder(apiScenario.getModulePath());
|
||||
List<String> pathLists = Arrays.asList(path.toString().split("/"));
|
||||
pathLists.set(request.getLevel(), request.getName());
|
||||
path.delete(0, path.length());
|
||||
for (int i = 1; i < pathLists.size(); i++) {
|
||||
path.append("/").append(pathLists.get(i));
|
||||
}
|
||||
apiScenario.setModulePath(path.toString());
|
||||
});
|
||||
|
||||
batchUpdateApiScenario(apiScenarios);
|
||||
// List<ApiScenarioDTO> apiScenarios = queryByModuleIds(request);
|
||||
// apiScenarios.forEach(apiScenario -> {
|
||||
// StringBuilder path = new StringBuilder(apiScenario.getModulePath());
|
||||
// List<String> pathLists = Arrays.asList(path.toString().split("/"));
|
||||
// pathLists.set(request.getLevel(), request.getName());
|
||||
// path.delete(0, path.length());
|
||||
// for (int i = 1; i < pathLists.size(); i++) {
|
||||
// path.append("/").append(pathLists.get(i));
|
||||
// }
|
||||
// apiScenario.setModulePath(path.toString());
|
||||
// });
|
||||
// batchUpdateApiScenario(apiScenarios);
|
||||
|
||||
return apiScenarioModuleMapper.updateByPrimaryKeySelective(request);
|
||||
}
|
||||
|
|
|
@ -95,15 +95,16 @@
|
|||
if (valid) {
|
||||
let path = "/api/automation/create";
|
||||
this.setParameter();
|
||||
this.$fileUpload(path, null, [], this.scenarioForm, () => {
|
||||
if (saveAs) {
|
||||
this.scenarioForm.request = JSON.stringify(this.scenarioForm.request);
|
||||
this.$emit('saveAsEdit', this.scenarioForm);
|
||||
this.visible = false;
|
||||
if (saveAs) {
|
||||
this.scenarioForm.request = JSON.stringify(this.scenarioForm.request);
|
||||
this.$emit('saveAsEdit', this.scenarioForm);
|
||||
} else {
|
||||
} else {
|
||||
this.$fileUpload(path, null, [], this.scenarioForm, () => {
|
||||
this.visible = false;
|
||||
this.$emit('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -117,7 +118,7 @@
|
|||
if (this.currentModule && this.currentModule.id != "root") {
|
||||
this.scenarioForm.modulePath = this.currentModule.method !== undefined ? this.currentModule.method : null;
|
||||
this.scenarioForm.apiScenarioModuleId = this.currentModule.id;
|
||||
}else{
|
||||
} else {
|
||||
this.scenarioForm.modulePath = this.$t("commons.module_title");
|
||||
this.scenarioForm.apiScenarioModuleId = "default-module";
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
result() {
|
||||
this.response = this.result;
|
||||
this.isActive = true;
|
||||
},
|
||||
apiItem(){
|
||||
this.getExecResult();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<template>
|
||||
<div class="request-form">
|
||||
<component :is="component" :isMax="isMax" :show-btn="showBtn"
|
||||
:scenario="scenario" :controller="scenario" :timer="scenario" :assertions="scenario" :extract="scenario" :jsr223-processor="scenario" :request="scenario" :currentScenario="currentScenario" :currentEnvironmentId="currentEnvironmentId" :node="node"
|
||||
:draggable="draggable" :title="title" :color="titleColor" :background-color="backgroundColor" @suggestClick="suggestClick(node)" :response="response"
|
||||
@remove="remove" @copyRow="copyRow" @refReload="refReload" @openScenario="openScenario" :project-list="projectList" :env-map="envMap"/>
|
||||
<keep-alive>
|
||||
<component v-bind:is="component" :isMax="isMax" :show-btn="showBtn"
|
||||
:scenario="scenario" :controller="scenario" :timer="scenario" :assertions="scenario" :extract="scenario" :jsr223-processor="scenario" :request="scenario" :currentScenario="currentScenario" :currentEnvironmentId="currentEnvironmentId" :node="node"
|
||||
:draggable="draggable" :title="title" :color="titleColor" :background-color="backgroundColor" @suggestClick="suggestClick(node)" :response="response"
|
||||
@remove="remove" @copyRow="copyRow" @refReload="refReload" @openScenario="openScenario" :project-list="projectList" :env-map="envMap"/>
|
||||
</keep-alive>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
},
|
||||
methods: {
|
||||
getEnvironments() {
|
||||
let flag = false;
|
||||
if (this.projectId) {
|
||||
this.$get('/api/environment/list/' + this.projectId, response => {
|
||||
this.environments = response.data;
|
||||
|
@ -62,12 +63,16 @@
|
|||
parseEnvironment(environment);
|
||||
if (this.useEnvironment && this.useEnvironment === environment.id) {
|
||||
this.environmentId = this.useEnvironment;
|
||||
flag = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.environmentId = undefined;
|
||||
}
|
||||
if(this.useEnvironment && !flag){
|
||||
this.$emit('setEnvironment', {});
|
||||
}
|
||||
},
|
||||
openEnvironmentConfig() {
|
||||
if (!this.projectId) {
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
<el-row type="flex">
|
||||
<el-col>
|
||||
<div style="font-size: 14px;color: #AAAAAA;float: left">{{$t('api_report.response_code')}} :</div>
|
||||
<div style="font-size: 14px;color:#61C550;margin-top:2px;margin-left:10px;float: left">{{response.responseResult && response.responseResult.responseCode ? response.responseResult.responseCode :'0'}}</div>
|
||||
<el-tooltip
|
||||
:content="response.responseResult.responseCode"
|
||||
placement="top">
|
||||
<div class="node-title">
|
||||
{{response.responseResult && response.responseResult.responseCode ? response.responseResult.responseCode :'0'}}
|
||||
</div>
|
||||
</el-tooltip>
|
||||
</el-col>
|
||||
<el-col>
|
||||
<div style="font-size: 14px;color: #AAAAAA;float: left">{{$t('api_report.response_time')}} :</div>
|
||||
|
@ -37,4 +43,18 @@
|
|||
.metric-container {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.node-title {
|
||||
width: 150px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1 1 auto;
|
||||
padding: 0px 5px;
|
||||
overflow: hidden;
|
||||
font-size: 14px;
|
||||
color: #61C550;
|
||||
margin-top: 2px;
|
||||
margin-left: 10px;
|
||||
float: left
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue