feat: 测试计划接口测试批量执行

This commit is contained in:
chenjianxing 2020-12-22 21:58:44 +08:00
parent 2581666165
commit 8f23ae9473
4 changed files with 111 additions and 133 deletions

View File

@ -2,7 +2,7 @@
<div></div>
</template>
<script>
import {getUUID} from "@/common/js/utils";
import {getUUID, getBodyUploadFiles} from "@/common/js/utils";
import ThreadGroup from "./jmeter/components/thread-group";
import TestPlan from "./jmeter/components/test-plan";
@ -56,49 +56,6 @@
});
}
},
getBodyUploadFiles(obj) {
let bodyUploadFiles = [];
obj.bodyUploadIds = [];
if (this.runData) {
this.runData.forEach(request => {
if (request.body) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
if (request.body.binary) {
request.body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
});
}
return bodyUploadFiles;
},
run() {
let testPlan = new TestPlan();
let threadGroup = new ThreadGroup();
@ -108,7 +65,7 @@
threadGroup.hashTree.push(item);
})
let reqObj = {id: this.reportId, testElement: testPlan, type: this.type};
let bodyFiles = this.getBodyUploadFiles(reqObj);
let bodyFiles = getBodyUploadFiles(reqObj, this.runData);
let url = "";
if (this.debug) {
url = "/api/definition/run/debug";

View File

@ -81,7 +81,6 @@
<el-table-column v-if="!isReadOnly" :label="$t('commons.operating')" align="center">
<template v-slot:default="scope">
<!--<el-button type="text" @click="handleTestCase(scope.row)">{{$t('commons.edit')}}</el-button>-->
<el-button type="text" @click="singleRun(scope.row)">{{$t('api_test.run')}}</el-button>
<el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C">{{$t('commons.delete')}}</el-button>
</template>
@ -91,13 +90,8 @@
<ms-table-pagination :change="initTable" :current-page.sync="currentPage" :page-size.sync="pageSize"
:total="total"/>
<!--<api-case-list @showExecResult="showExecResult" @refresh="initTable" :currentApi="selectCase" ref="caseList"/>-->
<test-plan-api-case-result :response="response" ref="apiCaseResult"/>
<!--批量编辑-->
<!--<ms-batch-edit ref="batchEdit" @batchEdit="batchEdit" :typeArr="typeArr" :value-arr="valueArr"/>-->
<!-- 执行组件 -->
<ms-run :debug="false" :type="'API_PLAN'" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
@ -124,11 +118,12 @@
import ApiListContainer from "../../../../../api/definition/components/list/ApiListContainer";
import PriorityTableItem from "../../../../common/tableItems/planview/PriorityTableItem";
import ApiCaseList from "../../../../../api/definition/components/case/ApiCaseList";
import {_filter, _sort, getUUID} from "../../../../../../../common/js/utils";
import {_filter, _sort, getUUID, getBodyUploadFiles} from "../../../../../../../common/js/utils";
import TestPlanCaseListHeader from "./TestPlanCaseListHeader";
import MsRun from "../../../../../api/definition/components/Run";
import TestPlanApiCaseResult from "./TestPlanApiCaseResult";
import TestPlan from "../../../../../api/definition/components/jmeter/components/test-plan";
import ThreadGroup from "../../../../../api/definition/components/jmeter/components/thread-group";
export default {
name: "TestPlanApiCaseList",
@ -159,7 +154,7 @@
selectRows: new Set(),
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}
{name: this.$t('api_test.automation.batch_execute'), handleClick: this.handleBatchExecute}
],
typeArr: [
{id: 'priority', name: this.$t('test_track.case.priority')},
@ -320,24 +315,6 @@
buildPagePath(path) {
return path + "/" + this.currentPage + "/" + this.pageSize;
},
handleTestCase(testCase) {
this.$get('/api/definition/get/' + testCase.apiDefinitionId, (response) => {
let api = response.data;
let selectApi = api;
let request = {};
if (Object.prototype.toString.call(api.request).match(/\[object (\w+)\]/)[1].toLowerCase() === 'object') {
request = api.request;
} else {
request = JSON.parse(api.request);
}
if (!request.hashTree) {
request.hashTree = [];
}
selectApi.url = request.path;
this.currentCaseProjectId = testCase.projectId;
this.$refs.caseList.open(selectApi, testCase.id);
});
},
reductionApi(row) {
let ids = [row.id];
this.$post('/api/testcase/reduction/', ids, () => {
@ -395,44 +372,46 @@
this.reportId = getUUID().substring(0, 8);
});
},
// batchRun() {
// if (!this.environment) {
// this.$warning(this.$t('api_test.environment.select_environment'));
// return;
// }
// if (this.apiCaseList.length > 0) {
// this.apiCaseList.forEach(item => {
// if (item.id) {
// item.request.name = item.id;
// item.request.useEnvironment = this.environment.id;
// this.runData.push(item.request);
// }
// })
// if (this.runData.length > 0) {
// // this.batchLoading = true;
// /**/
// this.reportId = getUUID().substring(0, 8);
// } else {
// this.$warning("");
// }
// } else {
// this.$warning("");
// }
// },
// handleEditBatch() {
// this.$refs.batchEdit.open();
// },
// batchEdit(form) {
// let arr = Array.from(this.selectRows);
// let ids = arr.map(row => row.id);
// let param = {};
// param[form.type] = form.value;
// param.ids = ids;
// this.$post('/api/testcase/batch/edit', param, () => {
// this.$success(this.$t('commons.save_success'));
// this.initTable();
// });
// },
batchEdit(form) {
let arr = Array.from(this.selectRows);
let ids = arr.map(row => row.id);
let param = {};
param[form.type] = form.value;
param.ids = ids;
this.$post('/api/testcase/batch/edit', param, () => {
this.$success(this.$t('commons.save_success'));
this.initTable();
});
},
handleBatchExecute() {
this.selectRows.forEach(row => {
this.$get('/api/testcase/get/' + row.caseId, (response) => {
let apiCase = response.data;
let request = JSON.parse(apiCase.request);
request.name = row.id;
request.id = row.id;
request.useEnvironment = row.environmentId;
let runData = [];
runData.push(request);
this.batchRun(runData, getUUID().substring(0, 8));
});
});
this.$message('任务执行中,请稍后刷新查看结果');
this.search();
},
batchRun(runData, reportId) {
let testPlan = new TestPlan();
let threadGroup = new ThreadGroup();
threadGroup.hashTree = [];
testPlan.hashTree = [threadGroup];
runData.forEach(item => {
threadGroup.hashTree.push(item);
});
let reqObj = {id: reportId, testElement: testPlan, type: 'API_PLAN', reportId: "run"};
let bodyFiles = getBodyUploadFiles(reqObj, runData);
this.$fileUpload("/api/definition/run", null, bodyFiles, reqObj, response => {
});
},
handleDelete(apiCase) {
this.$get('/test/plan/api/case/delete/' + this.planId + '/' + apiCase.id, () => {
this.$success(this.$t('commons.delete_success'));

View File

@ -115,9 +115,9 @@
{
name: this.$t('api_test.definition.request.batch_delete'), 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
}
],
selectRows: new Set()
}
@ -149,19 +149,6 @@
this.loading = false;
});
},
handleBatchExecute() {
this.infoDb = false;
let url = "/test/plan/scenario/case/run";
let run = {};
run.planCaseIds = Array.from(this.selectRows).map(row => row.id);
run.id = getUUID();
run.projectId = getCurrentProjectID();
this.$post(url, run, response => {
let data = response.data;
this.runVisible = true;
this.reportId = run.id;
});
},
reductionApi(row) {
row.scenarioDefinition = null;
let rows = [row];
@ -170,19 +157,31 @@
this.search();
})
},
handleBatchExecute() {
this.selectRows.forEach(row => {
let param = this.buildExecuteParam(row);
this.$post("/test/plan/scenario/case/run", param, response => {
});
});
this.$message('任务执行中,请稍后刷新查看结果');
this.search();
},
execute(row) {
this.infoDb = false;
let url = "/test/plan/scenario/case/run";
let run = {};
run.id = row.id;
run.projectId = row.projectId;
run.planCaseIds = [];
run.planCaseIds.push(row.id);
this.$post(url, run, response => {
let param = this.buildExecuteParam(row);
this.$post("/test/plan/scenario/case/run", param, response => {
this.runVisible = true;
this.reportId = response.data;
});
},
buildExecuteParam(row) {
let param = {};
param.id = row.id;
param.projectId = row.projectId;
param.planCaseIds = [];
param.planCaseIds.push(row.id);
return param;
},
showReport(row) {
this.runVisible = true;
this.infoDb = true;

View File

@ -299,3 +299,46 @@ export function windowPrint(id, zoom) {
return false;
}
export function getBodyUploadFiles(obj, runData) {
let bodyUploadFiles = [];
obj.bodyUploadIds = [];
if (runData) {
runData.forEach(request => {
if (request.body) {
request.body.kvs.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
if (request.body.binary) {
request.body.binary.forEach(param => {
if (param.files) {
param.files.forEach(item => {
if (item.file) {
if (!item.id) {
let fileId = getUUID().substring(0, 12);
item.name = item.file.name;
item.id = fileId;
}
obj.bodyUploadIds.push(item.id);
bodyUploadFiles.push(item.file);
}
});
}
});
}
}
});
}
return bodyUploadFiles;
}