Merge branch 'feature_1000439'
# Conflicts: # backend/src/main/java/io/metersphere/api/controller/APITestController.java # backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java # frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue # frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue
This commit is contained in:
commit
1909c4267f
|
@ -9,25 +9,37 @@ import io.metersphere.api.dto.datacount.request.ScheduleInfoRequest;
|
|||
import io.metersphere.api.dto.datacount.response.ApiDataCountDTO;
|
||||
import io.metersphere.api.dto.datacount.response.ExecutedCaseInfoDTO;
|
||||
import io.metersphere.api.dto.datacount.response.TaskInfoResult;
|
||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.scenario.request.dubbo.RegistryCenter;
|
||||
import io.metersphere.api.service.*;
|
||||
import io.metersphere.base.domain.ApiTest;
|
||||
import io.metersphere.base.domain.LoadTest;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.constants.ScheduleGroup;
|
||||
import io.metersphere.commons.utils.CronUtils;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
import io.metersphere.performance.service.PerformanceTestService;
|
||||
import io.metersphere.service.CheckPermissionService;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import io.metersphere.track.request.testplan.SaveTestPlanRequest;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -58,6 +70,12 @@ public class APITestController {
|
|||
@Resource
|
||||
private ScheduleService scheduleService;
|
||||
@Resource
|
||||
private APIReportService apiReportService;
|
||||
@Resource
|
||||
private PerformanceTestService performanceTestService;
|
||||
@Resource
|
||||
private CheckPermissionService checkPermissionService;
|
||||
@Resource
|
||||
private HistoricalDataUpgradeService historicalDataUpgradeService;
|
||||
|
||||
@GetMapping("recent/{count}")
|
||||
|
@ -108,6 +126,7 @@ public class APITestController {
|
|||
public void mergeCreate(@RequestPart("request") SaveAPITestRequest request, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "selectIds") List<String> selectIds) {
|
||||
apiTestService.mergeCreate(request, file, selectIds);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
|
||||
public void update(@RequestPart("request") SaveAPITestRequest request, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
checkownerService.checkApiTestOwner(request.getId());
|
||||
|
@ -262,15 +281,15 @@ public class APITestController {
|
|||
List<ApiDataCountResult> countResultByRunResult = apiAutomationService.countRunResultByProjectID(projectId);
|
||||
apiCountResult.countRunResult(countResultByRunResult);
|
||||
|
||||
long allCount = apiCountResult.getUnexecuteCount()+apiCountResult.getExecutionPassCount()+apiCountResult.getExecutionFailedCount();
|
||||
long allCount = apiCountResult.getUnexecuteCount() + apiCountResult.getExecutionPassCount() + apiCountResult.getExecutionFailedCount();
|
||||
|
||||
if(allCount!=0){
|
||||
float coverageRageNumber =(float)apiCountResult.getExecutionPassCount()*100/allCount;
|
||||
if (allCount != 0) {
|
||||
float coverageRageNumber = (float) apiCountResult.getExecutionPassCount() * 100 / allCount;
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
apiCountResult.setPassRage(df.format(coverageRageNumber)+"%");
|
||||
apiCountResult.setPassRage(df.format(coverageRageNumber) + "%");
|
||||
}
|
||||
|
||||
return apiCountResult;
|
||||
return apiCountResult;
|
||||
|
||||
}
|
||||
|
||||
|
@ -362,4 +381,15 @@ public class APITestController {
|
|||
public String historicalDataUpgrade(@RequestBody SaveHistoricalDataUpgrade request) {
|
||||
return historicalDataUpgradeService.upgrade(request);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/genPerformanceTestXml", consumes = {"multipart/form-data"})
|
||||
public JmxInfoDTO genPerformanceTest(@RequestPart("request") RunDefinitionRequest runRequest, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
HashTree hashTree = runRequest.getTestElement().generateHashTree();
|
||||
String jmxString = runRequest.getTestElement().getJmx(hashTree);
|
||||
JmxInfoDTO dto = new JmxInfoDTO();
|
||||
dto.setName(runRequest.getName()+".JMX");
|
||||
dto.setXml(jmxString);
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,24 +2,40 @@ package io.metersphere.api.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.api.dto.JmxInfoDTO;
|
||||
import io.metersphere.api.dto.automation.*;
|
||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.request.*;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.base.domain.ApiScenario;
|
||||
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.performance.service.PerformanceTestService;
|
||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||
import io.metersphere.track.request.testplan.SaveTestPlanRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/automation")
|
||||
|
@ -28,6 +44,8 @@ public class ApiAutomationController {
|
|||
|
||||
@Resource
|
||||
ApiAutomationService apiAutomationService;
|
||||
@Resource
|
||||
PerformanceTestService performanceTestService;
|
||||
|
||||
|
||||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
|
@ -122,5 +140,10 @@ public class ApiAutomationController {
|
|||
apiAutomationService.createSchedule(request);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/genPerformanceTestJmx")
|
||||
public JmxInfoDTO genPerformanceTestJmx(@RequestBody RunScenarioRequest runRequest) {
|
||||
runRequest.setExecuteType(ExecuteType.Completed.name());
|
||||
return apiAutomationService.genPerformanceTestJmx(runRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,19 @@ public class ApiTestCaseController {
|
|||
return apiTestCaseService.list(request);
|
||||
}
|
||||
|
||||
@GetMapping("/findById/{id}")
|
||||
public ApiTestCaseResult single(@PathVariable String id ) {
|
||||
ApiTestCaseRequest request = new ApiTestCaseRequest();
|
||||
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
request.setId(id);
|
||||
List<ApiTestCaseResult> list = apiTestCaseService.list(request);
|
||||
if(!list.isEmpty()){
|
||||
return list.get(0);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
public Pager<List<ApiTestCaseDTO>> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.api.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/1/5 5:48 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class JmxInfoDTO {
|
||||
private String name;
|
||||
private String xml;
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.api.dto.DeleteAPIReportRequest;
|
||||
import io.metersphere.api.dto.JmxInfoDTO;
|
||||
import io.metersphere.api.dto.automation.*;
|
||||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||
|
@ -29,15 +30,18 @@ import io.metersphere.commons.utils.ServiceUtils;
|
|||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.job.sechedule.ApiScenarioTestJob;
|
||||
import io.metersphere.performance.service.PerformanceTestService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import io.metersphere.track.dto.TestPlanDTO;
|
||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||
import io.metersphere.track.request.testplan.SaveTestPlanRequest;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -45,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -73,6 +78,8 @@ public class ApiAutomationService {
|
|||
SqlSessionFactory sqlSessionFactory;
|
||||
@Resource
|
||||
private ApiScenarioReportMapper apiScenarioReportMapper;
|
||||
@Resource
|
||||
private PerformanceTestService performanceTestService;
|
||||
|
||||
public List<ApiScenarioDTO> list(ApiScenarioRequest request) {
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
|
@ -545,4 +552,69 @@ public class ApiAutomationService {
|
|||
scheduleService.addOrUpdateCronJob(
|
||||
request, ApiScenarioTestJob.getJobKey(request.getResourceId()), ApiScenarioTestJob.getTriggerKey(request.getResourceId()), ApiScenarioTestJob.class);
|
||||
}
|
||||
|
||||
public JmxInfoDTO genPerformanceTestJmx(RunScenarioRequest request) {
|
||||
List<ApiScenarioWithBLOBs> apiScenarios = null;
|
||||
List<String> ids = request.getScenarioIds();
|
||||
if (request.isSelectAllDate()) {
|
||||
ids = this.getAllScenarioIdsByFontedSelect(
|
||||
request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
|
||||
}
|
||||
apiScenarios = extApiScenarioMapper.selectIds(ids);
|
||||
MsTestPlan testPlan = new MsTestPlan();
|
||||
testPlan.setHashTree(new LinkedList<>());
|
||||
HashTree jmeterHashTree = new ListedHashTree();
|
||||
try {
|
||||
boolean isFirst = true;
|
||||
for (ApiScenarioWithBLOBs item : apiScenarios) {
|
||||
if (item.getStepTotal() == 0) {
|
||||
MSException.throwException(item.getName() + "," + Translator.get("automation_exec_info"));
|
||||
break;
|
||||
}
|
||||
MsThreadGroup group = new MsThreadGroup();
|
||||
group.setLabel(item.getName());
|
||||
group.setName(UUID.randomUUID().toString());
|
||||
// 批量执行的结果直接存储为报告
|
||||
if (isFirst) {
|
||||
group.setName(request.getId());
|
||||
isFirst = false;
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
JSONObject element = JSON.parseObject(item.getScenarioDefinition());
|
||||
MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class);
|
||||
|
||||
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
||||
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
|
||||
LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"),
|
||||
new TypeReference<LinkedList<MsTestElement>>() {
|
||||
});
|
||||
scenario.setHashTree(elements);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(element.getString("variables"))) {
|
||||
LinkedList<KeyValue> variables = mapper.readValue(element.getString("variables"),
|
||||
new TypeReference<LinkedList<KeyValue>>() {
|
||||
});
|
||||
scenario.setVariables(variables);
|
||||
}
|
||||
group.setEnableCookieShare(scenario.isEnableCookieShare());
|
||||
LinkedList<MsTestElement> scenarios = new LinkedList<>();
|
||||
scenarios.add(scenario);
|
||||
group.setHashTree(scenarios);
|
||||
testPlan.getHashTree().add(group);
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
MSException.throwException(ex.getMessage());
|
||||
}
|
||||
|
||||
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig());
|
||||
String jmx = testPlan.getJmx(jmeterHashTree);
|
||||
String name = request.getName() + ".JMX";
|
||||
|
||||
JmxInfoDTO dto = new JmxInfoDTO();
|
||||
dto.setName(name);
|
||||
dto.setXml(jmx);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,9 +127,7 @@ public class PerformanceTestService {
|
|||
if (files == null) {
|
||||
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
|
||||
checkQuota(request, true);
|
||||
|
||||
final LoadTestWithBLOBs loadTest = saveLoadTest(request);
|
||||
files.forEach(file -> {
|
||||
final FileMetadata fileMetadata = fileService.saveFile(file);
|
||||
|
|
|
@ -107,6 +107,25 @@ public class FileService {
|
|||
return fileMetadata;
|
||||
}
|
||||
|
||||
public FileMetadata saveFile(byte[] fileByte,String fileName,Long fileSize) {
|
||||
final FileMetadata fileMetadata = new FileMetadata();
|
||||
fileMetadata.setId(UUID.randomUUID().toString());
|
||||
fileMetadata.setName(fileName);
|
||||
fileMetadata.setSize(fileSize);
|
||||
fileMetadata.setCreateTime(System.currentTimeMillis());
|
||||
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||
FileType fileType = getFileType(fileMetadata.getName());
|
||||
fileMetadata.setType(fileType.name());
|
||||
fileMetadataMapper.insert(fileMetadata);
|
||||
|
||||
FileContent fileContent = new FileContent();
|
||||
fileContent.setFileId(fileMetadata.getId());
|
||||
fileContent.setFile(fileByte);
|
||||
fileContentMapper.insert(fileContent);
|
||||
|
||||
return fileMetadata;
|
||||
}
|
||||
|
||||
public FileMetadata copyFile(String fileId) {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(fileId);
|
||||
FileContent fileContent = getFileContent(fileId);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="ref">{{ $t('api_test.automation.view_ref') }}</el-dropdown-item>
|
||||
<el-dropdown-item command="schedule" v-tester>{{ $t('api_test.automation.schedule') }}</el-dropdown-item>
|
||||
<el-dropdown-item command="create_performance" v-tester>{{ $t('api_test.create_performance_test') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
<ms-reference-view ref="viewRef"/>
|
||||
<ms-schedule-maintain ref="scheduleMaintain" />
|
||||
|
@ -15,6 +16,7 @@
|
|||
<script>
|
||||
import MsReferenceView from "@/business/components/api/automation/scenario/ReferenceView";
|
||||
import MsScheduleMaintain from "@/business/components/api/automation/schedule/ScheduleMaintain"
|
||||
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
|
||||
|
||||
export default {
|
||||
name: "MsScenarioExtendButtons",
|
||||
|
@ -31,8 +33,34 @@
|
|||
case "schedule":
|
||||
this.$refs.scheduleMaintain.open(this.row);
|
||||
break;
|
||||
case "create_performance":
|
||||
this.createPerformance(this.row);
|
||||
break;
|
||||
}
|
||||
},
|
||||
createPerformance(row) {
|
||||
this.infoDb = false;
|
||||
let url = "/api/automation/genPerformanceTestJmx";
|
||||
let run = {};
|
||||
let scenarioIds = [];
|
||||
scenarioIds.push(row.id);
|
||||
run.projectId = getCurrentProjectID();
|
||||
run.scenarioIds = scenarioIds;
|
||||
run.id = getUUID();
|
||||
run.name = row.name;
|
||||
this.$post(url, run, response => {
|
||||
let jmxObj = {};
|
||||
jmxObj.name = response.data.name;
|
||||
jmxObj.xml = response.data.xml;
|
||||
this.$store.commit('setTest', {
|
||||
name: row.name,
|
||||
jmx: jmxObj
|
||||
})
|
||||
this.$router.push({
|
||||
path: "/performance/test/create"
|
||||
})
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-dialog
|
||||
:title="$t('api_test.environment.select_environment')"
|
||||
:visible.sync="dialogVisible"
|
||||
width="25%"
|
||||
:destroy-on-close="true"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form label-position="right" label-width="150px" size="medium" ref="form">
|
||||
<el-form-item prop="type">
|
||||
<el-select v-model="environmentId" value-key="id" size="small" class="ms-htt-width"
|
||||
:placeholder="$t('api_test.definition.request.run_env')"
|
||||
clearable>
|
||||
<el-option v-for="(environment, index) in environments" :key="index"
|
||||
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
|
||||
:value="environment.id"/>
|
||||
<template v-slot:empty>
|
||||
<div class="empty-environment">
|
||||
</div>
|
||||
</template>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template v-slot:footer>
|
||||
<!-- <el-button onclick="this.handleClose">{{ $t('commons.cancel') }}</el-button>-->
|
||||
<el-button type="primary" @click="createPerformance" @keydown.enter.native.prevent>
|
||||
{{ $t('commons.confirm') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
|
||||
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
|
||||
import {getUUID, getCurrentProjectID} from "@/common/js/utils";
|
||||
|
||||
export default {
|
||||
name: "MsSetEnvironment",
|
||||
components: {},
|
||||
props: {
|
||||
testCase: Object,
|
||||
row: Object,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
filterable: false,
|
||||
environments: [],
|
||||
environmentId: "",
|
||||
dialogTitle: {
|
||||
type: String,
|
||||
default() {
|
||||
return this.$t('api_test.environment.select_environment')
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
environmentId() {
|
||||
this.environmentChange(this.environmentId);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
environmentChange(value) {
|
||||
for (let i in this.environments) {
|
||||
if (this.environments[i].id === value) {
|
||||
this.environment = this.environments[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
getEnvironments() {
|
||||
let selectProjectId = getCurrentProjectID();
|
||||
if (selectProjectId) {
|
||||
this.$get('/api/environment/list/' + selectProjectId, response => {
|
||||
this.environments = response.data;
|
||||
this.environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.environment = undefined;
|
||||
}
|
||||
},
|
||||
open() {
|
||||
this.dialogVisible = true;
|
||||
this.getEnvironments();
|
||||
listenGoBack(this.handleClose);
|
||||
},
|
||||
handleClose() {
|
||||
this.form = {};
|
||||
this.options = [];
|
||||
removeGoBackListener(this.handleClose);
|
||||
},
|
||||
createPerformance() {
|
||||
this.$get('/api/testcase/findById/' + this.testCase.id, response => {
|
||||
let testCaseInfo = response.data;
|
||||
if(testCaseInfo!=null){
|
||||
this.$emit("createPerformance", testCaseInfo, this.environment);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -40,7 +40,7 @@
|
|||
size="mini" :disabled="!apiCase.id || isCaseEdit" circle v-tester/>
|
||||
<ms-tip-button @click="deleteCase(index,apiCase)" :tip="$t('commons.delete')" icon="el-icon-delete"
|
||||
size="mini" :disabled="!apiCase.id || isCaseEdit" circle v-tester/>
|
||||
<ms-api-extend-btns :is-case-edit="isCaseEdit" :row="apiCase" v-tester/>
|
||||
<ms-api-extend-btns :is-case-edit="isCaseEdit" :environment="environment" :row="apiCase" v-tester/>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="3">
|
||||
|
@ -102,7 +102,6 @@
|
|||
return {
|
||||
result: {},
|
||||
grades: [],
|
||||
environment: {},
|
||||
isReadOnly: false,
|
||||
selectedEvent: Object,
|
||||
priorities: PRIORITY,
|
||||
|
@ -121,6 +120,7 @@
|
|||
return {}
|
||||
}
|
||||
},
|
||||
environment: {},
|
||||
index: {
|
||||
type: Number,
|
||||
default() {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
@singleRun="singleRun"
|
||||
@copyCase="copyCase"
|
||||
@showExecResult="showExecResult"
|
||||
:environment="environment"
|
||||
:is-case-edit="isCaseEdit"
|
||||
:api="api"
|
||||
:api-case="item" :index="index"/>
|
||||
|
|
|
@ -85,6 +85,10 @@
|
|||
<api-case-list @showExecResult="showExecResult" @refresh="initTable" :currentApi="selectCase" ref="caseList"/>
|
||||
<!--批量编辑-->
|
||||
<ms-batch-edit ref="batchEdit" @batchEdit="batchEdit" :typeArr="typeArr" :value-arr="valueArr"/>
|
||||
<!--选择环境(当创建性能测试的时候)-->
|
||||
<ms-set-environment ref="setEnvironment" :testCase="clickRow" @createPerformance="createPerformance"/>
|
||||
<!--查看引用-->
|
||||
<ms-reference-view ref="viewRef"/>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
@ -101,17 +105,26 @@
|
|||
import MsBottomContainer from "../BottomContainer";
|
||||
import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn";
|
||||
import MsBatchEdit from "../basis/BatchEdit";
|
||||
import {API_METHOD_COLOUR, CASE_PRIORITY, REQ_METHOD} from "../../model/JsonData";
|
||||
import {API_METHOD_COLOUR, CASE_PRIORITY} from "../../model/JsonData";
|
||||
import {getCurrentProjectID} from "@/common/js/utils";
|
||||
import ApiListContainer from "./ApiListContainer";
|
||||
import PriorityTableItem from "../../../../track/common/tableItems/planview/PriorityTableItem";
|
||||
import ApiCaseList from "../case/ApiCaseList";
|
||||
import {_filter, _sort} from "../../../../../../common/js/utils";
|
||||
import TestPlanCaseListHeader from "../../../../track/plan/view/comonents/api/TestPlanCaseListHeader";
|
||||
import MsEnvironmentSelect from "../case/MsEnvironmentSelect";
|
||||
import {_handleSelect, _handleSelectAll} from "../../../../../../common/js/tableUtils";
|
||||
import MsApiCaseTableExtendBtns from "../reference/ApiCaseTableExtendBtns";
|
||||
import MsReferenceView from "../reference/ReferenceView";
|
||||
import MsSetEnvironment from "@/business/components/api/definition/components/basis/SetEnvironment";
|
||||
import TestPlan from "@/business/components/api/definition/components/jmeter/components/test-plan";
|
||||
import ThreadGroup from "@/business/components/api/definition/components/jmeter/components/thread-group";
|
||||
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
|
||||
|
||||
export default {
|
||||
name: "ApiCaseSimpleList",
|
||||
components: {
|
||||
MsSetEnvironment,
|
||||
ApiCaseList,
|
||||
PriorityTableItem,
|
||||
ApiListContainer,
|
||||
|
@ -123,7 +136,9 @@
|
|||
MsContainer,
|
||||
MsBottomContainer,
|
||||
ShowMoreBtn,
|
||||
MsBatchEdit
|
||||
MsBatchEdit,
|
||||
MsApiCaseTableExtendBtns,
|
||||
MsReferenceView,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -134,6 +149,7 @@
|
|||
selectDataRange: "all",
|
||||
deletePath: "/test/case/delete",
|
||||
selectRows: new Set(),
|
||||
clickRow: {},
|
||||
buttons: [
|
||||
{name: this.$t('api_test.definition.request.batch_delete'), handleClick: this.handleDeleteBatch},
|
||||
{name: this.$t('api_test.definition.request.batch_edit'), handleClick: this.handleEditBatch}
|
||||
|
@ -163,6 +179,7 @@
|
|||
selectAll: false,
|
||||
unSelection: [],
|
||||
selectDataCounts: 0,
|
||||
environments: [],
|
||||
}
|
||||
},
|
||||
props: {
|
||||
|
@ -442,9 +459,87 @@
|
|||
let rowArray = Array.from(rowSets)
|
||||
let ids = rowArray.map(s => s.id);
|
||||
return ids;
|
||||
}
|
||||
},
|
||||
showCaseRef(row) {
|
||||
this.$refs.viewRef.open(row);
|
||||
},
|
||||
showEnvironment(row) {
|
||||
|
||||
let projectID = getCurrentProjectID();
|
||||
if (this.projectId) {
|
||||
this.$get('/api/environment/list/' + this.projectId, response => {
|
||||
this.environments = response.data;
|
||||
this.environments.forEach(environment => {
|
||||
parseEnvironment(environment);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.environment = undefined;
|
||||
}
|
||||
this.clickRow = row;
|
||||
this.$refs.setEnvironment.open(row);
|
||||
},
|
||||
},
|
||||
}
|
||||
createPerformance(row,environment){
|
||||
/**
|
||||
* 思路:调用后台创建性能测试的方法,把当前案例的hashTree在后台转化为jmx并文件创建性能测试。
|
||||
* 然后跳转到修改性能测试的页面
|
||||
*
|
||||
* 性能测试保存地址: performance/save
|
||||
*
|
||||
*/
|
||||
if (!environment) {
|
||||
this.$warning(this.$t('api_test.environment.select_environment'));
|
||||
return;
|
||||
}
|
||||
let runData = [];
|
||||
let singleLoading = true;
|
||||
row.request = JSON.parse( row.request );
|
||||
row.request.name = row.id;
|
||||
row.request.useEnvironment = environment.id;
|
||||
runData.push(row.request);
|
||||
/*触发执行操作*/
|
||||
let testPlan = new TestPlan();
|
||||
let threadGroup = new ThreadGroup();
|
||||
threadGroup.hashTree = [];
|
||||
testPlan.hashTree = [threadGroup];
|
||||
runData.forEach(item => {
|
||||
threadGroup.hashTree.push(item);
|
||||
})
|
||||
let reqObj = {id: row.id,
|
||||
testElement: testPlan,
|
||||
name:row.name,
|
||||
projectId:getCurrentProjectID(),
|
||||
};
|
||||
let bodyFiles = getBodyUploadFiles(reqObj, runData);
|
||||
reqObj.reportId = "run";
|
||||
|
||||
let url = "/api/genPerformanceTestXml";
|
||||
|
||||
this.$fileUpload(url, null, bodyFiles, reqObj, response => {
|
||||
let jmxObj = {};
|
||||
jmxObj.name = response.data.name;
|
||||
jmxObj.xml = response.data.xml;
|
||||
this.$store.commit('setTest', {
|
||||
name: row.name,
|
||||
jmx: jmxObj
|
||||
})
|
||||
this.$router.push({
|
||||
path: "/performance/test/create"
|
||||
})
|
||||
// let performanceId = response.data;
|
||||
// if(performanceId!=null){
|
||||
// this.$router.push({
|
||||
// path: "/performance/test/edit/"+performanceId,
|
||||
// })
|
||||
// }
|
||||
}, erro => {
|
||||
this.$emit('runRefresh', {});
|
||||
});
|
||||
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<template>
|
||||
<el-dropdown @command="handleCommand" class="scenario-ext-btn">
|
||||
<el-link type="primary" :underline="false">
|
||||
<el-icon class="el-icon-more"></el-icon>
|
||||
</el-link>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="ref">{{ $t('api_test.automation.view_ref') }}</el-dropdown-item>
|
||||
<el-dropdown-item command="create_performance">{{ $t('api_test.create_performance_test') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: "MsApiCaseTableExtendBtns",
|
||||
components: {},
|
||||
props: {
|
||||
row: Object,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
planVisible: false,
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleCommand(cmd) {
|
||||
if (this.row.id) {
|
||||
switch (cmd) {
|
||||
case "ref":
|
||||
this.$emit("showCaseRef", this.row);
|
||||
break;
|
||||
case "create_performance":
|
||||
this.$emit("showEnvironment", this.row);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
this.$warning(this.$t('api_test.automation.save_case_info'))
|
||||
}
|
||||
},
|
||||
createPerformance(row, environment) {
|
||||
this.$emit("createPerformance", row, environment);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.scenario-ext-btn {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
|
@ -5,7 +5,8 @@
|
|||
</el-link>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="ref">{{ $t('api_test.automation.view_ref') }}</el-dropdown-item>
|
||||
<!--<el-dropdown-item :disabled="isCaseEdit" command="add_plan">{{ $t('api_test.automation.batch_add_plan') }}</el-dropdown-item>-->
|
||||
<!-- <el-dropdown-item :disabled="isCaseEdit" command="add_plan">{{ $t('api_test.automation.batch_add_plan') }}</el-dropdown-item>-->
|
||||
<el-dropdown-item :disabled="isCaseEdit" command="create_performance">{{ $t('api_test.create_performance_test') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
<ms-reference-view ref="viewRef"/>
|
||||
<!--测试计划-->
|
||||
|
@ -18,6 +19,9 @@
|
|||
<script>
|
||||
import MsReferenceView from "./ReferenceView";
|
||||
import MsTestPlanList from "../../../automation/scenario/testplan/TestPlanList";
|
||||
import {getBodyUploadFiles, getCurrentProjectID, getUUID} from "@/common/js/utils";
|
||||
import TestPlan from "@/business/components/api/definition/components/jmeter/components/test-plan";
|
||||
import ThreadGroup from "@/business/components/api/definition/components/jmeter/components/thread-group";
|
||||
|
||||
export default {
|
||||
name: "MsApiExtendBtns",
|
||||
|
@ -25,6 +29,7 @@
|
|||
props: {
|
||||
row: Object,
|
||||
isCaseEdit: Boolean,
|
||||
environment: {},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -42,11 +47,73 @@
|
|||
case "add_plan":
|
||||
this.addCaseToPlan();
|
||||
break;
|
||||
case "create_performance":
|
||||
this.createPerformance(this.row);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
this.$warning(this.$t('api_test.automation.save_case_info'))
|
||||
}
|
||||
},
|
||||
createPerformance(row){
|
||||
/**
|
||||
* 思路:调用后台创建性能测试的方法,把当前案例的hashTree在后台转化为jmx并文件创建性能测试。
|
||||
* 然后跳转到修改性能测试的页面
|
||||
*
|
||||
* 性能测试保存地址: performance/save
|
||||
*
|
||||
*/
|
||||
if (!this.environment || !this.environment) {
|
||||
this.$warning(this.$t('api_test.environment.select_environment'));
|
||||
return;
|
||||
}
|
||||
this.runData = [];
|
||||
this.singleLoading = true;
|
||||
this.row.request.name = this.row.id;
|
||||
this.row.request.useEnvironment = this.environment.id;
|
||||
this.runData.push(this.row.request);
|
||||
/*触发执行操作*/
|
||||
let testPlan = new TestPlan();
|
||||
let threadGroup = new ThreadGroup();
|
||||
threadGroup.hashTree = [];
|
||||
testPlan.hashTree = [threadGroup];
|
||||
this.runData.forEach(item => {
|
||||
threadGroup.hashTree.push(item);
|
||||
})
|
||||
let reqObj = {id: this.row.id,
|
||||
testElement: testPlan,
|
||||
type: this.type,
|
||||
name:this.row.name,
|
||||
projectId:getCurrentProjectID(),
|
||||
};
|
||||
|
||||
let bodyFiles = getBodyUploadFiles(reqObj, this.runData);
|
||||
reqObj.reportId = "run";
|
||||
// let url = "/api/genPerformanceTest";
|
||||
let url = "/api/genPerformanceTestXml";
|
||||
|
||||
this.$fileUpload(url, null, bodyFiles, reqObj, response => {
|
||||
let jmxObj = {};
|
||||
jmxObj.name = response.data.name;
|
||||
jmxObj.xml = response.data.xml;
|
||||
this.$store.commit('setTest', {
|
||||
name: row.name,
|
||||
jmx: jmxObj
|
||||
})
|
||||
this.$router.push({
|
||||
path: "/performance/test/create"
|
||||
})
|
||||
// let performanceId = response.data;
|
||||
// if(performanceId!=null){
|
||||
// this.$router.push({
|
||||
// path: "/performance/test/edit/"+performanceId,
|
||||
// })
|
||||
// }
|
||||
}, erro => {
|
||||
this.$emit('runRefresh', {});
|
||||
});
|
||||
|
||||
},
|
||||
addCaseToPlan() {
|
||||
this.planVisible = true;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue