mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-04 04:59:48 +08:00
fix(UI 自动化) 含有循环的步骤一直不出报告结果
--bug=1016617 --user=张大海 【UI测试】场景中含循环步骤-生成报告一直加载中 https://www.tapd.cn/55049933/s/1239868
This commit is contained in:
parent
1c75776ede
commit
1a017e8274
@ -36,7 +36,9 @@ public class PassRateUtil {
|
|||||||
} else {
|
} else {
|
||||||
long successSize = requestResults.stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Success.name())).count();
|
long successSize = requestResults.stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Success.name())).count();
|
||||||
if (report.getReportType().startsWith(SystemConstants.TestTypeEnum.UI.name())) {
|
if (report.getReportType().startsWith(SystemConstants.TestTypeEnum.UI.name())) {
|
||||||
Map<String, String> resultIdMap = requestResults.stream().collect(Collectors.toMap(r -> r.getResourceId(), r -> r.getStatus()));
|
//resourceId -> 结果列表 循环可能一个 resourceId 对应多个接口
|
||||||
|
Map<String, List<ApiScenarioReportResult>> resultResourceStatusMap = requestResults.stream().collect(Collectors.groupingBy(ApiScenarioReportResult::getResourceId));
|
||||||
|
|
||||||
ApiScenarioReportStructureExample e = new ApiScenarioReportStructureExample();
|
ApiScenarioReportStructureExample e = new ApiScenarioReportStructureExample();
|
||||||
e.createCriteria().andReportIdEqualTo(report.getId());
|
e.createCriteria().andReportIdEqualTo(report.getId());
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ public class PassRateUtil {
|
|||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
List<StepTreeDTO> stepList = JSONArray.parseArray(new String(apiScenarioReportStructures.get(0).getResourceTree(), StandardCharsets.UTF_8), StepTreeDTO.class);
|
List<StepTreeDTO> stepList = JSONArray.parseArray(new String(apiScenarioReportStructures.get(0).getResourceTree(), StandardCharsets.UTF_8), StepTreeDTO.class);
|
||||||
successSize = getUISuccessSize(resultIdMap, stepList);
|
successSize = getUISuccessSize(resultResourceStatusMap, stepList);
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(stepList)) {
|
if (CollectionUtils.isEmpty(stepList)) {
|
||||||
return "0";
|
return "0";
|
||||||
@ -64,20 +66,20 @@ public class PassRateUtil {
|
|||||||
* @param stepList
|
* @param stepList
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static long getUISuccessSize(Map<String, String> resultIdMap, List<StepTreeDTO> stepList) {
|
private static long getUISuccessSize(Map<String, List<ApiScenarioReportResult>> resultIdMap, List<StepTreeDTO> stepList) {
|
||||||
AtomicLong atomicLong = new AtomicLong();
|
AtomicLong atomicLong = new AtomicLong();
|
||||||
stepList.forEach(stepFather -> {
|
stepList.forEach(stepFather -> {
|
||||||
stepFather.getChildren().forEach(step -> {
|
stepFather.getChildren().forEach(step -> {
|
||||||
if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) {
|
if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) {
|
||||||
AtomicInteger failCount = new AtomicInteger();
|
AtomicLong failCount = new AtomicLong();
|
||||||
getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount);
|
getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount);
|
||||||
//复制或者嵌套场景的成功只算 1 次
|
//复制或者嵌套场景的成功只算 1 次
|
||||||
if (failCount.get() == 0) {
|
if (failCount.get() == 0) {
|
||||||
atomicLong.getAndAdd(1);
|
atomicLong.getAndAdd(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (resultIdMap.containsKey(step.getResourceId()) && StringUtils.equalsIgnoreCase(resultIdMap.get(step.getResourceId()), ScenarioStatus.Success.name())) {
|
if (resultIdMap.containsKey(step.getResourceId()) && CollectionUtils.isNotEmpty(resultIdMap.get(step.getResourceId()))) {
|
||||||
atomicLong.incrementAndGet();
|
calculateCount(resultIdMap, atomicLong, step, ScenarioStatus.Success.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -94,18 +96,31 @@ public class PassRateUtil {
|
|||||||
* @param failCount
|
* @param failCount
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static void getUIFailStepCount(Map<String, String> resultIdMap, List<StepTreeDTO> stepTrees, AtomicInteger failCount) {
|
private static void getUIFailStepCount(Map<String, List<ApiScenarioReportResult>> resultIdMap, List<StepTreeDTO> stepTrees, AtomicLong failCount) {
|
||||||
stepTrees.forEach(step -> {
|
stepTrees.forEach(step -> {
|
||||||
if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) {
|
if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) {
|
||||||
getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount);
|
getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount);
|
||||||
} else {
|
} else {
|
||||||
if (resultIdMap.containsKey(step.getResourceId()) && StringUtils.equalsIgnoreCase(resultIdMap.get(step.getResourceId()), ScenarioStatus.Error.name())) {
|
if (resultIdMap.containsKey(step.getResourceId()) && CollectionUtils.isNotEmpty(resultIdMap.get(step.getResourceId()))) {
|
||||||
failCount.incrementAndGet();
|
calculateCount(resultIdMap, failCount, step, ScenarioStatus.Fail.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void calculateCount(Map<String, List<ApiScenarioReportResult>> resultIdMap, AtomicLong failCount, StepTreeDTO step, String status) {
|
||||||
|
List<ApiScenarioReportResult> sameResourceIdResults = resultIdMap.get(step.getResourceId());
|
||||||
|
if (StringUtils.equalsIgnoreCase(sameResourceIdResults.get(0).getStatus(), status)) {
|
||||||
|
failCount.incrementAndGet();
|
||||||
|
|
||||||
|
//计算完结果移除
|
||||||
|
sameResourceIdResults.remove(0);
|
||||||
|
if (CollectionUtils.isEmpty(sameResourceIdResults)) {
|
||||||
|
resultIdMap.remove(step.getResourceId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算总步骤数
|
* 计算总步骤数
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user