diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 9841e5c3e8..a4221c3d24 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -347,6 +347,8 @@ public class ApiScenarioExecuteService { String reportType = request.getConfig() != null ? request.getConfig().getReportType() : null; if (scenario != null) { report.setVersionId(scenario.getVersionId()); + String scenarioDefinition = JSON.toJSONString(request.getTestElement().getHashTree().get(0).getHashTree().get(0)); + scenario.setScenarioDefinition(scenarioDefinition); reportStructureService.save(scenario, report.getId(), reportType); } else { if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) { diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index fef9f371cb..670766485e 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -403,8 +403,12 @@ export default { scenarioDefinition: t.currentScenario.scenarioDefinition }; let v3 = JSON.parse(JSON.stringify(v2)); - this.deleteResourceIds(v1.scenarioDefinition); - this.deleteResourceIds(v3.scenarioDefinition); + if (v1.scenarioDefinition) { + this.deleteResourceIds(v1.scenarioDefinition); + } + if (v3.scenarioDefinition) { + this.deleteResourceIds(v3.scenarioDefinition); + } let delta = jsondiffpatch.diff(JSON.parse(JSON.stringify(v1)), JSON.parse(JSON.stringify(v3))); if (delta) { this.isSave = true; @@ -560,7 +564,9 @@ export default { } }, refresh(data) { - this.setTabTitle(data); + if (data) { + this.setTabTitle(data); + } this.isSave = true; }, refreshTree() { diff --git a/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue b/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue index f608085091..8b6e879f21 100644 --- a/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue +++ b/frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue @@ -128,12 +128,17 @@ export default { this.isRequestResult = false; }, created() { - if (this.scenario && this.scenario.scenarioDefinition) { - this.content.scenarioStepTotal = this.scenario.scenarioDefinition.hashTree.length; - this.initTree(); - this.initMessageSocket(); - this.clearDebug(); - } + + }, + mounted() { + this.$nextTick(() => { + if (this.scenario && this.scenario.scenarioDefinition) { + this.content.scenarioStepTotal = this.scenario.scenarioDefinition.hashTree.length; + this.initTree(); + this.initMessageSocket(); + this.clearDebug(); + } + }); }, props: { reportId: String, @@ -208,7 +213,7 @@ export default { this.$refs.failsTree.filter(index); } else if (this.activeName === "errorReport") { this.$refs.errorReportTree.filter("errorReport"); - } else if(this.activeName === "unExecute"){ + } else if (this.activeName === "unExecute") { this.$refs.unExecuteTree.filter("unexecute"); } }, diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index ef72ed377b..4286bf59de 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -972,18 +972,18 @@ export default { } /*触发执行操作*/ this.$refs['currentScenario'].validate(async (valid) => { - if (valid) { - this.debugLoading = true; - let definition = JSON.parse(JSON.stringify(this.currentScenario)); - definition.hashTree = this.scenarioDefinition; - await this.getEnv(JSON.stringify(definition)); - await this.$refs.envPopover.initEnv(); - const sign = await this.$refs.envPopover.checkEnv(this.isFullUrl); - if (!sign) { - this.debugLoading = false; - return; - } - this.editScenario().then(() => { + if (valid) { + this.debugLoading = true; + let definition = JSON.parse(JSON.stringify(this.currentScenario)); + definition.hashTree = this.scenarioDefinition; + await this.getEnv(JSON.stringify(definition)); + await this.$refs.envPopover.initEnv(); + const sign = await this.$refs.envPopover.checkEnv(this.isFullUrl); + if (!sign) { + this.debugLoading = false; + return; + } + this.initParameter(); this.debugData = { id: this.currentScenario.id, name: this.currentScenario.name, @@ -999,9 +999,10 @@ export default { this.reportId = getUUID().substring(0, 8); this.debugLoading = false; this.pluginDelStep = false; - }) + this.$emit('refresh'); + } } - }) + ) }, validatePluginData(steps) { steps.forEach(step => { @@ -1621,7 +1622,7 @@ export default { } } }, - async setParameter() { + initParameter() { this.currentScenario.stepTotal = this.scenarioDefinition.length; if (!this.currentScenario.projectId) { this.currentScenario.projectId = this.projectId; @@ -1646,11 +1647,6 @@ export default { this.formatData(scenario.hashTree); } this.currentScenario.environmentType = this.environmentType; - let definition = JSON.parse(JSON.stringify(this.currentScenario)); - definition.hashTree = this.scenarioDefinition; - await this.getEnv(JSON.stringify(definition)); - // 保存时同步所需要的项目环境 - savePreciseEnvProjectIds(this.projectIds, this.projectEnvMap); this.currentScenario.environmentJson = JSON.stringify(strMapToObj(this.projectEnvMap)); this.currentScenario.environmentGroupId = this.envGroupId; this.currentScenario.scenarioDefinition = scenario; @@ -1662,6 +1658,14 @@ export default { this.currentScenario.apiScenarioModuleId = this.currentModule.id; } }, + async setParameter() { + this.initParameter(); + let definition = JSON.parse(JSON.stringify(this.currentScenario)); + definition.hashTree = this.scenarioDefinition; + await this.getEnv(JSON.stringify(definition)); + // 保存时同步所需要的项目环境 + savePreciseEnvProjectIds(this.projectIds, this.projectEnvMap); + }, runRefresh() { if (!this.debug) { this.debugVisible = true; @@ -1679,6 +1683,7 @@ export default { this.runScenario = undefined; this.message = "stop"; this.clearMessage = getUUID().substring(0, 8); + this.debugData = {}; }, showScenarioParameters() { this.$refs.scenarioParameters.open(this.currentScenario.variables, this.currentScenario.headers); @@ -1726,6 +1731,7 @@ export default { }, detailRefresh(result) { // 把执行结果分发给各个请求 + this.debugData = {}; }, fullScreen() { this.drawer = true;