diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java index ad1f08d27f..2eb30e0f64 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java @@ -27,4 +27,5 @@ public class ApiScenarioRequest { private boolean isSelectThisWeedData; private long createTime = 0; private String executeStatus; + private boolean notInTestPlan; } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java index ff4f5128c5..83aff1371a 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.Setter; import java.util.List; +import java.util.Map; @Setter @Getter @@ -32,6 +33,8 @@ public class RunScenarioRequest { private List scenarioIds; + private Map scenarioTestPlanIdMap; + /** * isSelectAllDate:选择的数据是否是全部数据(全部数据是不受分页影响的数据) * filters: 数据状态 diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 5181517719..6805899a82 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -400,8 +400,19 @@ public class ApiAutomationService { scenarios.add(scenario); // 创建场景报告 if (reportIds != null) { - createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), - request.getExecuteType(), item.getProjectId(), request.getReportUserID()); + //如果是测试计划页面触发的执行方式,生成报告时createScenarioReport第二个参数需要特殊处理 + if(StringUtils.equals(request.getRunMode(),ApiRunMode.SCENARIO_PLAN.name())){ + String testPlanScenarioId = item.getId(); + if(request.getScenarioTestPlanIdMap()!=null&&request.getScenarioTestPlanIdMap().containsKey(item.getId())){ + testPlanScenarioId = request.getScenarioTestPlanIdMap().get(item.getId()); + } + createScenarioReport(group.getName(), testPlanScenarioId, item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), + request.getExecuteType(), item.getProjectId(), request.getReportUserID()); + }else{ + createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), + request.getExecuteType(), item.getProjectId(), request.getReportUserID()); + } + reportIds.add(group.getName()); } group.setHashTree(scenarios); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 6f811c32da..f30550e488 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -134,31 +134,41 @@ public class ApiScenarioReportService { } public ApiScenarioReport updatePlanCase(TestResult result) { - TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId()); - ScenarioResult scenarioResult = result.getScenarios().get(0); - if (scenarioResult.getError() > 0) { - testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name()); - } else { - testPlanApiScenario.setLastResult(ScenarioStatus.Success.name()); +// TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId()); + List scenarioResultList = result.getScenarios(); + ApiScenarioReport returnReport = null; + for (ScenarioResult scenarioResult : + scenarioResultList) { + ApiScenarioReport report = editReport(scenarioResult); + // 报告详情内容 + ApiScenarioReportDetail detail = new ApiScenarioReportDetail(); + TestResult newResult = createTestResult(result.getTestId(), scenarioResult); + scenarioResult.setName(report.getScenarioName()); + newResult.addScenario(scenarioResult); + + detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8)); + detail.setReportId(report.getId()); + detail.setProjectId(report.getProjectId()); + apiScenarioReportDetailMapper.insert(detail); + + TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(report.getScenarioId()); + if(testPlanApiScenario!=null){ + report.setScenarioId(testPlanApiScenario.getApiScenarioId()); + apiScenarioReportMapper.updateByPrimaryKeySelective(report); + if (scenarioResult.getError() > 0) { + testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name()); + } else { + testPlanApiScenario.setLastResult(ScenarioStatus.Success.name()); + } + String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError())); + testPlanApiScenario.setPassRate(passRate); + testPlanApiScenario.setReportId(report.getId()); + testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); + } + returnReport = report; } - String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError())); - testPlanApiScenario.setPassRate(passRate); - // 存储场景报告 - ApiScenarioReport report = editReport(scenarioResult); - // 报告详情内容 - ApiScenarioReportDetail detail = new ApiScenarioReportDetail(); - TestResult newResult = createTestResult(result.getTestId(), scenarioResult); - scenarioResult.setName(report.getScenarioName()); - newResult.addScenario(scenarioResult); - detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8)); - detail.setReportId(report.getId()); - detail.setProjectId(report.getProjectId()); - apiScenarioReportDetailMapper.insert(detail); - - testPlanApiScenario.setReportId(report.getId()); - testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); - return report; + return returnReport; } public ApiScenarioReport updateSchedulePlanCase(TestResult result) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index aad982b1f3..c0089a1413 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -164,7 +164,13 @@ and api_scenario.last_result = 'Success' - + + and api_scenario.id not in ( + select pc.api_scenario_id + from test_plan_api_scenario pc + where pc.test_plan_id = #{request.planId} + ) + order by diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index 62e675723d..b5c9256f6a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -145,43 +145,43 @@ - and atc.name + and t1.name - and atc.update_time + and t1.update_time - - and atc.create_time + + and t1.create_time - and atc.priority + and t1.priority - and atc.user_id + and t1.user_id - and atc.tags + and t1.tags - and ader.status + and t2.status @@ -190,17 +190,17 @@