refactor(接口测试): 优化场景报告

This commit is contained in:
wxg0103 2024-03-29 13:00:19 +08:00 committed by wxg0103
parent 1ac7e3e458
commit f49744e27d
11 changed files with 73 additions and 24 deletions

View File

@ -49,4 +49,6 @@ public interface ExtApiScenarioReportMapper {
ApiScenarioBlob getScenarioBlob(String id);
void updateApiScenario(List<String> subList);
List<ApiScenarioReportStepDTO> selectStepDeatilByReportId(String id);
}

View File

@ -73,19 +73,9 @@
api_scenario_report_step.`name`,
api_scenario_report_step.sort,
api_scenario_report_step.step_type,
api_scenario_report_step.parent_id,
api_scenario_report_detail.status,
api_scenario_report_detail.fake_code,
api_scenario_report_detail.request_name,
api_scenario_report_detail.request_time,
api_scenario_report_detail.code,
api_scenario_report_detail.response_size,
api_scenario_report_detail.script_identifier,
api_scenario_report_detail.sort as loopIndex
api_scenario_report_step.parent_id
from api_scenario_report_step
left join api_scenario_report_detail
on api_scenario_report_step.step_id = api_scenario_report_detail.step_id
and api_scenario_report_detail.report_id = api_scenario_report_step.report_id
where api_scenario_report_step.report_id = #{reportId}
</select>
@ -221,6 +211,21 @@
where api_scenario_record.api_scenario_report_id = #{id}
</select>
<select id="selectStepDeatilByReportId"
resultType="io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO">
select api_scenario_report_detail.step_id,
api_scenario_report_detail.report_id,
api_scenario_report_detail.status,
api_scenario_report_detail.fake_code,
api_scenario_report_detail.request_name,
api_scenario_report_detail.request_time,
api_scenario_report_detail.code,
api_scenario_report_detail.response_size,
api_scenario_report_detail.script_identifier,
api_scenario_report_detail.sort as loopIndex
from api_scenario_report_detail
where api_scenario_report_detail.report_id = #{reportId}
</select>
<sql id="filters">
<if test="${filter} != null and ${filter}.size() > 0">

View File

