This commit is contained in:
fit2-zhao 2021-01-21 19:02:18 +08:00
commit c8d0470ed1
11 changed files with 79 additions and 54 deletions

View File

@ -27,4 +27,5 @@ public class ApiScenarioRequest {
private boolean isSelectThisWeedData; private boolean isSelectThisWeedData;
private long createTime = 0; private long createTime = 0;
private String executeStatus; private String executeStatus;
private boolean notInTestPlan;
} }

View File

@ -4,6 +4,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List; import java.util.List;
import java.util.Map;
@Setter @Setter
@Getter @Getter
@ -32,6 +33,8 @@ public class RunScenarioRequest {
private List<String> scenarioIds; private List<String> scenarioIds;
private Map<String,String> scenarioTestPlanIdMap;
/** /**
* isSelectAllDate选择的数据是否是全部数据全部数据是不受分页影响的数据 * isSelectAllDate选择的数据是否是全部数据全部数据是不受分页影响的数据
* filters: 数据状态 * filters: 数据状态

View File

@ -400,8 +400,19 @@ public class ApiAutomationService {
scenarios.add(scenario); scenarios.add(scenario);
// 创建场景报告 // 创建场景报告
if (reportIds != null) { if (reportIds != null) {
//如果是测试计划页面触发的执行方式生成报告时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(), createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
request.getExecuteType(), item.getProjectId(), request.getReportUserID()); request.getExecuteType(), item.getProjectId(), request.getReportUserID());
}
reportIds.add(group.getName()); reportIds.add(group.getName());
} }
group.setHashTree(scenarios); group.setHashTree(scenarios);

View File

@ -134,16 +134,11 @@ public class ApiScenarioReportService {
} }
public ApiScenarioReport updatePlanCase(TestResult result) { public ApiScenarioReport updatePlanCase(TestResult result) {
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId()); // TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
ScenarioResult scenarioResult = result.getScenarios().get(0); List<ScenarioResult> scenarioResultList = result.getScenarios();
if (scenarioResult.getError() > 0) { ApiScenarioReport returnReport = null;
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name()); for (ScenarioResult scenarioResult :
} else { scenarioResultList) {
testPlanApiScenario.setLastResult(ScenarioStatus.Success.name());
}
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
testPlanApiScenario.setPassRate(passRate);
// 存储场景报告
ApiScenarioReport report = editReport(scenarioResult); ApiScenarioReport report = editReport(scenarioResult);
// 报告详情内容 // 报告详情内容
ApiScenarioReportDetail detail = new ApiScenarioReportDetail(); ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
@ -156,9 +151,24 @@ public class ApiScenarioReportService {
detail.setProjectId(report.getProjectId()); detail.setProjectId(report.getProjectId());
apiScenarioReportDetailMapper.insert(detail); 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()); testPlanApiScenario.setReportId(report.getId());
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
return report; }
returnReport = report;
}
return returnReport;
} }
public ApiScenarioReport updateSchedulePlanCase(TestResult result) { public ApiScenarioReport updateSchedulePlanCase(TestResult result) {

View File

@ -164,7 +164,13 @@
<if test="request.executeStatus == 'executePass'"> <if test="request.executeStatus == 'executePass'">
and api_scenario.last_result = 'Success' and api_scenario.last_result = 'Success'
</if> </if>
<if test="request.notInTestPlan == true ">
and api_scenario.id not in (
select pc.api_scenario_id
from test_plan_api_scenario pc
where pc.test_plan_id = #{request.planId}
)
</if>
</where> </where>
<if test="request.orders != null and request.orders.size() > 0"> <if test="request.orders != null and request.orders.size() > 0">
order by order by

View File

@ -1,12 +1,7 @@
package io.metersphere.job.sechedule; package io.metersphere.job.sechedule;
import io.metersphere.api.dto.automation.ExecuteType; import io.metersphere.api.dto.automation.ExecuteType;
import io.metersphere.api.dto.automation.RunScenarioRequest;
import io.metersphere.api.dto.automation.SchedulePlanScenarioExecuteRequest; import io.metersphere.api.dto.automation.SchedulePlanScenarioExecuteRequest;
import io.metersphere.api.dto.definition.RunCaseRequest;
import io.metersphere.api.dto.definition.RunDefinitionRequest;
import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ApiRunMode;
@ -19,13 +14,9 @@ import io.metersphere.track.dto.TestPlanLoadCaseDTO;
import io.metersphere.track.request.testplan.LoadCaseRequest; import io.metersphere.track.request.testplan.LoadCaseRequest;
import io.metersphere.track.request.testplan.RunTestPlanRequest; import io.metersphere.track.request.testplan.RunTestPlanRequest;
import io.metersphere.track.service.*; import io.metersphere.track.service.*;
import org.python.antlr.ast.Str;
import org.quartz.*; import org.quartz.*;
import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* 情景测试Job * 情景测试Job
@ -130,7 +121,7 @@ public class TestPlanTestJob extends MsScheduleJob {
scenarioRequest.setTestPlanID(this.resourceId); scenarioRequest.setTestPlanID(this.resourceId);
scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name()); scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name());
scenarioRequest.setTestPlanReportId(testPlanReport.getId()); scenarioRequest.setTestPlanReportId(testPlanReport.getId());
testPlanService.runApiCase(scenarioRequest); testPlanService.runScenarioCase(scenarioRequest);
LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------"); LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------");
//执行性能测试任务 //执行性能测试任务

View File

@ -22,9 +22,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -51,11 +49,12 @@ public class TestPlanScenarioCaseService {
} }
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) { public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
List<String> ids = apiAutomationService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId()); // List<String> ids = apiAutomationService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId());
if (CollectionUtils.isEmpty(ids)) { // if (CollectionUtils.isEmpty(ids)) {
return new ArrayList<>(); // return new ArrayList<>();
} // }
request.setIds(ids); // request.setIds(ids);
request.setNotInTestPlan(true);
return apiAutomationService.list(request); return apiAutomationService.list(request);
} }
@ -88,11 +87,17 @@ public class TestPlanScenarioCaseService {
public String run(RunScenarioRequest request) { public String run(RunScenarioRequest request) {
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria().andIdIn(request.getPlanCaseIds()); example.createCriteria().andIdIn(request.getPlanCaseIds());
List<String> scenarioIds = testPlanApiScenarioMapper.selectByExample(example).stream() List<TestPlanApiScenario> testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
.map(TestPlanApiScenario::getApiScenarioId)
.collect(Collectors.toList()); List<String> scenarioIds = new ArrayList<>();
scenarioIds.addAll(scenarioIds); Map<String,String> scenarioIdApiScarionMap = new HashMap<>();
for (TestPlanApiScenario apiScenario:
testPlanApiScenarioList) {
scenarioIds.add(apiScenario.getApiScenarioId());
scenarioIdApiScarionMap.put(apiScenario.getApiScenarioId(),apiScenario.getId());
}
request.setScenarioIds(scenarioIds); request.setScenarioIds(scenarioIds);
request.setScenarioTestPlanIdMap(scenarioIdApiScarionMap);
request.setRunMode(ApiRunMode.SCENARIO_PLAN.name()); request.setRunMode(ApiRunMode.SCENARIO_PLAN.name());
return apiAutomationService.run(request); return apiAutomationService.run(request);
} }

View File

@ -751,7 +751,7 @@ public class TestPlanService {
* @param request * @param request
* @return * @return
*/ */
public String runApiCase(SchedulePlanScenarioExecuteRequest request) { public String runScenarioCase(SchedulePlanScenarioExecuteRequest request) {
MsTestPlan testPlan = new MsTestPlan(); MsTestPlan testPlan = new MsTestPlan();
testPlan.setHashTree(new LinkedList<>()); testPlan.setHashTree(new LinkedList<>());
HashTree jmeterHashTree = new ListedHashTree(); HashTree jmeterHashTree = new ListedHashTree();

View File

@ -65,11 +65,9 @@
</el-table-column> </el-table-column>
<el-table-column prop="passRate" :label="$t('api_test.automation.passing_rate')" <el-table-column prop="passRate" :label="$t('api_test.automation.passing_rate')"
show-overflow-tooltip/> show-overflow-tooltip/>
<el-table-column :label="$t('commons.operating')" width="200px" v-if="!referenced"> <el-table-column fixed="right" :label="$t('commons.operating')" width="200px" v-if="!referenced">
<template v-slot:default="{row}"> <template v-slot:default="{row}">
<div v-if="trashEnable"> <div v-if="trashEnable">
<!-- <el-button type="text" @click="reductionApi(row)" v-tester>{{ $t('commons.reduction') }}</el-button>-->
<!-- <el-button type="text" @click="remove(row)" v-tester>{{ $t('api_test.automation.remove') }}</el-button>-->
<ms-table-operator-button :tip="$t('commons.reduction')" icon="el-icon-refresh-left" @exec="reductionApi(row)" v-tester/> <ms-table-operator-button :tip="$t('commons.reduction')" icon="el-icon-refresh-left" @exec="reductionApi(row)" v-tester/>
<ms-table-operator-button :tip="$t('api_test.automation.remove')" icon="el-icon-delete" @exec="remove(row)" type="danger" v-tester/> <ms-table-operator-button :tip="$t('api_test.automation.remove')" icon="el-icon-delete" @exec="remove(row)" type="danger" v-tester/>
</div> </div>

View File

@ -168,7 +168,7 @@ export default {
deletePath: "/test/case/delete", deletePath: "/test/case/delete",
selectRows: new Set(), selectRows: new Set(),
buttons: [ buttons: [
{name: this.$t('api_test.definition.request.batch_delete'), handleClick: this.handleDeleteBatch}, {name: this.$t('test_track.case.batch_unlink'), handleClick: this.handleDeleteBatch},
{name: this.$t('api_test.automation.batch_execute'), handleClick: this.handleBatchExecute} {name: this.$t('api_test.automation.batch_execute'), handleClick: this.handleBatchExecute}
], ],
typeArr: [ typeArr: [

View File

@ -117,7 +117,7 @@
runData: [], runData: [],
buttons: [ buttons: [
{ {
name: this.$t('api_test.definition.request.batch_delete'), handleClick: this.handleDeleteBatch name: this.$t('test_track.case.batch_unlink'), handleClick: this.handleDeleteBatch
}, },
{ {
name: this.$t('api_test.automation.batch_execute'), handleClick: this.handleBatchExecute name: this.$t('api_test.automation.batch_execute'), handleClick: this.handleBatchExecute