fix(接口测试): 修复场景调试状态不更新问题

--bug=1009505 --user=赵勇 【github#9177】接口自动化在调试的时候,状态显示有问题 https://www.tapd.cn/55049933/s/1090303
This commit is contained in:
fit2-zhao 2022-01-11 13:02:15 +08:00 committed by 刘瑞斌
parent fe3caea2d9
commit 4504c9a302
9 changed files with 48 additions and 40 deletions

View File

@ -202,9 +202,8 @@ public class ApiAutomationController {
@MsAuditLog(module = "api_automation", type = OperLogConstants.DEBUG, title = "#request.scenarioName", sourceId = "#request.scenarioId", project = "#request.projectId")
public void runDebug(@RequestPart("request") RunDefinitionRequest request,
@RequestPart(value = "bodyFiles", required = false) List<MultipartFile> bodyFiles, @RequestPart(value = "scenarioFiles", required = false) List<MultipartFile> scenarioFiles) {
request.setExecuteType(ExecuteType.Debug.name());
if (request.isSaved()) {
request.setExecuteType(ExecuteType.Saved.name());
if (StringUtils.isEmpty(request.getExecuteType())) {
request.setExecuteType(ExecuteType.Debug.name());
}
apiAutomationService.debugRun(request, bodyFiles, scenarioFiles);
}

View File

@ -377,21 +377,23 @@ public class ApiScenarioExecuteService {
} catch (Exception e) {
MSException.throwException(e.getMessage());
}
APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
SessionUtils.getUserId(), request.getConfig(), request.getId());
apiScenarioReportMapper.insert(report);
if (request.isSaved()) {
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId());
apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null);
} else {
if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) {
ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs();
scenario.setId(request.getScenarioId());
MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0);
if (testElement != null) {
scenario.setName(testElement.getName());
scenario.setScenarioDefinition(JSON.toJSONString(testElement));
apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null);
APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
SessionUtils.getUserId(), request.getConfig(), request.getId());
apiScenarioReportMapper.insert(report);
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId());
if (scenarioWithBLOBs != null) {
apiScenarioReportStructureService.save(scenarioWithBLOBs, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null);
} else {
if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) {
ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs();
scenario.setId(request.getScenarioId());
MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0);
if (testElement != null) {
scenario.setName(testElement.getName());
scenario.setScenarioDefinition(JSON.toJSONString(testElement));
apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null);
}
}
}
}

View File

