feat(测试计划): 计划列表增加执行按钮
This commit is contained in:
parent
3e802d4ea7
commit
717f5d2f4b
|
@ -178,6 +178,16 @@ public class TestPlanController {
|
|||
return testPlanService.getApiScenarioEnv(caseIds);
|
||||
}
|
||||
|
||||
@PostMapping("/case/env")
|
||||
public Map<String, List<String>> getPlanCaseEnv(@RequestBody TestPlan plan) {
|
||||
return testPlanService.getPlanCaseEnv(plan.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/run")
|
||||
public String run(@RequestBody TestplanRunRequest testplanRunRequest) {
|
||||
return testPlanService.runPlan(testplanRunRequest);
|
||||
}
|
||||
|
||||
@GetMapping("/report/export/{planId}")
|
||||
public void exportHtmlReport(@PathVariable String planId, HttpServletResponse response) throws UnsupportedEncodingException {
|
||||
testPlanService.exportPlanReport(planId, response);
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.track.request.testplan;
|
|||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -16,5 +17,6 @@ public class TestplanRunRequest {
|
|||
private String onSampleError;//是否失败停止
|
||||
private String runWithinResourcePool;//是否选择资源池
|
||||
private String resourcePoolId;//资源池Id
|
||||
private Map<String, String> envMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -484,7 +484,7 @@ public class TestPlanApiCaseService {
|
|||
return request.getId();
|
||||
}
|
||||
|
||||
private void setApiCaseEnv(List<String> planIds, Map<String, String> map) {
|
||||
public void setApiCaseEnv(List<String> planIds, Map<String, String> map) {
|
||||
if (CollectionUtils.isEmpty(planIds)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ public class TestPlanScenarioCaseService {
|
|||
return apiAutomationService.run(request);
|
||||
}
|
||||
|
||||
private void setScenarioEnv(List<String> planScenarioIds, Map<String, String> envMap) {
|
||||
public void setScenarioEnv(List<String> planScenarioIds, Map<String, String> envMap) {
|
||||
if (CollectionUtils.isEmpty(planScenarioIds)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,9 @@ import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest;
|
|||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||
import io.metersphere.track.request.testplan.AddTestPlanRequest;
|
||||
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||
import io.metersphere.track.request.testplan.TestplanRunRequest;
|
||||
import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -66,6 +68,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
public class TestPlanService {
|
||||
|
@ -1412,4 +1415,73 @@ public class TestPlanService {
|
|||
public TestCaseReportStatusResultDTO getFunctionalResultReport(String planId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getPlanCaseEnv(String planId) {
|
||||
Map<String, List<String>> envMap = new HashMap<>();
|
||||
if (StringUtils.isBlank(planId)) {
|
||||
return envMap;
|
||||
}
|
||||
|
||||
TestPlanApiCaseExample caseExample = new TestPlanApiCaseExample();
|
||||
caseExample.createCriteria().andTestPlanIdEqualTo(planId);
|
||||
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(caseExample);
|
||||
List<String> apiCaseIds = testPlanApiCases.stream().map(TestPlanApiCase::getId).collect(Collectors.toList());
|
||||
envMap = this.getApiCaseEnv(apiCaseIds);
|
||||
|
||||
TestPlanApiScenarioExample scenarioExample = new TestPlanApiScenarioExample();
|
||||
scenarioExample.createCriteria().andTestPlanIdEqualTo(planId);
|
||||
List<TestPlanApiScenario> testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(scenarioExample);
|
||||
List<String> scenarioIds = testPlanApiScenarios.stream().map(TestPlanApiScenario::getId).collect(Collectors.toList());
|
||||
Map<String, List<String>> scenarioEnv = this.getApiScenarioEnv(scenarioIds);
|
||||
|
||||
Set<String> projectIds = scenarioEnv.keySet();
|
||||
for (String projectId : projectIds) {
|
||||
if (envMap.containsKey(projectId)) {
|
||||
List<String> apiList = envMap.get(projectId);
|
||||
List<String> scenarioList = scenarioEnv.get(projectId);
|
||||
List<String> result = Stream.of(apiList, scenarioList)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
envMap.put(projectId, result);
|
||||
} else {
|
||||
envMap.put(projectId, scenarioEnv.get(projectId));
|
||||
}
|
||||
}
|
||||
|
||||
return envMap;
|
||||
}
|
||||
|
||||
public String runPlan(TestplanRunRequest testplanRunRequest) {
|
||||
if (MapUtils.isNotEmpty(testplanRunRequest.getEnvMap())) {
|
||||
this.setPlanCaseEnv(testplanRunRequest.getTestPlanId(), testplanRunRequest.getEnvMap());
|
||||
}
|
||||
|
||||
ApiRunConfigDTO api = new ApiRunConfigDTO();
|
||||
api.setMode(testplanRunRequest.getMode());
|
||||
api.setResourcePoolId(testplanRunRequest.getResourcePoolId());
|
||||
api.setOnSampleError(Boolean.parseBoolean(testplanRunRequest.getOnSampleError()));
|
||||
if (StringUtils.isBlank(testplanRunRequest.getReportType())) {
|
||||
api.setReportType("iddReport");
|
||||
} else {
|
||||
api.setReportType(testplanRunRequest.getReportType());
|
||||
}
|
||||
String apiRunConfig = JSONObject.toJSONString(api);
|
||||
return this.run(testplanRunRequest.getTestPlanId(), testplanRunRequest.getProjectId(),
|
||||
testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), apiRunConfig);
|
||||
}
|
||||
|
||||
public void setPlanCaseEnv(String planId, Map<String, String> envMap) {
|
||||
TestPlanApiCaseExample caseExample = new TestPlanApiCaseExample();
|
||||
caseExample.createCriteria().andTestPlanIdEqualTo(planId);
|
||||
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(caseExample);
|
||||
List<String> planApiCaseIds = testPlanApiCases.stream().map(TestPlanApiCase::getId).collect(Collectors.toList());
|
||||
testPlanApiCaseService.setApiCaseEnv(planApiCaseIds, envMap);
|
||||
|
||||
TestPlanApiScenarioExample scenarioExample = new TestPlanApiScenarioExample();
|
||||
scenarioExample.createCriteria().andTestPlanIdEqualTo(planId);
|
||||
List<TestPlanApiScenario> testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(scenarioExample);
|
||||
List<String> planScenarioIds = testPlanApiScenarios.stream().map(TestPlanApiScenario::getId).collect(Collectors.toList());
|
||||
testPlanScenarioCaseService.setScenarioEnv(planScenarioIds, envMap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ export default {
|
|||
projectIds: new Set(),
|
||||
};
|
||||
},
|
||||
props: ['planCaseIds', 'type'],
|
||||
props: ['planCaseIds', 'type', 'planId'],
|
||||
methods: {
|
||||
open(testType) {
|
||||
this.runModeVisible = true;
|
||||
|
@ -141,13 +141,19 @@ export default {
|
|||
},
|
||||
showPopover() {
|
||||
this.projectIds.clear();
|
||||
let param = undefined;
|
||||
let url = "";
|
||||
if (this.type === 'apiCase') {
|
||||
url = '/test/plan/api/case/env';
|
||||
param = this.planCaseIds;
|
||||
} else if (this.type === 'apiScenario') {
|
||||
url = '/test/plan/api/scenario/env';
|
||||
param = this.planCaseIds;
|
||||
} else if (this.type === 'plan') {
|
||||
url = '/test/plan/case/env';
|
||||
param = {id: this.planId};
|
||||
}
|
||||
this.$post(url, this.planCaseIds, res => {
|
||||
this.$post(url, param, res => {
|
||||
let data = res.data;
|
||||
if (data) {
|
||||
this.projectEnvListMap = data;
|
||||
|
|
|
@ -187,6 +187,10 @@
|
|||
<ms-table-operator :edit-permission="['PROJECT_TRACK_PLAN:READ+EDIT']"
|
||||
:show-delete="false"
|
||||
@editClick="handleEdit(scope.row)">
|
||||
<template v-slot:front>
|
||||
<ms-table-operator-button :tip="$t('api_test.run')" icon="el-icon-video-play" class="run-button"
|
||||
@exec="handleRun(scope.row)"/>
|
||||
</template>
|
||||
<template v-slot:middle>
|
||||
<ms-table-operator-button :tip="$t('commons.copy')" icon="el-icon-copy-document"
|
||||
@exec="handleCopy(scope.row)"/>
|
||||
|
@ -230,6 +234,7 @@
|
|||
{{ $t('test_track.plan.plan_delete_tip') }}
|
||||
</ms-delete-confirm>
|
||||
<ms-test-plan-schedule-maintain ref="scheduleMaintain" @refreshTable="initTableData"/>
|
||||
<plan-run-mode-with-env @handleRunBatch="_handleRun" ref="runMode" :plan-case-ids="[]" :type="'plan'" :plan-id="currentPlanId"/>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
|
@ -260,7 +265,8 @@ import HeaderCustom from "@/business/components/common/head/HeaderCustom";
|
|||
import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate";
|
||||
import MsTag from "@/business/components/common/components/MsTag";
|
||||
import MsTestPlanScheduleMaintain from "@/business/components/track/plan/components/ScheduleMaintain";
|
||||
import {getCurrentProjectID, hasPermission} from "@/common/js/utils";
|
||||
import {getCurrentProjectID, getCurrentUserId, hasPermission} from "@/common/js/utils";
|
||||
import PlanRunModeWithEnv from "@/business/components/track/plan/common/PlanRunModeWithEnv";
|
||||
|
||||
export default {
|
||||
name: "TestPlanList",
|
||||
|
@ -274,7 +280,7 @@ export default {
|
|||
PlanStageTableItem,
|
||||
PlanStatusTableItem,
|
||||
MsTestPlanScheduleMaintain,
|
||||
MsTableOperator, MsTableOperatorButton, MsDialogFooter, MsTableHeader, MsCreateBox, MsTablePagination
|
||||
MsTableOperator, MsTableOperatorButton, MsDialogFooter, MsTableHeader, MsCreateBox, MsTablePagination, PlanRunModeWithEnv
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -308,6 +314,7 @@ export default {
|
|||
{text: this.$t('test_track.plan.system_test'), value: 'system'},
|
||||
{text: this.$t('test_track.plan.regression_test'), value: 'regression'},
|
||||
],
|
||||
currentPlanId: ""
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
|
@ -481,6 +488,22 @@ export default {
|
|||
this.$post('test/plan/copy/' + row.id, {},() => {
|
||||
this.initTableData();
|
||||
});
|
||||
},
|
||||
handleRun(row) {
|
||||
this.currentPlanId = row.id;
|
||||
this.$refs.runMode.open('API');
|
||||
},
|
||||
_handleRun(config) {
|
||||
let {mode, reportType, onSampleError, runWithinResourcePool, resourcePoolId, envMap} = config;
|
||||
let param = {mode, reportType, onSampleError, runWithinResourcePool, resourcePoolId, envMap};
|
||||
param.testPlanId = this.currentPlanId;
|
||||
param.projectId = getCurrentProjectID();
|
||||
param.userId = getCurrentUserId();
|
||||
this.result = this.$post('test/plan/run/', param,() => {
|
||||
this.$success(this.$t('commons.run_success'));
|
||||
}, () => {
|
||||
this.$error(this.$t('commons.run_fail'));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -176,6 +176,8 @@ export default {
|
|||
debug_history: "Debug history",
|
||||
testing: "Testing",
|
||||
environment: "Environment",
|
||||
run_success: "Run Success",
|
||||
run_fail: "Run Fail",
|
||||
table: {
|
||||
select_tip: "Item {0} data is selected"
|
||||
},
|
||||
|
|
|
@ -177,6 +177,8 @@ export default {
|
|||
debug_history: "调试历史",
|
||||
testing: "测试中",
|
||||
environment: "运行环境",
|
||||
run_success: "执行成功",
|
||||
run_fail: "执行失败",
|
||||
table: {
|
||||
select_tip: "已选中 {0} 条数据"
|
||||
},
|
||||
|
|
|
@ -177,6 +177,8 @@ export default {
|
|||
debug_history: "調試歷史",
|
||||
testing: "測試中",
|
||||
environment: "運行環境",
|
||||
run_success: "執行成功",
|
||||
run_fail: "執行失敗",
|
||||
selector: {
|
||||
required: "必填",
|
||||
not_required: "非必填",
|
||||
|
|
Loading…
Reference in New Issue