fix(UI测试): UI报告统计错误

This commit is contained in:
chenjianxing 2022-03-24 13:49:21 +08:00 committed by 刘瑞斌
parent c82acec9c5
commit 7f6fefeea2
3 changed files with 27 additions and 10 deletions

View File

@ -74,14 +74,14 @@ public class ApiScenarioReportResultService {
if (StringUtils.isNoneBlank(header)) {
JSONObject jsonObject = JSONObject.parseObject(header);
for (String resourceId : jsonObject.keySet()) {
apiScenarioReportResultMapper.insert(this.newUiScenarioReportResult(reportId, resourceId, jsonObject.get(resourceId).toString()));
apiScenarioReportResultMapper.insert(this.newUiScenarioReportResult(reportId, resourceId, jsonObject.getJSONObject(resourceId)));
}
}
});
}
}
private ApiScenarioReportResult newUiScenarioReportResult(String reportId, String resourceId, String value) {
private ApiScenarioReportResult newUiScenarioReportResult(String reportId, String resourceId, JSONObject value) {
ApiScenarioReportResult report = new ApiScenarioReportResult();
report.setId(UUID.randomUUID().toString());
report.setResourceId(resourceId);
@ -89,9 +89,9 @@ public class ApiScenarioReportResultService {
report.setTotalAssertions(0L);
report.setPassAssertions(0L);
report.setCreateTime(System.currentTimeMillis());
String status = value.equalsIgnoreCase("OK") ? ExecuteResult.Success.name() : ExecuteResult.Error.name();
String status = value.getBooleanValue("success") ? ExecuteResult.Success.name() : ExecuteResult.Error.name();
report.setStatus(status);
report.setContent(value.getBytes(StandardCharsets.UTF_8));
report.setContent(value.toJSONString().getBytes(StandardCharsets.UTF_8));
return report;
}

View File

@ -18,6 +18,7 @@ import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.RequestResult;
import io.metersphere.utils.LoggerUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -41,7 +42,7 @@ public class ApiScenarioReportStructureService {
@Resource
private ApiDefinitionExecResultMapper definitionExecResultMapper;
private static final List<String> requests = Arrays.asList("HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "JSR223Processor", "AbstractSampler");
private static final List<String> requests = Arrays.asList("HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "JSR223Processor", "AbstractSampler", "MsUiCommand");
private static final List<String> controls = Arrays.asList("Assertions","IfController","ConstantTimer");
public void save(List<ApiScenarioWithBLOBs> apiScenarios, String reportId, String reportType) {
@ -307,7 +308,7 @@ public class ApiScenarioReportStructureService {
if (dto.getValue() instanceof RequestResultExpandDTO && StringUtils.isNotEmpty(((RequestResultExpandDTO) dto.getValue()).getStatus())) {
dto.setTotalStatus(((RequestResultExpandDTO) dto.getValue()).getStatus());
} else if (dto.getValue() != null) {
if (dto.getValue().getError() > 0) {
if (dto.getValue().getError() > 0 || BooleanUtils.isNotTrue(dto.getValue().isSuccess())) {
dto.setTotalStatus("fail");
} else {
dto.setTotalStatus("success");
@ -383,7 +384,20 @@ public class ApiScenarioReportStructureService {
List<StepTreeDTO> unList = dtoList.stream().filter(e -> e.getValue() != null
&& StringUtils.equalsIgnoreCase(e.getTotalStatus(), "unexecute")).collect(Collectors.toList());
Map<String, Integer> map = unList.stream().collect(Collectors.toMap(StepTreeDTO::getResourceId, StepTreeDTO::getIndex));
List<StepTreeDTO> list = dtoList.stream().sorted(Comparator.comparing(x -> x.getValue().getStartTime())).collect(Collectors.toList());
List<StepTreeDTO> list = dtoList.stream()
.sorted(
(x, y) -> {
// 如果开始时间是0即未开始则排后面
if (x.getValue().getStartTime() == 0) {
return -1;
} else {
return x.getValue().getStartTime() - y.getValue().getStartTime() > 0 ? 1 : -1;
}
}
)
.collect(Collectors.toList());
for (int index = 0; index < list.size(); index++) {
if (map.containsKey(list.get(index).getResourceId())) {
Collections.swap(list, index, (map.get(list.get(index).getResourceId()) - 1));

View File

@ -13,7 +13,7 @@
</el-col>
<el-col :span="3">
<span v-if="result" :style="!result.success ? 'color: #FE6F71' : ''">
<span v-if="!isUnexecute" :style="!result.success ? 'color: #FE6F71' : ''">
{{ result.endTime - result.startTime }} ms
</span>
</el-col>
@ -23,7 +23,7 @@
placement="right"
trigger="hover"
popper-class="issues-popover"
v-if="result">
v-if="!isUnexecute">
<el-image
style="width: 100px; height: 100px"
:src="'/resource/ui/get?fileName=' + result.url"
@ -35,7 +35,7 @@
<el-col :span="2">
<div>
<el-tag size="mini" v-if="!result">
<el-tag size="mini" v-if="isUnexecute">
{{ $t('api_test.home_page.detail_card.unexecute') }}
</el-tag>
<el-tag size="mini" type="success" v-else-if="result.success">
@ -68,6 +68,9 @@ export default {
computed: {
label() {
return this.command.label ? commandDefinition[this.command.label].cnName : '';
},
isUnexecute() {
return this.result && this.result.status === 'unexecute';
}
},
data() {