refactor(接口测试): 场景中生成报告优化

--bug=1011491 --user=赵勇 【接口测试】场景-编辑-点击生成报告到弹出报告页面时间较长 https://www.tapd.cn/55049933/s/1122486
This commit is contained in:
fit2-zhao 2022-03-21 19:22:46 +08:00 committed by CountryBuilder
parent 9ddcb35344
commit af4b298296
4 changed files with 49 additions and 30 deletions

View File

@ -347,6 +347,8 @@ public class ApiScenarioExecuteService {
String reportType = request.getConfig() != null ? request.getConfig().getReportType() : null; String reportType = request.getConfig() != null ? request.getConfig().getReportType() : null;
if (scenario != null) { if (scenario != null) {
report.setVersionId(scenario.getVersionId()); 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); reportStructureService.save(scenario, report.getId(), reportType);
} else { } else {
if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) { if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) {

View File

@ -403,8 +403,12 @@ export default {
scenarioDefinition: t.currentScenario.scenarioDefinition scenarioDefinition: t.currentScenario.scenarioDefinition
}; };
let v3 = JSON.parse(JSON.stringify(v2)); let v3 = JSON.parse(JSON.stringify(v2));
this.deleteResourceIds(v1.scenarioDefinition); if (v1.scenarioDefinition) {
this.deleteResourceIds(v3.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))); let delta = jsondiffpatch.diff(JSON.parse(JSON.stringify(v1)), JSON.parse(JSON.stringify(v3)));
if (delta) { if (delta) {
this.isSave = true; this.isSave = true;
@ -560,7 +564,9 @@ export default {
} }
}, },
refresh(data) { refresh(data) {
this.setTabTitle(data); if (data) {
this.setTabTitle(data);
}
this.isSave = true; this.isSave = true;
}, },
refreshTree() { refreshTree() {

View File

@ -128,12 +128,17 @@ export default {
this.isRequestResult = false; this.isRequestResult = false;
}, },
created() { created() {
if (this.scenario && this.scenario.scenarioDefinition) {
this.content.scenarioStepTotal = this.scenario.scenarioDefinition.hashTree.length; },
this.initTree(); mounted() {
this.initMessageSocket(); this.$nextTick(() => {
this.clearDebug(); if (this.scenario && this.scenario.scenarioDefinition) {
} this.content.scenarioStepTotal = this.scenario.scenarioDefinition.hashTree.length;
this.initTree();
this.initMessageSocket();
this.clearDebug();
}
});
}, },
props: { props: {
reportId: String, reportId: String,
@ -208,7 +213,7 @@ export default {
this.$refs.failsTree.filter(index); this.$refs.failsTree.filter(index);
} else if (this.activeName === "errorReport") { } else if (this.activeName === "errorReport") {
this.$refs.errorReportTree.filter("errorReport"); this.$refs.errorReportTree.filter("errorReport");
} else if(this.activeName === "unExecute"){ } else if (this.activeName === "unExecute") {
this.$refs.unExecuteTree.filter("unexecute"); this.$refs.unExecuteTree.filter("unexecute");
} }
}, },

View File

@ -972,18 +972,18 @@ export default {
} }
/*触发执行操作*/ /*触发执行操作*/
this.$refs['currentScenario'].validate(async (valid) => { this.$refs['currentScenario'].validate(async (valid) => {
if (valid) { if (valid) {
this.debugLoading = true; this.debugLoading = true;
let definition = JSON.parse(JSON.stringify(this.currentScenario)); let definition = JSON.parse(JSON.stringify(this.currentScenario));
definition.hashTree = this.scenarioDefinition; definition.hashTree = this.scenarioDefinition;
await this.getEnv(JSON.stringify(definition)); await this.getEnv(JSON.stringify(definition));
await this.$refs.envPopover.initEnv(); await this.$refs.envPopover.initEnv();
const sign = await this.$refs.envPopover.checkEnv(this.isFullUrl); const sign = await this.$refs.envPopover.checkEnv(this.isFullUrl);
if (!sign) { if (!sign) {
this.debugLoading = false; this.debugLoading = false;
return; return;
} }
this.editScenario().then(() => { this.initParameter();
this.debugData = { this.debugData = {
id: this.currentScenario.id, id: this.currentScenario.id,
name: this.currentScenario.name, name: this.currentScenario.name,
@ -999,9 +999,10 @@ export default {
this.reportId = getUUID().substring(0, 8); this.reportId = getUUID().substring(0, 8);
this.debugLoading = false; this.debugLoading = false;
this.pluginDelStep = false; this.pluginDelStep = false;
}) this.$emit('refresh');
}
} }
}) )
}, },
validatePluginData(steps) { validatePluginData(steps) {
steps.forEach(step => { steps.forEach(step => {
@ -1621,7 +1622,7 @@ export default {
} }
} }
}, },
async setParameter() { initParameter() {
this.currentScenario.stepTotal = this.scenarioDefinition.length; this.currentScenario.stepTotal = this.scenarioDefinition.length;
if (!this.currentScenario.projectId) { if (!this.currentScenario.projectId) {
this.currentScenario.projectId = this.projectId; this.currentScenario.projectId = this.projectId;
@ -1646,11 +1647,6 @@ export default {
this.formatData(scenario.hashTree); this.formatData(scenario.hashTree);
} }
this.currentScenario.environmentType = this.environmentType; 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.environmentJson = JSON.stringify(strMapToObj(this.projectEnvMap));
this.currentScenario.environmentGroupId = this.envGroupId; this.currentScenario.environmentGroupId = this.envGroupId;
this.currentScenario.scenarioDefinition = scenario; this.currentScenario.scenarioDefinition = scenario;
@ -1662,6 +1658,14 @@ export default {
this.currentScenario.apiScenarioModuleId = this.currentModule.id; 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() { runRefresh() {
if (!this.debug) { if (!this.debug) {
this.debugVisible = true; this.debugVisible = true;
@ -1679,6 +1683,7 @@ export default {
this.runScenario = undefined; this.runScenario = undefined;
this.message = "stop"; this.message = "stop";
this.clearMessage = getUUID().substring(0, 8); this.clearMessage = getUUID().substring(0, 8);
this.debugData = {};
}, },
showScenarioParameters() { showScenarioParameters() {
this.$refs.scenarioParameters.open(this.currentScenario.variables, this.currentScenario.headers); this.$refs.scenarioParameters.open(this.currentScenario.variables, this.currentScenario.headers);
@ -1726,6 +1731,7 @@ export default {
}, },
detailRefresh(result) { detailRefresh(result) {
// //
this.debugData = {};
}, },
fullScreen() { fullScreen() {
this.drawer = true; this.drawer = true;