fix(UI 自动化) UI测试报告不同步测试计划,无消息发送

--bug=1015636 --user=张大海 【UI 测试】测试计划 UI 测试结果与总报告结果不同步 https://www.tapd.cn/55049933/s/1223786
--bug=1015719 --user=张大海 【测试跟踪】测试计划 - 只关联UI自动化场景 - 不发送消息通知 https://www.tapd.cn/55049933/s/1223784
This commit is contained in:
zhangdahai112 2022-08-15 18:27:10 +08:00 committed by zhangdahai112
parent 4673586d04
commit 9e01b59843
6 changed files with 249 additions and 42 deletions

View File

@ -37,6 +37,8 @@ public class TestPlanReport implements Serializable {
private Boolean isNew;
private Boolean isUiScenarioExecuting;
private String runInfo;
private static final long serialVersionUID = 1L;

View File

@ -1143,6 +1143,66 @@ public class TestPlanReportExample {
addCriterion("is_new not between", value1, value2, "isNew");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingIsNull() {
addCriterion("is_ui_scenario_executing is null");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingIsNotNull() {
addCriterion("is_ui_scenario_executing is not null");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingEqualTo(Boolean value) {
addCriterion("is_ui_scenario_executing =", value, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingNotEqualTo(Boolean value) {
addCriterion("is_ui_scenario_executing <>", value, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingGreaterThan(Boolean value) {
addCriterion("is_ui_scenario_executing >", value, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingGreaterThanOrEqualTo(Boolean value) {
addCriterion("is_ui_scenario_executing >=", value, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingLessThan(Boolean value) {
addCriterion("is_ui_scenario_executing <", value, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingLessThanOrEqualTo(Boolean value) {
addCriterion("is_ui_scenario_executing <=", value, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingIn(List<Boolean> values) {
addCriterion("is_ui_scenario_executing in", values, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingNotIn(List<Boolean> values) {
addCriterion("is_ui_scenario_executing not in", values, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingBetween(Boolean value1, Boolean value2) {
addCriterion("is_ui_scenario_executing between", value1, value2, "isUiScenarioExecuting");
return (Criteria) this;
}
public Criteria andIsUiScenarioExecutingNotBetween(Boolean value1, Boolean value2) {
addCriterion("is_ui_scenario_executing not between", value1, value2, "isUiScenarioExecuting");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -18,6 +18,7 @@
<result column="principal" jdbcType="VARCHAR" property="principal" />
<result column="components" jdbcType="VARCHAR" property="components" />
<result column="is_new" jdbcType="BIT" property="isNew" />
<result column="is_ui_scenario_executing" jdbcType="BIT" property="isUiScenarioExecuting" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.TestPlanReport">
<result column="run_info" jdbcType="LONGVARCHAR" property="runInfo" />
@ -83,7 +84,7 @@
<sql id="Base_Column_List">
id, test_plan_id, create_time, update_time, `name`, `status`, trigger_mode, creator,
start_time, end_time, is_api_case_executing, is_scenario_executing, is_performance_executing,
principal, components, is_new
principal, components, is_new, is_ui_scenario_executing
</sql>
<sql id="Blob_Column_List">
run_info
@ -142,13 +143,15 @@
trigger_mode, creator, start_time,
end_time, is_api_case_executing, is_scenario_executing,
is_performance_executing, principal, components,
is_new, run_info)
is_new, is_ui_scenario_executing, run_info
)
values (#{id,jdbcType=VARCHAR}, #{testPlanId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{triggerMode,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT},
#{endTime,jdbcType=BIGINT}, #{isApiCaseExecuting,jdbcType=BIT}, #{isScenarioExecuting,jdbcType=BIT},
#{isPerformanceExecuting,jdbcType=BIT}, #{principal,jdbcType=VARCHAR}, #{components,jdbcType=VARCHAR},
#{isNew,jdbcType=BIT}, #{runInfo,jdbcType=LONGVARCHAR})
#{isNew,jdbcType=BIT}, #{isUiScenarioExecuting,jdbcType=BIT}, #{runInfo,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestPlanReport">
insert into test_plan_report
@ -201,6 +204,9 @@
<if test="isNew != null">
is_new,
</if>
<if test="isUiScenarioExecuting != null">
is_ui_scenario_executing,
</if>
<if test="runInfo != null">
run_info,
</if>
@ -254,6 +260,9 @@
<if test="isNew != null">
#{isNew,jdbcType=BIT},
</if>
<if test="isUiScenarioExecuting != null">
#{isUiScenarioExecuting,jdbcType=BIT},
</if>
<if test="runInfo != null">
#{runInfo,jdbcType=LONGVARCHAR},
</if>
@ -316,6 +325,9 @@
<if test="record.isNew != null">
is_new = #{record.isNew,jdbcType=BIT},
</if>
<if test="record.isUiScenarioExecuting != null">
is_ui_scenario_executing = #{record.isUiScenarioExecuting,jdbcType=BIT},
</if>
<if test="record.runInfo != null">
run_info = #{record.runInfo,jdbcType=LONGVARCHAR},
</if>
@ -342,6 +354,7 @@
principal = #{record.principal,jdbcType=VARCHAR},
components = #{record.components,jdbcType=VARCHAR},
is_new = #{record.isNew,jdbcType=BIT},
is_ui_scenario_executing = #{record.isUiScenarioExecuting,jdbcType=BIT},
run_info = #{record.runInfo,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -364,7 +377,8 @@
is_performance_executing = #{record.isPerformanceExecuting,jdbcType=BIT},
principal = #{record.principal,jdbcType=VARCHAR},
components = #{record.components,jdbcType=VARCHAR},
is_new = #{record.isNew,jdbcType=BIT}
is_new = #{record.isNew,jdbcType=BIT},
is_ui_scenario_executing = #{record.isUiScenarioExecuting,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -417,6 +431,9 @@
<if test="isNew != null">
is_new = #{isNew,jdbcType=BIT},
</if>
<if test="isUiScenarioExecuting != null">
is_ui_scenario_executing = #{isUiScenarioExecuting,jdbcType=BIT},
</if>
<if test="runInfo != null">
run_info = #{runInfo,jdbcType=LONGVARCHAR},
</if>
@ -440,6 +457,7 @@
principal = #{principal,jdbcType=VARCHAR},
components = #{components,jdbcType=VARCHAR},
is_new = #{isNew,jdbcType=BIT},
is_ui_scenario_executing = #{isUiScenarioExecuting,jdbcType=BIT},
run_info = #{runInfo,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
@ -459,7 +477,8 @@
is_performance_executing = #{isPerformanceExecuting,jdbcType=BIT},
principal = #{principal,jdbcType=VARCHAR},
components = #{components,jdbcType=VARCHAR},
is_new = #{isNew,jdbcType=BIT}
is_new = #{isNew,jdbcType=BIT},
is_ui_scenario_executing = #{isUiScenarioExecuting,jdbcType=BIT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -21,13 +21,12 @@ public class TestPlanReportSaveRequest {
private boolean countResources;
private boolean apiCaseIsExecuting;
private boolean scenarioIsExecuting;
private boolean uiScenarioIsExecuting;
private boolean performanceIsExecuting;
// private String apiCaseIdListJSON;
// private String scenarioIdListJSON;
// private String performanceIdListJSON;
Map<String, String> apiCaseIdMap;
Map<String, String> scenarioIdMap;
Map<String, String> uiScenarioIdMap;
Map<String, String> performanceIdMap;
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode) {
@ -39,21 +38,106 @@ public class TestPlanReportSaveRequest {
this.countResources = true;
}
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode, boolean apiCaseIsExecuting, boolean scenarioIsExecuting, boolean performanceIsExecuting,
Map<String,String> apiCaseIdMap, Map<String,String> scenarioIdMap, Map<String,String> performanceIdMap) {
public TestPlanReportSaveRequest(Builder builder) {
this.reportID = builder.reportID;
this.planId = builder.planId;
this.userId = builder.userId;
this.triggerMode = builder.triggerMode;
this.countResources = builder.countResources;
this.apiCaseIsExecuting = builder.apiCaseIsExecuting;
this.scenarioIsExecuting = builder.scenarioIsExecuting;
this.uiScenarioIsExecuting = builder.uiScenarioIsExecuting;
this.performanceIsExecuting = builder.performanceIsExecuting;
this.apiCaseIdMap = builder.apiCaseIdMap;
this.scenarioIdMap = builder.scenarioIdMap;
this.uiScenarioIdMap = builder.uiScenarioIdMap;
this.performanceIdMap = builder.performanceIdMap;
}
public static class Builder {
private String reportID;
private String planId;
private String userId;
private String triggerMode;
private boolean countResources;
private boolean apiCaseIsExecuting;
private boolean scenarioIsExecuting;
private boolean uiScenarioIsExecuting;
private boolean performanceIsExecuting;
Map<String, String> apiCaseIdMap;
Map<String, String> scenarioIdMap;
Map<String, String> uiScenarioIdMap;
Map<String, String> performanceIdMap;
public Builder setReportID(String reportID) {
this.reportID = reportID;
return this;
}
public Builder setPlanId(String planId) {
this.planId = planId;
return this;
}
public Builder setUserId(String userId) {
this.userId = userId;
return this;
}
public Builder setTriggerMode(String triggerMode) {
this.triggerMode = triggerMode;
return this;
}
this.countResources = false;
public Builder setCountResources(boolean countResources) {
this.countResources = countResources;
return this;
}
public Builder setApiCaseIsExecuting(boolean apiCaseIsExecuting) {
this.apiCaseIsExecuting = apiCaseIsExecuting;
this.scenarioIsExecuting = scenarioIsExecuting;
this.performanceIsExecuting = performanceIsExecuting;
return this;
}
public Builder setScenarioIsExecuting(boolean scenarioIsExecuting) {
this.scenarioIsExecuting = scenarioIsExecuting;
return this;
}
public Builder setUiScenarioIsExecuting(boolean uiScenarioIsExecuting) {
this.uiScenarioIsExecuting = uiScenarioIsExecuting;
return this;
}
public Builder setPerformanceIsExecuting(boolean performanceIsExecuting) {
this.performanceIsExecuting = performanceIsExecuting;
return this;
}
public Builder setApiCaseIdMap(Map<String, String> apiCaseIdMap) {
this.apiCaseIdMap = apiCaseIdMap;
return this;
}
public Builder setScenarioIdMap(Map<String, String> scenarioIdMap) {
this.scenarioIdMap = scenarioIdMap;
return this;
}
public Builder setPerformanceIdMap(Map<String, String> performanceIdMap) {
this.performanceIdMap = performanceIdMap;
return this;
}
public Builder setUiScenarioIdMap(Map<String, String> uiScenarioIdMap) {
this.uiScenarioIdMap = uiScenarioIdMap;
return this;
}
public TestPlanReportSaveRequest build() {
return new TestPlanReportSaveRequest(this);
}
}
}

View File

@ -58,7 +58,7 @@ public class TestPlanMessageService {
if (testPlanReportContent != null) {
report = testPlanReportService.checkTestPlanReportHasErrorCase(report, testPlanReportContent);
}
if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting()) {
if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting() && !report.getIsUiScenarioExecuting()) {
//更新TestPlan状态为完成
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId());
if (testPlan != null && !StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) {

View File

@ -271,22 +271,21 @@ public class TestPlanReportService {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
}
Map<String, String> apiCaseInfoMap = new HashMap<>();
for (String id : planTestCaseIdMap.keySet()) {
apiCaseInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
}
Map<String, String> scenarioInfoMap = new HashMap<>();
for (String id : planScenarioIdMap.keySet()) {
scenarioInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
}
Map<String, String> performanceInfoMap = new HashMap<>();
for (String id : performanceIdMap.values()) {
performanceInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
}
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId, planId, userId, triggerMode,
planTestCaseIdMap.size() > 0, planScenarioIdMap.size() > 0, performanceIdMap.size() > 0,
apiCaseInfoMap, scenarioInfoMap, performanceInfoMap);
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest.Builder()
.setReportID(planReportId)
.setPlanId(planId)
.setUserId(userId)
.setCountResources(false)
.setTriggerMode(triggerMode)
.setApiCaseIsExecuting(!planTestCaseIdMap.isEmpty())
.setScenarioIsExecuting(!planScenarioIdMap.isEmpty())
.setPerformanceIsExecuting(!performanceIdMap.isEmpty())
.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty())
.setApiCaseIdMap(planTestCaseIdMap)
.setScenarioIdMap(planScenarioIdMap)
.setPerformanceIdMap(performanceIdMap)
.setUiScenarioIdMap(uiScenarioIdMap)
.build();
if (testPlanReport == null) {
returnDTO = this.genTestPlanReport(saveRequest, runInfoDTO);
@ -383,6 +382,9 @@ public class TestPlanReportService {
List<String> scenarioIdList = testPlanApiScenarioList.stream().map(TestPlanApiScenarioInfoDTO::getApiScenarioId).collect(Collectors.toList());
testPlanReport.setIsScenarioExecuting(!scenarioIdList.isEmpty());
List<TestPlanUiScenario> testPlanUiScenarioList = extTestPlanUiScenarioCaseMapper.selectLegalDataByTestPlanId(saveRequest.getPlanId());
testPlanReport.setIsUiScenarioExecuting(!testPlanUiScenarioList.isEmpty());
LoadCaseRequest loadCaseRequest = new LoadCaseRequest();
loadCaseRequest.setTestPlanId(saveRequest.getPlanId());
loadCaseRequest.setProjectId(testPlan.getProjectId());
@ -393,9 +395,13 @@ public class TestPlanReportService {
testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting());
testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting());
testPlanReport.setIsPerformanceExecuting(saveRequest.isPerformanceIsExecuting());
testPlanReport.setIsUiScenarioExecuting(saveRequest.isUiScenarioIsExecuting());
}
if (testPlanReport.getIsScenarioExecuting() || testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting()) {
if (testPlanReport.getIsScenarioExecuting()
|| testPlanReport.getIsApiCaseExecuting()
|| testPlanReport.getIsPerformanceExecuting()
|| testPlanReport.getIsUiScenarioExecuting()) {
testPlanReport.setStatus(TestPlanReportStatus.RUNNING.name());
} else {
testPlanReport.setStatus(TestPlanReportStatus.COMPLETED.name());
@ -572,6 +578,7 @@ public class TestPlanReportService {
testPlanReport.setIsApiCaseExecuting(false);
testPlanReport.setIsScenarioExecuting(false);
testPlanReport.setIsPerformanceExecuting(false);
testPlanReport.setIsUiScenarioExecuting(false);
TestPlanExecutionQueueExample testPlanExecutionQueueExample = new TestPlanExecutionQueueExample();
testPlanExecutionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId);
@ -1346,6 +1353,41 @@ public class TestPlanReportService {
LogUtil.error("Parse test plan report cenario case error!", e);
}
}
if (!hasErrorCase && StringUtils.isNotEmpty(content.getPlanUiScenarioReportStruct())) {
try {
List<TestPlanUiScenarioDTO> scenarioCases = JSONArray.parseArray(content.getPlanUiScenarioReportStruct(), TestPlanUiScenarioDTO.class);
List<String> reportIdList = new ArrayList<>();
scenarioCases.forEach(item -> {
if (StringUtils.isNotEmpty(item.getReportId())) {
reportIdList.add(item.getReportId());
}
});
String defaultStatus = "Fail";
Map<String, String> reportStatus = apiScenarioReportService.getReportStatusByReportIds(reportIdList);
for (TestPlanUiScenarioDTO dto : scenarioCases) {
String reportId = dto.getReportId();
if (StringUtils.isNotEmpty(reportId)) {
String execStatus = reportStatus.get(reportId);
if (execStatus == null) {
execStatus = defaultStatus;
} else {
if (StringUtils.equalsIgnoreCase(execStatus, "Error")) {
execStatus = "Fail";
}
}
dto.setLastResult(execStatus);
dto.setStatus(execStatus);
if (!StringUtils.equalsAnyIgnoreCase(execStatus, "success")) {
hasErrorCase = true;
}
}
}
} catch (Exception e) {
LogUtil.error("Parse test plan report ui scenario case error!", e);
}
}
}
return hasErrorCase;
}