diff --git a/frontend/src/business/components/performance/test/EditPerformanceTest.vue b/frontend/src/business/components/performance/test/EditPerformanceTest.vue index 656a867d25..27338c86b5 100644 --- a/frontend/src/business/components/performance/test/EditPerformanceTest.vue +++ b/frontend/src/business/components/performance/test/EditPerformanceTest.vue @@ -126,12 +126,13 @@ export default { let apiTest = this.$store.state.test; if (apiTest && apiTest.name) { this.$set(this.test, "name", apiTest.name); - let blob = new Blob([apiTest.jmx.xml], {type: "application/octet-stream"}); - let suffixIndex = apiTest.jmx.name.lastIndexOf(".jmx"); - let jmxName = apiTest.jmx.name.substring(0, suffixIndex) + "_" + new Date().getTime() + ".jmx"; - let file = new File([blob], jmxName); // 保证每次从接口测试都能创建新的性能测试 - this.$refs.basicConfig.beforeUploadJmx(file); - this.$refs.basicConfig.handleUpload({file: file}); + if (apiTest.jmx.scenarioId) { + this.$refs.basicConfig.importScenario(apiTest.jmx.scenarioId); + this.$refs.basicConfig.handleUpload(); + } + if (apiTest.jmx.caseId) { + this.$refs.basicConfig.importCase(apiTest.jmx); + } if (JSON.stringify(apiTest.jmx.attachFiles) != "{}") { let attachFiles = []; for (let fileID in apiTest.jmx.attachFiles) { diff --git a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue index bd5272b216..418ebf9224 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue @@ -116,6 +116,7 @@ import MsTableOperatorButton from "@/business/components/common/components/MsTab import MsDialogFooter from "@/business/components/common/components/MsDialogFooter"; import ExistFiles from "@/business/components/performance/test/components/ExistFiles"; import ExistScenarios from "@/business/components/performance/test/components/ExistScenarios"; +import {findThreadGroup} from "@/business/components/performance/test/model/ThreadGroup"; export default { name: "PerformanceBasicConfig", @@ -329,12 +330,30 @@ export default { } return true; }, - beforeUploadJmx(file) { - this.$refs.existFiles.beforeUploadFile(file); + importScenario(scenarioId) { + this.$refs.existScenarios.selectIds.add(scenarioId); }, - handleUpload(file) { + importCase(caseObj) { + console.log("case: ", caseObj); + let suffixIndex = caseObj.name.lastIndexOf(".jmx"); + let jmxName = caseObj.name.substring(0, suffixIndex) + "_" + new Date().getTime() + ".jmx"; + let threadGroups = findThreadGroup(caseObj.xml, jmxName); + threadGroups.forEach(tg => { + tg.options = {}; + }); + this.fileChange(threadGroups); + let file = new File([caseObj.xml], jmxName); + this.uploadList.push(file); + this.tableData.push({ + name: file.name, + size: (file.size / 1024).toFixed(2) + ' KB', + type: 'JMX', + updateTime: file.lastModified, + }); + }, + handleUpload() { // 从api创建的测试 - this.$refs.existFiles.handleUpload(file, true); + this.$refs.existScenarios.handleImport(); }, }, }