feat(接口自动化): 场景步骤跨项目添加接口

This commit is contained in:
shiziyuan9527 2021-02-26 18:24:59 +08:00
parent b5d7140aa8
commit 532007f25d
10 changed files with 116 additions and 88 deletions

View File

@ -437,11 +437,9 @@ public class ApiDefinitionService {
Map<String, EnvironmentConfig> envConfig = new HashMap<>();
Map<String, String> map = request.getEnvironmentMap();
if (map != null && map.size() > 0) {
map.keySet().forEach(id -> {
ApiTestEnvironmentWithBLOBs environment = environmentService.get(map.get(id));
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
envConfig.put(id, env);
});
ApiTestEnvironmentWithBLOBs environment = environmentService.get(map.get(request.getProjectId()));
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
envConfig.put(request.getProjectId(), env);
config.setConfig(envConfig);
}

View File

@ -150,14 +150,14 @@
break;
}
},
list() {
list(projectId) {
let url = undefined;
if (this.isPlanModel) {
url = '/api/automation/module/list/plan/' + this.planId;
} else if (this.isRelevanceModel) {
url = "/api/automation/module/list/" + this.relevanceProjectId;
} else {
url = "/api/automation/module/list/" + this.projectId;
url = "/api/automation/module/list/" + (projectId ? projectId : this.projectId);
if (!this.projectId) {
return;
}

View File

@ -1,8 +1,11 @@
<template>
<relevance-dialog :title="$t('api_test.definition.api_import')" ref="relevanceDialog">
<test-case-relevance-base
@setProject="setProject"
:dialog-title="$t('api_test.definition.api_import')"
ref="baseRelevance">
<template v-slot:aside>
<ms-api-module
style="margin-top: 5px;"
@nodeSelectEvent="nodeChange"
@protocolChange="handleProtocolChange"
@refreshTable="refresh"
@ -13,6 +16,7 @@
<scenario-relevance-api-list
v-if="isApiListEnable"
:project-id="projectId"
:current-protocol="currentProtocol"
:select-node-ids="selectNodeIds"
:is-api-list-enable="isApiListEnable"
@ -21,6 +25,7 @@
<scenario-relevance-case-list
v-if="!isApiListEnable"
:project-id="projectId"
:current-protocol="currentProtocol"
:select-node-ids="selectNodeIds"
:is-api-list-enable="isApiListEnable"
@ -33,8 +38,7 @@
{{ $t('api_test.scenario.reference') }}
</el-button>
</template>
</relevance-dialog>
</test-case-relevance-base>
</template>
<script>
@ -45,10 +49,12 @@ import MsAsideContainer from "../../../../common/components/MsAsideContainer";
import MsMainContainer from "../../../../common/components/MsMainContainer";
import ScenarioRelevanceApiList from "./RelevanceApiList";
import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog";
import TestCaseRelevanceBase from "@/business/components/track/plan/view/comonents/base/TestCaseRelevanceBase";
export default {
name: "ApiRelevance",
components: {
TestCaseRelevanceBase,
RelevanceDialog,
ScenarioRelevanceApiList,
MsMainContainer, MsAsideContainer, MsContainer, MsApiModule, ScenarioRelevanceCaseList
@ -58,67 +64,82 @@ export default {
result: {},
currentProtocol: null,
selectNodeIds: [],
moduleOptions: {},
isApiListEnable: true,
}
},
methods: {
reference() {
this.save('REF');
},
copy() {
this.save('Copy');
},
save(reference) {
if (this.isApiListEnable) {
this.$emit('save', this.$refs.apiList.selectRows, 'API', reference);
this.close();
} else {
let apiCases = this.$refs.apiCaseList.selectRows;
let ids = Array.from(apiCases).map(row => row.id);
this.result = this.$post("/api/testcase/get/request", {ids: ids}, (response) => {
apiCases.forEach((item) => {
item.request = response.data[item.id];
});
this.$emit('save', apiCases, 'CASE', reference);
this.close();
});
}
},
close() {
this.refresh();
this.$refs.relevanceDialog.close();
},
open() {
if (this.$refs.apiList) {
this.$refs.apiList.clearSelection();
}
if (this.$refs.apiCaseList) {
this.$refs.apiCaseList.clearSelection();
}
this.$refs.relevanceDialog.open();
},
isApiListEnableChange(data) {
this.isApiListEnable = data;
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
handleProtocolChange(protocol) {
this.currentProtocol = protocol;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
refresh() {
if (this.isApiListEnable) {
this.$refs.apiList.initTable();
} else {
this.$refs.apiCaseList.initTable();
}
},
}
moduleOptions: {},
isApiListEnable: true,
projectId: ""
}
},
watch: {
projectId() {
this.refresh();
this.$refs.nodeTree.list(this.projectId);
}
},
methods: {
reference() {
this.save('REF');
},
copy() {
this.save('Copy');
},
save(reference) {
if (this.isApiListEnable) {
let apis = this.$refs.apiList.selectRows;
apis.forEach(api => {
api.projectId = this.projectId;
})
this.$emit('save', this.$refs.apiList.selectRows, 'API', reference);
this.$refs.baseRelevance.close();
} else {
let apiCases = this.$refs.apiCaseList.selectRows;
let ids = Array.from(apiCases).map(row => row.id);
this.result = this.$post("/api/testcase/get/request", {ids: ids}, (response) => {
apiCases.forEach((item) => {
item.request = response.data[item.id];
item.projectId = this.projectId;
});
this.$emit('save', apiCases, 'CASE', reference);
this.$refs.baseRelevance.close();
});
}
},
close() {
this.refresh();
this.$refs.relevanceDialog.close();
},
open() {
if (this.$refs.apiList) {
this.$refs.apiList.clearSelection();
}
if (this.$refs.apiCaseList) {
this.$refs.apiCaseList.clearSelection();
}
this.$refs.baseRelevance.open();
},
isApiListEnableChange(data) {
this.isApiListEnable = data;
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
handleProtocolChange(protocol) {
this.currentProtocol = protocol;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
refresh() {
if (this.isApiListEnable) {
this.$refs.apiList.initTable(this.projectId);
} else {
this.$refs.apiCaseList.initTable(this.projectId);
}
},
setProject(projectId) {
this.projectId = projectId;
},
}
}
</script>
<style scoped>

View File

@ -178,18 +178,19 @@ export default {
isApiListEnableChange(data) {
this.$emit('isApiListEnableChange', data);
},
initTable() {
initTable(projectId) {
this.condition.filters = {status: ["Prepare", "Underway", "Completed"]};
this.condition.moduleIds = this.selectNodeIds;
if (this.trashEnable) {
this.condition.filters = {status: ["Trash"]};
this.condition.moduleIds = [];
}
if (this.projectId != null) {
if (projectId != null && typeof projectId === 'string') {
this.condition.projectId = projectId;
} else if (this.projectId != null) {
this.condition.projectId = this.projectId;
} else {
this.condition.projectId = getCurrentProjectID();
}
if (this.currentProtocol != null) {
this.condition.protocol = this.currentProtocol;
}else{

View File

@ -164,14 +164,13 @@ export default {
isApiListEnableChange(data) {
this.$emit('isApiListEnableChange', data);
},
initTable() {
initTable(projectId) {
this.condition.status = "";
this.condition.moduleIds = this.selectNodeIds;
if (this.projectId != null) {
if (projectId != null && typeof projectId === 'string') {
this.condition.projectId = projectId;
} else if (this.projectId != null) {
this.condition.projectId = this.projectId;
} else {
this.condition.projectId = getCurrentProjectID();
}
if (this.currentProtocol != null) {
this.condition.protocol = this.currentProtocol;

View File

@ -1,9 +1,11 @@
<template>
<test-case-relevance-base
:dialog-title="$t('api_test.automation.scenario_import')"
@setProject="setProject"
ref="baseRelevance">
<template v-slot:aside>
<ms-api-scenario-module
style="margin-top: 5px;"
@nodeSelectEvent="nodeChange"
@refreshTable="refresh"
@setModuleOptions="setModuleOptions"
@ -27,12 +29,9 @@
</template>
<script>
import ScenarioRelevanceCaseList from "./RelevanceCaseList";
import MsApiModule from "../../../definition/components/module/ApiModule";
import MsContainer from "../../../../common/components/MsContainer";
import MsAsideContainer from "../../../../common/components/MsAsideContainer";
import MsMainContainer from "../../../../common/components/MsMainContainer";
import ScenarioRelevanceApiList from "./RelevanceApiList";
import MsApiScenarioModule from "../ApiScenarioModule";
import MsApiScenarioList from "../ApiScenarioList";
import {getUUID} from "../../../../../../common/js/utils";
@ -63,6 +62,7 @@
watch: {
projectId() {
this.$refs.apiScenarioList.search(this.projectId);
this.$refs.nodeTree.list(this.projectId);
}
},
methods: {

View File

@ -104,7 +104,10 @@
if (!this.request.requestResult) {
this.request.requestResult = {responseResult: {}};
}
this.request.projectId = getCurrentProjectID();
// IDID
if (!this.request.projectId) {
this.request.projectId = getCurrentProjectID();
}
//
this.getApiInfo();
if (this.request.protocol === 'HTTP') {

View File

@ -74,7 +74,7 @@ import {getUUID, getBodyUploadFiles, getCurrentProjectID, strMapToObj} from "@/c
//
projectId = this.runData.projectId;
}
let reqObj = {id: this.reportId, testElement: testPlan, type: this.type,projectId:getCurrentProjectID(), environmentMap: strMapToObj(this.envMap)};
let reqObj = {id: this.reportId, testElement: testPlan, type: this.type,projectId: projectId, environmentMap: strMapToObj(this.envMap)};
let bodyFiles = getBodyUploadFiles(reqObj, this.runData);
let url = "";
if (this.debug) {

View File

@ -107,14 +107,14 @@ export default {
}
},
methods: {
list() {
list(projectId) {
let url = undefined;
if (this.isPlanModel) {
url = '/api/module/list/plan/' + this.planId + '/' + this.condition.protocol;
} else if (this.isRelevanceModel) {
url = "/api/module/list/" + this.relevanceProjectId + "/" + this.condition.protocol;
} else {
url = "/api/module/list/" + this.projectId + "/" + this.condition.protocol;
url = "/api/module/list/" + (projectId ? projectId : this.projectId) + "/" + this.condition.protocol;
if (!this.projectId) {
return;
}

View File

@ -1,5 +1,5 @@
<template>
<relevance-dialog :title="$t('test_track.plan_view.relevance_test_case')" ref="relevanceDialog">
<relevance-dialog :title="dialogTitle" ref="relevanceDialog">
<template v-slot:aside>
<select-menu
@ -51,6 +51,12 @@
props: {
planId: {
type: String
},
dialogTitle: {
type: String,
default() {
return this.$t('test_track.plan_view.relevance_test_case');
}
}
},
watch: {