fix(测试跟踪): 修复测试计划 导出的场景用例报告显示的不正确的问题

--bug=1012071 --user=宋天阳 【测试跟踪】-测试计划  导出的场景用例报告显示的不正确
https://www.tapd.cn/55049933/s/1132333
This commit is contained in:
song-tianyang 2022-04-11 17:55:25 +08:00 committed by fit2-zhao
parent 9c222f0aea
commit 6d145a49c5
9 changed files with 75 additions and 43 deletions

View File

@ -31,7 +31,7 @@ public class APIScenarioReportController {
@GetMapping("/get/{reportId}")
public APIScenarioReportResult get(@PathVariable String reportId) {
return apiReportService.get(reportId);
return apiReportService.get(reportId,false);
}
@PostMapping("/list/{goPage}/{pageSize}")

View File

@ -126,7 +126,7 @@ public class ApiScenarioReportService {
return scenarioReport;
}
public APIScenarioReportResult get(String reportId) {
public APIScenarioReportResult get(String reportId,boolean selectReportContent) {
ApiDefinitionExecResult result = definitionExecResultMapper.selectByPrimaryKey(reportId);
if (result != null) {
APIScenarioReportResult reportResult = new APIScenarioReportResult();
@ -140,7 +140,7 @@ public class ApiScenarioReportService {
APIScenarioReportResult reportResult = extApiScenarioReportMapper.get(reportId);
if (reportResult != null) {
if (reportResult.getReportVersion() != null && reportResult.getReportVersion() > 1) {
reportResult.setContent(JSON.toJSONString(apiScenarioReportStructureService.assembleReport(reportId)));
reportResult.setContent(JSON.toJSONString(apiScenarioReportStructureService.assembleReport(reportId,selectReportContent)));
} else {
ApiScenarioReportDetail detail = apiScenarioReportDetailMapper.selectByPrimaryKey(reportId);
if (detail != null && reportResult != null) {

View File

@ -286,6 +286,18 @@ public class ApiScenarioReportStructureService {
if (reportResults.size() > 1) {
for (int i = 0; i < reportResults.size(); i++) {
ApiScenarioReportResultWithBLOBs reportResult = reportResults.get(i);
if(reportResult.getContent() != null){
//来自报告导出的数据
if (i == 0) {
dto.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
dto.setErrorCode(reportResults.get(0).getErrorCode());
} else {
StepTreeDTO step = new StepTreeDTO(dto.getLabel(), UUID.randomUUID().toString(), dto.getType(), reportResults.get(i).getId(), (i + 1));
step.setValue(JSON.parseObject(new String(reportResults.get(i).getContent(), StandardCharsets.UTF_8), RequestResult.class));
step.setErrorCode(reportResults.get(i).getErrorCode());
dtoList.add(step);
}
}else {
reportResult = apiScenarioReportResultService.formatScenarioResult(reportResult);
if (i == 0) {
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult);
@ -300,8 +312,14 @@ public class ApiScenarioReportStructureService {
dtoList.add(step);
}
}
}
} else {
ApiScenarioReportResultWithBLOBs reportResult = reportResults.get(0);
if(reportResult.getContent() != null){
String content = new String(reportResults.get(0).getContent(), StandardCharsets.UTF_8);
dto.setValue(JSON.parseObject(content, RequestResult.class));
dto.setErrorCode(reportResults.get(0).getErrorCode());
}else {
reportResult = apiScenarioReportResultService.formatScenarioResult(reportResult);
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO(reportResult);
dto.setStepId(reportResults.get(0).getId());
@ -309,6 +327,7 @@ public class ApiScenarioReportStructureService {
dto.setErrorCode(reportResults.get(0).getErrorCode());
}
}
}
if (StringUtils.isNotEmpty(dto.getType()) && requests.contains(dto.getType()) && dto.getValue() == null || isUiUnExecuteCommand(dto)) {
RequestResultExpandDTO requestResultExpandDTO = new RequestResultExpandDTO();
requestResultExpandDTO.setStatus("unexecute");
@ -517,16 +536,16 @@ public class ApiScenarioReportStructureService {
return reportDTO;
}
public ApiScenarioReportDTO assembleReport(String reportId) {
public ApiScenarioReportDTO assembleReport(String reportId,boolean selectReportContent) {
ApiScenarioReport report = scenarioReportMapper.selectByPrimaryKey(reportId);
if (report != null && report.getReportType().equals(ReportTypeConstants.API_INTEGRATED.name())) {
return this.apiIntegratedReport(reportId);
} else {
return this.getReport(reportId);
return this.getReport(reportId,selectReportContent);
}
}
private ApiScenarioReportDTO getReport(String reportId) {
private ApiScenarioReportDTO getReport(String reportId,boolean selectContent) {
List<ApiScenarioReportResultWithBLOBs> reportResults = null;
ApiScenarioReport report = scenarioReportMapper.selectByPrimaryKey(reportId);
if (report.getReportType() != null && report.getReportType().startsWith("UI")) {
@ -534,6 +553,10 @@ public class ApiScenarioReportStructureService {
example.createCriteria().andReportIdEqualTo(reportId);
reportResults = reportResultMapper.selectByExampleWithBLOBs(example);
removeUiResultIfNotStep(reportResults);
}else if(selectContent){
ApiScenarioReportResultExample example = new ApiScenarioReportResultExample();
example.createCriteria().andReportIdEqualTo(reportId);
reportResults = reportResultMapper.selectByExampleWithBLOBs(example);
}else {
reportResults = this.selectBaseInfoResultByReportId(reportId);
}

View File

@ -170,7 +170,7 @@ public class ShareController {
@GetMapping("/api/scenario/report/get/{shareId}/{reportId}")
public APIScenarioReportResult get(@PathVariable String shareId, @PathVariable String reportId) {
shareInfoService.validateExpired(shareId); // 测试计划和接口都会用这个
return apiScenarioReportService.get(reportId);
return apiScenarioReportService.get(reportId,false);
}
@GetMapping("/performance/report/{shareId}/{reportId}")

View File

@ -496,7 +496,7 @@ public class TestPlanScenarioCaseService {
private void calculateScenarioResultDTO(PlanReportCaseDTO item,
TestPlanScenarioStepCountDTO stepCount) {
if (StringUtils.isNotBlank(item.getReportId())) {
APIScenarioReportResult apiScenarioReportResult = apiScenarioReportService.get(item.getReportId());
APIScenarioReportResult apiScenarioReportResult = apiScenarioReportService.get(item.getReportId(),false);
if (apiScenarioReportResult != null) {
String content = apiScenarioReportResult.getContent();
if (StringUtils.isNotBlank(content)) {

View File

@ -1462,7 +1462,7 @@ public class TestPlanService {
public void buildScenarioResponse(List<TestPlanFailureScenarioDTO> cases) {
if (!CollectionUtils.isEmpty(cases)) {
cases.forEach((item) -> {
item.setResponse(apiScenarioReportService.get(item.getReportId()));
item.setResponse(apiScenarioReportService.get(item.getReportId(),true));
});
}
}

View File

@ -343,8 +343,12 @@ export default {
this.init();
if (this.isTemplate) {
//
if(this.templateReport){
this.handleGetScenarioReport(this.templateReport);
}else {
this.report = this.templateReport;
this.buildReport();
}
} else if (this.isShare) {
getShareScenarioReport(this.shareId, this.reportId, (data) => {
this.checkReport(data);

View File

@ -164,6 +164,13 @@ export default {
},
methods: {
loadRequestInfoExpand() {
if(!this.requestInfo.hasData){
if(this.request.responseResult && this.request.responseResult.body){
this.requestInfo = this.request;
this.requestInfo.hasData = true;
}
}
if(!this.requestInfo.hasData){
this.$get("/api/scenario/report/selectReportContent/" + this.stepId, response => {
let requestResult = response.data;
if (requestResult) {
@ -174,6 +181,8 @@ export default {
this.requestInfo.hasData = true;
});
});
}
},
active() {
if (this.request.unexecute) {
@ -182,12 +191,8 @@ export default {
this.showActive = !this.showActive;
}
if (this.showActive) {
if (this.requestInfo.hasData) {
this.requestInfo.loading = false;
} else {
this.loadRequestInfoExpand();
}
}
},
getName(name) {
if (name && name.indexOf("<->") !== -1) {