refactor(接口测试): 优化接口用例的展现方式

--bug=1011436 --user=宋天阳 从case列表点编辑默认展开当前用例,无需多点一次
https://www.tapd.cn/55049933/s/1122362
This commit is contained in:
song-tianyang 2022-03-21 16:59:32 +08:00 committed by 刘瑞斌
parent 66f20eef66
commit 39305d436b
2 changed files with 24 additions and 7 deletions

View File

@ -363,7 +363,12 @@ public class ApiScenarioReportStructureService {
ApiDefinitionExecResultVo vo = new ApiDefinitionExecResultVo();
BeanUtils.copyBean(vo, item);
if (StringUtils.isNotEmpty(item.getContent())) {
vo.setRequestResult(JSON.parseObject(item.getContent(), RequestResult.class));
try {
RequestResultExpandDTO resultExpandDTO = JSON.parseObject(item.getContent(), RequestResultExpandDTO.class);
vo.setRequestResult(resultExpandDTO);
} catch (Exception e) {
vo.setRequestResult(JSON.parseObject(item.getContent(), RequestResult.class));
}
if (vo.getRequestResult() != null) {
vo.setPassAssertions(vo.getRequestResult().getPassAssertions());
vo.setTotalAssertions(vo.getRequestResult().getTotalAssertions());
@ -378,6 +383,14 @@ public class ApiScenarioReportStructureService {
}
StepTreeDTO treeDTO = new StepTreeDTO(item.getName(), item.getResourceId(), "API", (i + 1));
treeDTO.setValue(vo.getRequestResult());
if (vo.getRequestResult() != null && vo.getRequestResult() instanceof RequestResultExpandDTO) {
RequestResultExpandDTO expandDTO = (RequestResultExpandDTO) vo.getRequestResult();
if (expandDTO.getAttachInfoMap() != null && expandDTO.getAttachInfoMap().get("errorReportResult") != null) {
treeDTO.setErrorCode(expandDTO.getAttachInfoMap().get("errorReportResult"));
treeDTO.setTotalStatus("errorCode");
}
}
stepList.add(treeDTO);
resultVos.add(vo);
}
@ -398,12 +411,13 @@ public class ApiScenarioReportStructureService {
reportDTO.setTotalAssertions(reportResults.stream().mapToLong(ApiDefinitionExecResultVo::getTotalAssertions).sum());
reportDTO = this.countReportNum(stepList, reportDTO);
reportDTO.setScenarioStepSuccess((reportResults.size() - reportDTO.getError()));
long successStep = reportResults.size() - reportDTO.getError() - reportDTO.getScenarioErrorReport();
reportDTO.setScenarioStepSuccess(successStep > 0 ? successStep : 0);
//统计步骤数据
reportDTO.setScenarioStepTotal(reportResults.size());
reportDTO.setScenarioStepError(reportDTO.getError());
reportDTO.setScenarioStepUnExecuteReport(reportDTO.getUnExecute());
reportDTO.setScenarioStepErrorReport(0);
reportDTO.setScenarioStepErrorReport(reportDTO.getScenarioErrorReport());
ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample();
structureExample.createCriteria().andReportIdEqualTo(reportId);

View File

@ -142,7 +142,7 @@ export default {
// testCaseId
this.testCaseId = testCaseId;
this.condition = {components: API_CASE_CONFIGS};
this.getApiTest(true);
this.getApiTest(true,true);
this.visible = true;
this.$store.state.currentApiCase = undefined;
@ -294,7 +294,7 @@ export default {
})
}
},
getTestCase() {
getTestCase(openCase) {
return new Promise((resolve) => {
let commonUseEnvironment = this.$store.state.useEnvironment;
this.environment = commonUseEnvironment ? commonUseEnvironment : "";
@ -302,6 +302,9 @@ export default {
let apiCase = response.data;
if (apiCase) {
this.formatCase(apiCase);
if(openCase){
apiCase.active = true;
}
this.apiCaseList = [apiCase];
}
resolve();
@ -323,11 +326,11 @@ export default {
});
}
},
getApiTest(addCase) {
getApiTest(addCase,openCase) {
if (this.loaded) {
this.getApiLoadCase();
} else {
this.getTestCase().then(() => {
this.getTestCase(openCase).then(() => {
if (addCase && !this.loaded && this.apiCaseList.length === 0) {
this.addCase();
}