@ -78,16 +78,8 @@ public class ApiScenarioReportStructureService {
JSONObject element = JSON.parseObject(apiScenario.getScenarioDefinition());
StepTreeDTO dto = null;
if (element != null && element.getBoolean("enable")) {
String referenced = element.getString("referenced");
element = getRefElement(element);
String type = element.getString("type");
if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) {
if (StringUtils.equals(element.getString("type"), "scenario")) {
ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id"));
if (scenarioWithBLOBs != null) {
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
}
}
}
String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id");
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
if (StringUtils.isNotEmpty(resourceId) && StringUtils.isNotEmpty(apiScenario.getId()) && !resourceId.contains(apiScenario.getId())) {
@ -104,19 +96,24 @@ public class ApiScenarioReportStructureService {
return dto;
}
private static JSONObject getRefElement(JSONObject element) {
String referenced = element.getString("referenced");
if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) {
if (StringUtils.equals(element.getString("type"), "scenario")) {
ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id"));
if (scenarioWithBLOBs != null) {
return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
}
}
}
return element;
}
public static void dataFormatting(JSONArray hashTree, StepTreeDTO dto, String id, String reportType) {
for (int i = 0; i < hashTree.size(); i++) {
JSONObject element = hashTree.getJSONObject(i);
if (element != null && element.getBoolean("enable")) {
String referenced = element.getString("referenced");
if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) {
if (StringUtils.equals(element.getString("type"), "scenario")) {
ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id"));
if (scenarioWithBLOBs != null) {
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
}
}
}
element = getRefElement(element);
String type = element.getString("type");
String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id");
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
@ -217,6 +214,11 @@ public class ApiScenarioReportStructureService {
dto.setErrorCode(reportResults.get(0).getErrorCode());
}
}
if (StringUtils.isNotEmpty(dto.getType()) && requests.contains(dto.getType()) && dto.getValue() == null) {
RequestResult requestResult = new RequestResult();
requestResult.setName(dto.getLabel());
dto.setValue(requestResult);
}
if (CollectionUtils.isNotEmpty(dto.getChildren())) {
reportFormatting(dto.getChildren(), maps);
if (StringUtils.isEmpty(dto.getErrorCode())) {

View File

@ -283,7 +283,7 @@
:dialog-title="$t('test_track.case.batch_edit_case')"/>
<batch-move @refresh="search" @moveSave="moveSave" ref="testBatchMove"/>
<ms-run-mode @handleRunBatch="handleRunBatch" :request="runRequest" ref="runMode"/>
<ms-run :debug="true" :environment="projectEnvMap" @runRefresh="runRefresh" :reportId="reportId" :saved="true"
<ms-run :debug="true" :environment="projectEnvMap" @runRefresh="runRefresh" :reportId="reportId" :saved="true" :executeType="'Saved'"
:environment-type="environmentType" :environment-group-id="envGroupId"
:run-data="debugData" ref="runTest"/>
<ms-task-center ref="taskCenter" :show-menu="false"/>

View File

@ -12,6 +12,7 @@ export default {
components: {},
props: {
environment: Map,
executeType: String,
runMode: String,
debug: Boolean,
reportId: String,
@ -70,7 +71,7 @@ export default {
testPlan.hashTree.push(threadGroup);
this.sort(testPlan.hashTree);
let reqObj = {
id: this.reportId, reportId: this.reportId, scenarioName: this.runData.name, saved: this.saved, runMode: this.runMode,
id: this.reportId, reportId: this.reportId, scenarioName: this.runData.name, saved: this.saved, runMode: this.runMode, executeType: this.executeType,
scenarioId: this.runData.id, testElement: testPlan, projectId: getCurrentProjectID(), environmentMap: strMapToObj(map),
environmentType: this.environmentType, environmentGroupId: this.environmentGroupId, environmentJson: JSON.stringify(strMapToObj(map))
};

View File

@ -268,7 +268,7 @@
<api-environment-config v-if="type!=='detail'" ref="environmentConfig" @close="environmentConfigClose"/>
<!--执行组件-->
<ms-run :debug="true" v-if="type!=='detail'" :environment="projectEnvMap" :reportId="reportId" :saved="!debug"
<ms-run :debug="true" v-if="type!=='detail'" :environment="projectEnvMap" :reportId="reportId" :saved="saved"
:run-data="debugData" :environment-type="environmentType" :environment-group-id="envGroupId"
@runRefresh="runRefresh" @errorRefresh="errorRefresh" ref="runTest"/>
<!-- 调试结果 -->
@ -488,6 +488,7 @@ export default {
loading: false
},
debug: false,
saved: false,
debugLoading: false,
reqTotal: 0,
reqSuccess: 0,
@ -1201,6 +1202,7 @@ export default {
this.clearResult(this.scenarioDefinition);
this.clearNodeStatus(this.$refs.stepTree.root.childNodes);
this.sort();
this.saved = runScenario && runScenario.stepScenario ? false : true;
/*触发执行操作*/
this.$refs.currentScenario.validate(async (valid) => {
if (valid) {

View File

@ -342,6 +342,7 @@ export default {
},
methods: {
forStatus() {
this.reqSuccess = true;
if (this.request.result && this.request.result.length > 0) {
this.request.result.forEach(item => {
item.requestResult.forEach(req => {

View File

@ -193,6 +193,7 @@ export default {
this.scenario.run = true;
let runScenario = JSON.parse(JSON.stringify(this.scenario));
runScenario.hashTree = [this.scenario];
runScenario.stepScenario = true;
this.$emit('runScenario', runScenario);
},
formatResult(map, scenarios) {

View File

@ -1,6 +1,6 @@
<template>
<div>
<ms-run :debug="true" :environment="envMap" :reportId="reportId" :runMode="'DEFINITION'" :run-data="debugData" @runRefresh="runRefresh" ref="runTest"/>
<ms-run :debug="true" :environment="envMap" :reportId="reportId" :saved="false" :runMode="'DEFINITION'" :run-data="debugData" @runRefresh="runRefresh" ref="runTest"/>
<api-base-component :if-from-variable-advance="ifFromVariableAdvance" @copy="copyRow" @active="active(controller)" @remove="remove" :data="controller" :draggable="draggable" :is-max="isMax" :show-btn="showBtn" color="#02A7F0" background-color="#F4F4F5" :title="$t('api_test.automation.loop_controller')" v-loading="loading">
<template v-slot:headerLeft>
@ -305,7 +305,7 @@ export default {
if (item.type === "HTTPSamplerProxy" || item.type === "DubboSampler" || item.type === "JDBCSampler" || item.type === "TCPSampler") {
item.activeName = "0";
item.active = true;
item.requestResult = this.requestResult.get(item.resourceId);
item.requestResult = this.requestResult.get(item.id);
}
if (item.hashTree && item.hashTree.length > 0) {
this.setResult(item.hashTree);