@ -191,7 +191,7 @@ public class ApiReportService {
//查询资源池名称
apiReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(apiReportDTO.getPoolId()).getName());
//查询环境名称
String environmentName = Translator.get("api_report_default_env");
String environmentName = null;
if (StringUtils.isNoneBlank(apiReportDTO.getEnvironmentId())) {
Environment environment = environmentMapper.selectByPrimaryKey(apiReportDTO.getEnvironmentId());
if (environment != null) {

View File

@ -197,6 +197,44 @@ public class ApiScenarioReportService {
scenarioReportDTO.setWaitingTime(scenarioConfig.getOtherConfig().getStepWaitTime());
}
}
//查询所有步骤的detail
List<ApiScenarioReportStepDTO> deatilList = extApiScenarioReportMapper.selectStepDeatilByReportId(id);
//根据stepId进行分组
Map<String, List<ApiScenarioReportStepDTO>> detailMap = deatilList.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getStepId));
scenarioReportSteps.forEach(step -> {
List<ApiScenarioReportStepDTO> details = detailMap.get(step.getStepId());
if (CollectionUtils.isNotEmpty(details)) {
details.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getLoopIndex));
//需要重新处理sort
for (int i = 0; i < details.size(); i++) {
ApiScenarioReportStepDTO detail = details.get(i);
detail.setSort((long) i + 1);
detail.setStepId(step.getStepId() + SPLITTER + detail.getSort());
detail.setStepType(step.getStepType());
detail.setName(detail.getRequestName());
}
step.setChildren(details);
//只处理请求的
List<String> stepTypes = Arrays.asList(ApiScenarioStepType.API_CASE.name(),
ApiScenarioStepType.API.name(),
ApiScenarioStepType.CUSTOM_REQUEST.name());
if (stepTypes.contains(step.getStepType())) {
step.setRequestTime(details.stream().mapToLong(ApiScenarioReportStepDTO::getRequestTime).sum());
step.setResponseSize(details.stream().mapToLong(ApiScenarioReportStepDTO::getResponseSize).sum());
List<String> requestStatus = details.stream().map(ApiScenarioReportStepDTO::getStatus).toList();
List<String> successStatus = requestStatus.stream().filter(status -> StringUtils.equals(ApiReportStatus.SUCCESS.name(), status)).toList();
if (requestStatus.contains(ApiReportStatus.ERROR.name())) {
step.setStatus(ApiReportStatus.ERROR.name());
} else if (requestStatus.contains(ApiReportStatus.FAKE_ERROR.name())) {
step.setStatus(ApiReportStatus.FAKE_ERROR.name());
} else if (successStatus.size() == details.size()) {
step.setStatus(ApiReportStatus.SUCCESS.name());
} else {
step.setStatus(ApiReportStatus.PENDING.name());
}
}
}
});
//将scenarioReportSteps按照parentId进行分组 值为list 然后根据sort进行排序
Map<String, List<ApiScenarioReportStepDTO>> scenarioReportStepMap = scenarioReportSteps.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getParentId));
// TODO 查询修改
@ -221,7 +259,7 @@ public class ApiScenarioReportService {
//查询资源池名称
scenarioReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(scenarioReport.getPoolId()).getName());
//查询环境名称
String environmentName = Translator.get("api_report_default_env");
String environmentName = null;
if (StringUtils.isNotBlank(scenarioReport.getEnvironmentId())) {
Environment environment = environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId());
if (environment != null) {
@ -247,7 +285,7 @@ public class ApiScenarioReportService {
List<ApiScenarioReportStepDTO> children = scenarioReportStepMap.get(step.getStepId());
if (CollectionUtils.isNotEmpty(children)) {
//如果是循环控制器 需要重新处理
if (StringUtils.equals(ApiScenarioStepType.LOOP_CONTROLLER.name(), step.getStepType())) {
/*if (StringUtils.equals(ApiScenarioStepType.LOOP_CONTROLLER.name(), step.getStepType())) {
//根据stepId进行分组
Map<String, List<ApiScenarioReportStepDTO>> loopMap = children.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getStepId));
List<ApiScenarioReportStepDTO> newChildren = new ArrayList<>();
@ -266,7 +304,7 @@ public class ApiScenarioReportService {
});
children = newChildren;
scenarioReportStepMap.remove(step.getStepId());
}
}*/
children.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
step.setChildren(children);
getStepTree(children, scenarioReportStepMap);

View File

@ -469,7 +469,6 @@
slotName: 'operation',
fixed: 'right',
width: 130,
hasDisable: true,
moreAction: [
{
eventTag: 'copy',
@ -544,7 +543,6 @@
slotName: 'operation',
fixed: 'right',
width: 130,
hasDisable: true,
moreAction: [
{
eventTag: 'copy',

View File

@ -2,7 +2,7 @@
<div>
<paramsTable
v-model:params="condition.assertions"
:selectable="true"
:selectable="false"
:columns="columns"
:scroll="{ minWidth: '700px' }"
:default-param-item="defaultParamItem"

View File

@ -8,12 +8,12 @@
<a-divider direction="vertical" :margin="4" class="!mx-2"></a-divider
></span>
<a-popover position="left" content-class="response-popover-content">
<span> {{ detail.environmentName || '-' }}</span>
<span> {{ detail.environmentName || t('report.detail.api.defaultEnv') }}</span>
<a-divider direction="vertical" :margin="4" class="!mx-2"></a-divider>
<template #content>
<div class="flex items-center gap-[8px] text-[14px]">
<div class="text-[var(--color-text-4)]">{{ t('report.detail.api.executeEnv') }}</div>
<span class="mx-1"> {{ detail.environmentName || '-' }}</span>
<span class="mx-1"> {{ detail.environmentName || t('report.detail.api.caseSaveEnv') }}</span>
</div>
</template>
</a-popover>

View File

@ -287,7 +287,7 @@
moduleType: props.moduleType,
filter: {
status: statusListFilters.value,
integrated: Array.of((showType.value === 'INTEGRATED').toString()),
integrated: showType.value === 'All' ? undefined : Array.of((showType.value === 'INTEGRATED').toString()),
triggerMode: triggerModeListFilters.value,
},
});

View File

@ -5,12 +5,12 @@
<!-- TODO 虚拟数据替换接口后边 -->
<span>
<a-popover position="left" content-class="response-popover-content">
<span> {{ detail.environmentName || '-' }}</span>
<span> {{ detail.environmentName || t('report.detail.api.defaultEnv') }}</span>
<a-divider direction="vertical" :margin="4" class="!mx-2"></a-divider>
<template #content>
<div class="flex items-center gap-[8px] text-[14px]">
<div class="text-[var(--color-text-4)]">{{ t('report.detail.api.executeEnv') }}</div>
<span class="mx-1"> {{ detail.environmentName || '-' }}</span>
<span class="mx-1"> {{ detail.environmentName || t('report.detail.api.scenarioSavedEnv') }}</span>
</div>
</template>
</a-popover>

View File

@ -77,4 +77,7 @@ export default {
'report.detail.api.runMode': 'Run mode',
'report.detail.api.copyLink': 'Copy link',
'report.detail.api.copyLinkTimeEnd': '(Valid 24 hours)',
'report.detail.api.defaultEnv': 'Default environment',
'report.detail.api.caseSaveEnv': 'Case saved environment',
'report.detail.api.scenarioSavedEnv': 'Scenario saved environment',
};

View File

@ -76,4 +76,7 @@ export default {
'report.detail.api.runMode': '运行模式',
'report.detail.api.copyLink': '复制链接',
'report.detail.api.copyLinkTimeEnd': '(24小时有效)',
'report.detail.api.defaultEnv': '默认环境',
'report.detail.api.caseSaveEnv': '用例保存的环境',
'report.detail.api.scenarioSavedEnv': '场景保存的环境',
};