feat(接口测试): Mock设置的表格中增加执行按钮

Mock设置的表格中增加执行按钮,点击直接跳转执行页面,并将mock设置的参数赋值过去
This commit is contained in:
song-tianyang 2022-02-07 18:50:47 +08:00 committed by 刘瑞斌
parent 688857e62b
commit 6d2e0d3c75
6 changed files with 526 additions and 440 deletions

View File

@ -44,6 +44,7 @@
@saveAsApi="editApi"
@saveAsCase="saveAsCase"
@refresh="refresh"
ref="httpTestPage"
v-if="currentProtocol==='HTTP'"
/>
<ms-run-test-tcp-page
@ -54,6 +55,7 @@
@saveAsApi="editApi"
@saveAsCase="saveAsCase"
@refresh="refresh"
ref="tcpTestPage"
v-if="currentProtocol==='TCP'"
/>
<ms-run-test-sql-page
@ -78,11 +80,9 @@
/>
</div>
<div v-if="showMock && (currentProtocol === 'HTTP')">
<mock-tab :base-mock-config-data="baseMockConfigData" :is-tcp="false"/>
</div>
<div v-if="showMock && (currentProtocol === 'TCP')">
<mock-tab :base-mock-config-data="baseMockConfigData" :is-tcp="true"/>
<div v-if="showMock && (currentProtocol === 'HTTP' || currentProtocol === 'TCP')">
<mock-tab :base-mock-config-data="baseMockConfigData" @redirectToTest="redirectToTest"
:is-tcp="currentProtocol === 'TCP'"/>
</div>
<div v-if="showTestCaseList">
<!--测试用例列表-->
@ -275,6 +275,20 @@ export default {
changeTab(tabType) {
this.refreshButtonActiveClass(tabType);
},
redirectToTest(param) {
this.refreshButtonActiveClass("test");
this.$nextTick(() => {
if (this.currentProtocol === "HTTP" && this.$refs.httpTestPage) {
let requestParam = null;
if (param.params) {
requestParam = param.params;
}
this.$refs.httpTestPage.setRequestParam(requestParam);
} else if (this.currentProtocol === "TCP" && this.$refs.tcpTestPage) {
this.$refs.tcpTestPage.setRequestParam(param);
}
});
},
removeListener() {
if (this.$refs && this.$refs.apiConfig) {
this.$refs.apiConfig.removeListener();

View File

@ -216,20 +216,19 @@ export default {
modeChange(mode) {
switch (this.body.type) {
case "JSON":
// this.setContentType("application/json");
this.setContentType("application/json");
break;
case "XML":
// this.setContentType("text/xml");
this.setContentType("text/xml");
break;
case "WWW_FORM":
// this.setContentType("application/x-www-form-urlencoded");
this.setContentType("application/x-www-form-urlencoded");
break;
case "BINARY":
this.setContentType("application/octet-stream");
break;
// todo from data
// case "BINARY":
// this.setContentType("application/octet-stream");
// break;
default:
// this.removeContentType();
this.removeContentType();
break;
}
},

View File

@ -91,13 +91,13 @@ export default {
name: 'MockTab',
components: {
MockEditDrawer,
MsTable,MsTableColumn,MsTag
MsTable, MsTableColumn, MsTag
},
props: {
baseMockConfigData: {},
isTcp:{
type:Boolean,
default:false,
isTcp: {
type: Boolean,
default: false,
},
},
data() {
@ -105,11 +105,18 @@ export default {
result: {},
visible: false,
mockConfigData: {},
tableSearch:"",
tableSearch: "",
apiParams: {},
pageSize: 10,
screenHeight:document.documentElement.clientHeight - 250,
screenHeight: document.documentElement.clientHeight - 250,
operators: [
{
tip: this.$t('api_test.automation.execute'),
icon: "el-icon-video-play",
exec: this.redirectToTest,
class: "run-button",
permissions: ['PROJECT_API_DEFINITION:READ+RUN']
},
{
tip: this.$t('commons.edit'), icon: "el-icon-edit",
exec: this.clickRow,
@ -129,7 +136,7 @@ export default {
},
watch: {
baseMockConfigData(){
baseMockConfigData() {
this.mockConfigData = this.baseMockConfigData;
}
},
@ -143,18 +150,25 @@ export default {
},
},
methods: {
redirectToTest(row) {
let requestParam = null;
if (row && row.request) {
requestParam = row.request;
}
this.$emit("redirectToTest", requestParam);
},
searchApiParams(apiId) {
let selectUrl = "/mockConfig/getApiParams/" + apiId;
this.$get(selectUrl, response => {
this.apiParams = response.data;
if(!this.apiParams.query){
if (!this.apiParams.query) {
this.apiParams.query = [];
}
if(!this.apiParams.rest){
if (!this.apiParams.rest) {
this.apiParams.rest = [];
}
if(!this.apiParams.form){
if (!this.apiParams.form) {
this.apiParams.form = [];
}
});
@ -223,7 +237,7 @@ export default {
});
});
},
addApiMock(){
addApiMock() {
this.searchApiParams(this.mockConfigData.mockConfig.apiId);
this.$refs.mockEditDrawer.close();
this.$nextTick(() => {
@ -274,6 +288,7 @@ export default {
.ms-drawer >>> .ms-drawer-body {
margin-top: 40px;
}
.search-input {
float: right;
width: 300px;

View File

@ -1,14 +1,15 @@
<template>
<div>
<div v-if="!isReloadData">
<el-row>
<el-col :span="spanNum" style="padding-bottom: 20px">
<div style="border:1px #DCDFE6 solid; height: 100%;border-radius: 4px ;width: 100% ;">
<el-form class="tcp" :model="request" :rules="rules" ref="request" :disabled="isReadOnly" style="margin: 20px">
<el-form class="tcp" :model="request" :rules="rules" ref="request" :disabled="isReadOnly"
style="margin: 20px">
<el-tabs v-model="activeName" class="request-tabs">
<!--test-->
<el-tab-pane name="parameters">
<template v-slot:label>
{{$t('api_test.definition.request.req_param')}}
{{ $t('api_test.definition.request.req_param') }}
<ms-instructions-icon :content="$t('api_test.definition.request.tcp_parameter_tip')"/>
</template>
<ms-api-variable :is-read-only="isReadOnly" :parameters="request.parameters"/>
@ -36,12 +37,14 @@
</div>
<div v-if="request.reportType === 'json'">
<div class="send-request">
<ms-code-edit mode="json" :read-only="isReadOnly" :data.sync="request.jsonDataStruct" :modes="['text', 'json', 'xml', 'html']" theme="eclipse"/>
<ms-code-edit mode="json" :read-only="isReadOnly" :data.sync="request.jsonDataStruct"
:modes="['text', 'json', 'xml', 'html']" theme="eclipse"/>
</div>
</div>
<div v-if="request.reportType === 'raw'">
<div class="send-request">
<ms-code-edit mode="text" :read-only="isReadOnly" :data.sync="request.rawDataStruct" :modes="['text', 'json', 'xml', 'html']" theme="eclipse"/>
<ms-code-edit mode="text" :read-only="isReadOnly" :data.sync="request.rawDataStruct"
:modes="['text', 'json', 'xml', 'html']" theme="eclipse"/>
</div>
</div>
</el-tab-pane>
@ -117,7 +120,8 @@
<el-col :span="6">
<el-form-item label="Connect encoding">
<el-select v-model="request.connectEncoding" style="width: 100px" size="small">
<el-option v-for="item in connectEncodingArr" :key="item.key" :label="item.value" :value="item.key"/>
<el-option v-for="item in connectEncodingArr" :key="item.key" :label="item.value"
:value="item.key"/>
</el-select>
</el-form-item>
</el-col>
@ -136,395 +140,400 @@
</template>
<script>
import MsApiKeyValue from "../../ApiKeyValue";
import MsApiAssertions from "../../assertion/ApiAssertions";
import MsApiExtract from "../../extract/ApiExtract";
import ApiRequestMethodSelect from "../../collapse/ApiRequestMethodSelect";
import MsCodeEdit from "../../../../../common/components/MsCodeEdit";
import MsApiScenarioVariables from "../../ApiScenarioVariables";
import {createComponent} from "../../jmeter/components";
import {Assertions, Extract} from "../../../model/ApiTestModel";
import {parseEnvironment} from "../../../model/EnvironmentModel";
import ApiEnvironmentConfig from "../../environment/ApiEnvironmentConfig";
import {API_STATUS} from "../../../model/JsonData";
import TCPSampler from "../../jmeter/components/sampler/tcp-sampler";
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
import MsApiVariable from "../../ApiVariable";
import MsInstructionsIcon from "../../../../../common/components/MsInstructionsIcon";
import Jsr233ProcessorContent from "../../../../automation/scenario/common/Jsr233ProcessorContent";
import JSR223PreProcessor from "../../jmeter/components/pre-processors/jsr223-pre-processor";
import ApiDefinitionStepButton from "../components/ApiDefinitionStepButton";
import TcpXmlTable from "@/business/components/api/definition/components/complete/table/TcpXmlTable";
import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
import MsApiKeyValue from "../../ApiKeyValue";
import MsApiAssertions from "../../assertion/ApiAssertions";
import MsApiExtract from "../../extract/ApiExtract";
import ApiRequestMethodSelect from "../../collapse/ApiRequestMethodSelect";
import MsCodeEdit from "../../../../../common/components/MsCodeEdit";
import MsApiScenarioVariables from "../../ApiScenarioVariables";
import {createComponent} from "../../jmeter/components";
import {Assertions, Extract} from "../../../model/ApiTestModel";
import {parseEnvironment} from "../../../model/EnvironmentModel";
import ApiEnvironmentConfig from "../../environment/ApiEnvironmentConfig";
import {API_STATUS} from "../../../model/JsonData";
import TCPSampler from "../../jmeter/components/sampler/tcp-sampler";
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
import MsApiVariable from "../../ApiVariable";
import MsInstructionsIcon from "../../../../../common/components/MsInstructionsIcon";
import Jsr233ProcessorContent from "../../../../automation/scenario/common/Jsr233ProcessorContent";
import JSR223PreProcessor from "../../jmeter/components/pre-processors/jsr223-pre-processor";
import ApiDefinitionStepButton from "../components/ApiDefinitionStepButton";
import TcpXmlTable from "@/business/components/api/definition/components/complete/table/TcpXmlTable";
import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
export default {
name: "MsTcpFormatParameters",
components: {
TcpXmlTable,
ApiDefinitionStepButton,
Jsr233ProcessorContent,
MsInstructionsIcon,
MsApiVariable,
MsApiScenarioVariables,
MsCodeEdit,
ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiKeyValue, ApiEnvironmentConfig
export default {
name: "MsTcpFormatParameters",
components: {
TcpXmlTable,
ApiDefinitionStepButton,
Jsr233ProcessorContent,
MsInstructionsIcon,
MsApiVariable,
MsApiScenarioVariables,
MsCodeEdit,
ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiKeyValue, ApiEnvironmentConfig
},
props: {
request: {},
basisData: {},
moduleOptions: Array,
isReadOnly: {
type: Boolean,
default: false
},
props: {
request: {},
basisData: {},
moduleOptions: Array,
isReadOnly: {
type: Boolean,
default: false
},
showScript: {
type: Boolean,
default: true,
},
referenced: {
type: Boolean,
default: false,
},
showScript: {
type: Boolean,
default: true,
},
data() {
return {
spanNum: 21,
activeName: "request",
classes: TCPSampler.CLASSES,
reportType:"xml",
isReloadData: false,
refreshedXmlTable:true,
options: API_STATUS,
currentProjectId: "",
connectEncodingArr:[
{
'key':'UTF-8',
'value':'UTF-8',
},
{
'key':'GBK',
'value':'GBK',
},
],
rules: {
classname: [{required: true, message: "请选择TCPClient", trigger: 'change'}],
server: [{required: true, message: this.$t('api_test.request.tcp.server_cannot_be_empty'), trigger: 'blur'}],
port: [{required: true, message: this.$t('commons.port_cannot_be_empty'), trigger: 'change'}],
referenced: {
type: Boolean,
default: false,
},
},
data() {
return {
spanNum: 21,
activeName: "request",
classes: TCPSampler.CLASSES,
reportType: "xml",
isReloadData: false,
refreshedXmlTable: true,
options: API_STATUS,
currentProjectId: "",
connectEncodingArr: [
{
'key': 'UTF-8',
'value': 'UTF-8',
},
}
},
watch:{
reportType(){
this.request.reportType = this.reportType;
}
},
created() {
if(!this.referenced && this.showScript){
this.spanNum = 21;
}else {
this.spanNum = 24;
}
this.currentProjectId = getCurrentProjectID();
if (!this.request.parameters) {
this.$set(this.request, 'parameters', []);
this.request.parameters = [];
}
if (!this.request.tcpPreProcessor) {
this.$set(this.request, 'tcpPreProcessor', new JSR223PreProcessor())
}
if(this.request.tcpPreProcessor){
this.request.tcpPreProcessor.clazzName = TYPE_TO_C.get(this.request.tcpPreProcessor.type);
}
if(!this.request.connectEncoding){
this.request.connectEncoding = "UTF-8";
}
this.getEnvironments();
{
'key': 'GBK',
'value': 'GBK',
},
],
rules: {
classname: [{required: true, message: "请选择TCPClient", trigger: 'change'}],
server: [{required: true, message: this.$t('api_test.request.tcp.server_cannot_be_empty'), trigger: 'blur'}],
port: [{required: true, message: this.$t('commons.port_cannot_be_empty'), trigger: 'change'}],
},
}
},
watch: {
reportType() {
this.request.reportType = this.reportType;
}
},
created() {
if (!this.referenced && this.showScript) {
this.spanNum = 21;
} else {
this.spanNum = 24;
}
this.currentProjectId = getCurrentProjectID();
if (!this.request.parameters) {
this.$set(this.request, 'parameters', []);
this.request.parameters = [];
}
if (!this.request.tcpPreProcessor) {
this.$set(this.request, 'tcpPreProcessor', new JSR223PreProcessor())
}
if (this.request.tcpPreProcessor) {
this.request.tcpPreProcessor.clazzName = TYPE_TO_C.get(this.request.tcpPreProcessor.type);
}
if (!this.request.connectEncoding) {
this.request.connectEncoding = "UTF-8";
}
this.getEnvironments();
if(this.request){
if (this.request) {
//
if(!this.request.xmlDataStruct && !this.request.jsonDataStruct && !this.request.rawDataStruct){
this.request.rawDataStruct = this.request.request;
//
if (!this.request.xmlDataStruct && !this.request.jsonDataStruct && !this.request.rawDataStruct) {
this.request.rawDataStruct = this.request.request;
this.request.reportType = "raw";
}
if (!this.request.reportType) {
this.request.reportType = "raw";
} else {
if (this.request.reportType !== "json" && this.request.reportType !== "xml" && this.request.reportType !== "raw") {
this.request.reportType = "raw";
}
if(!this.request.reportType){
this.request.reportType = "raw";
}else {
if(this.request.reportType !== "json" && this.request.reportType !== "xml"&&this.request.reportType !== "raw"){
this.request.reportType = "raw";
}
}
this.reportType = this.request.reportType;
if(!this.request.xmlDataStruct){
this.initXmlTableData();
}
}
},
methods: {
addPre() {
let jsr223PreProcessor = createComponent("JSR223PreProcessor");
this.request.hashTree.push(jsr223PreProcessor);
this.reload();
},
addPost() {
let jsr223PostProcessor = createComponent("JSR223PostProcessor");
this.request.hashTree.push(jsr223PostProcessor);
this.reload();
},
addAssertions() {
let assertions = new Assertions();
this.request.hashTree.push(assertions);
this.reload();
},
addExtract() {
let jsonPostProcessor = new Extract();
this.request.hashTree.push(jsonPostProcessor);
this.reload();
},
remove(row) {
let index = this.request.hashTree.indexOf(row);
this.request.hashTree.splice(index, 1);
this.reload();
},
copyRow(row) {
let obj =JSON.parse(JSON.stringify(row));
obj.id = getUUID();
this.request.hashTree.push(obj);
this.reload();
},
reload() {
this.isReloadData = true
this.$nextTick(() => {
this.isReloadData = false
})
},
validateApi() {
if (this.currentProjectId === null) {
this.$error(this.$t('api_test.select_project'), 2000);
return;
}
this.$refs['basicForm'].validate();
},
saveApi() {
this.basisData.method = this.basisData.protocol;
this.$emit('saveApi', this.basisData);
},
runTest() {
},
validate() {
if (this.currentProjectId === null) {
this.$error(this.$t('api_test.select_project'), 2000);
return;
}
this.$refs['request'].validate((valid) => {
if (valid) {
this.$emit('callback');
}
})
},
getEnvironments() {
if (this.currentProjectId) {
this.environments = [];
this.$get('/api/environment/list/' + this.currentProjectId, response => {
this.environments = response.data;
this.environments.forEach(environment => {
parseEnvironment(environment);
});
this.initDataSource();
});
}
},
openEnvironmentConfig() {
if (!this.currentProjectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(this.currentProjectId);
},
initDataSource() {
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
this.databaseConfigsOptions.push(item);
})
break;
}
}
},
environmentChange(value) {
this.request.dataSource = undefined;
for (let i in this.environments) {
if (this.environments[i].id === value) {
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
this.databaseConfigsOptions.push(item);
})
break;
}
}
},
environmentConfigClose() {
this.getEnvironments();
},
changeReportType(){
},
//xml
updateXmlTableData(dataStruct){
this.request.xmlDataStruct = dataStruct;
},
saveXmlTableData(dataStruct){
let valedataResult = this.validateXmlDataStruct(dataStruct);
if(valedataResult){
this.request.xmlDataStruct = dataStruct;
this.refreshXmlTable();
}
},
validateXmlDataStruct(){
if(this.request.xmlDataStruct){
this.refreshXmlTableDataStruct(this.request.xmlDataStruct);
let result = this.checkXmlTableDataStructData(this.request.xmlDataStruct);
return result;
}
},
refreshXmlTableDataStruct(dataStruct){
if(dataStruct && dataStruct.length > 0){
dataStruct.forEach( row => {
row.status = "";
if(row.children == null || row.children.length === 0){
row.children = [];
}else if(row.children.length>0){
this.refreshXmlTableDataStruct(row.children);
}
});
}
},
checkXmlTableDataStructData(dataStruct){
let allCheckResult = true;
if(this.$refs.treeTable){
if(dataStruct && dataStruct.length > 0){
for(let i = 0;i<dataStruct.length;i++){
let row = dataStruct[i];
allCheckResult = this.$refs.treeTable.validateRowData(row);
if(allCheckResult){
if(row.children != null && row.children.length > 0){
allCheckResult = this.checkXmlTableDataStructData(row.children);
if(!allCheckResult){
return false;
}
}
}else{
return false;
}
}
}
}
return allCheckResult;
},
initXmlTableData(){
if(this.request){
this.request.xmlDataStruct = [];
this.refreshXmlTable();
}
},
xmlTableDataPushRow(newRow){
if(this.request){
if(!this.request.xmlDataStruct){
this.request.xmlDataStruct = [];
}
this.request.xmlDataStruct.push(newRow);
this.refreshXmlTable();
}
},
xmlTableDataRemoveRow(row){
if(this.request){
if(this.request.xmlDataStruct){
this.removeFromDataStruct(this.request.xmlDataStruct,row);
this.refreshXmlTable();
}
}
},
removeFromDataStruct(dataStruct,row){
if(!dataStruct || dataStruct.length === 0){
return;
}
let rowIndex = dataStruct.indexOf(row);
if(rowIndex >= 0){
dataStruct.splice(rowIndex,1);
}else {
dataStruct.forEach( itemData => {
if(!itemData.children && itemData.children.length > 0){
this.removeFromDataStruct(itemData.children,row);
}
});
}
},
refreshXmlTable(){
this.refreshedXmlTable = true
this.$nextTick(() => {
this.refreshedXmlTable = false
})
},
xmlTablePushRow(row){
this.request.xmlDataStruct.push(row);
this.reportType = this.request.reportType;
if (!this.request.xmlDataStruct) {
this.initXmlTableData();
}
}
},
methods: {
addPre() {
let jsr223PreProcessor = createComponent("JSR223PreProcessor");
this.request.hashTree.push(jsr223PreProcessor);
this.reload();
},
addPost() {
let jsr223PostProcessor = createComponent("JSR223PostProcessor");
this.request.hashTree.push(jsr223PostProcessor);
this.reload();
},
addAssertions() {
let assertions = new Assertions();
this.request.hashTree.push(assertions);
this.reload();
},
addExtract() {
let jsonPostProcessor = new Extract();
this.request.hashTree.push(jsonPostProcessor);
this.reload();
},
remove(row) {
let index = this.request.hashTree.indexOf(row);
this.request.hashTree.splice(index, 1);
this.reload();
},
copyRow(row) {
let obj = JSON.parse(JSON.stringify(row));
obj.id = getUUID();
this.request.hashTree.push(obj);
this.reload();
},
setReportType(param) {
if (param && param !== "") {
this.reportType = param;
}
},
reload() {
this.isReloadData = true
this.$nextTick(() => {
this.isReloadData = false
})
},
validateApi() {
if (this.currentProjectId === null) {
this.$error(this.$t('api_test.select_project'), 2000);
return;
}
this.$refs['basicForm'].validate();
},
saveApi() {
this.basisData.method = this.basisData.protocol;
this.$emit('saveApi', this.basisData);
},
runTest() {
},
validate() {
if (this.currentProjectId === null) {
this.$error(this.$t('api_test.select_project'), 2000);
return;
}
this.$refs['request'].validate((valid) => {
if (valid) {
this.$emit('callback');
}
})
},
getEnvironments() {
if (this.currentProjectId) {
this.environments = [];
this.$get('/api/environment/list/' + this.currentProjectId, response => {
this.environments = response.data;
this.environments.forEach(environment => {
parseEnvironment(environment);
});
this.initDataSource();
});
}
},
openEnvironmentConfig() {
if (!this.currentProjectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(this.currentProjectId);
},
initDataSource() {
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
this.databaseConfigsOptions.push(item);
})
break;
}
}
},
environmentChange(value) {
this.request.dataSource = undefined;
for (let i in this.environments) {
if (this.environments[i].id === value) {
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
this.databaseConfigsOptions.push(item);
})
break;
}
}
},
environmentConfigClose() {
this.getEnvironments();
},
changeReportType() {
},
//xml
updateXmlTableData(dataStruct) {
this.request.xmlDataStruct = dataStruct;
},
saveXmlTableData(dataStruct) {
let valedataResult = this.validateXmlDataStruct(dataStruct);
if (valedataResult) {
this.request.xmlDataStruct = dataStruct;
this.refreshXmlTable();
}
},
validateXmlDataStruct() {
if (this.request.xmlDataStruct) {
this.refreshXmlTableDataStruct(this.request.xmlDataStruct);
let result = this.checkXmlTableDataStructData(this.request.xmlDataStruct);
return result;
}
},
refreshXmlTableDataStruct(dataStruct) {
if (dataStruct && dataStruct.length > 0) {
dataStruct.forEach(row => {
row.status = "";
if (row.children == null || row.children.length === 0) {
row.children = [];
} else if (row.children.length > 0) {
this.refreshXmlTableDataStruct(row.children);
}
});
}
},
checkXmlTableDataStructData(dataStruct) {
let allCheckResult = true;
if (this.$refs.treeTable) {
if (dataStruct && dataStruct.length > 0) {
for (let i = 0; i < dataStruct.length; i++) {
let row = dataStruct[i];
allCheckResult = this.$refs.treeTable.validateRowData(row);
if (allCheckResult) {
if (row.children != null && row.children.length > 0) {
allCheckResult = this.checkXmlTableDataStructData(row.children);
if (!allCheckResult) {
return false;
}
}
} else {
return false;
}
}
}
}
return allCheckResult;
},
initXmlTableData() {
if (this.request) {
this.request.xmlDataStruct = [];
this.refreshXmlTable();
}
},
xmlTableDataPushRow(newRow) {
if (this.request) {
if (!this.request.xmlDataStruct) {
this.request.xmlDataStruct = [];
}
this.request.xmlDataStruct.push(newRow);
this.refreshXmlTable();
}
},
xmlTableDataRemoveRow(row) {
if (this.request) {
if (this.request.xmlDataStruct) {
this.removeFromDataStruct(this.request.xmlDataStruct, row);
this.refreshXmlTable();
}
}
},
removeFromDataStruct(dataStruct, row) {
if (!dataStruct || dataStruct.length === 0) {
return;
}
let rowIndex = dataStruct.indexOf(row);
if (rowIndex >= 0) {
dataStruct.splice(rowIndex, 1);
} else {
dataStruct.forEach(itemData => {
if (!itemData.children && itemData.children.length > 0) {
this.removeFromDataStruct(itemData.children, row);
}
});
}
},
refreshXmlTable() {
this.refreshedXmlTable = true
this.$nextTick(() => {
this.refreshedXmlTable = false
})
},
xmlTablePushRow(row) {
this.request.xmlDataStruct.push(row);
}
}
}
</script>
<style scoped>
.tcp >>> .el-input-number {
width: 100%;
}
.tcp >>> .el-input-number {
width: 100%;
}
.send-request {
padding: 0px 0;
height: 300px;
border: 1px #DCDFE6 solid;
border-radius: 4px;
width: 100%;
}
.send-request {
padding: 0px 0;
height: 300px;
border: 1px #DCDFE6 solid;
border-radius: 4px;
width: 100%;
}
.ms-left-cell {
margin-top: 40px;
}
.ms-left-cell {
margin-top: 40px;
}
.ms-left-buttion {
margin: 6px 0px 8px 30px;
}
.ms-left-buttion {
margin: 6px 0px 8px 30px;
}
/deep/ .el-form-item {
margin-bottom: 15px;
}
/deep/ .el-form-item {
margin-bottom: 15px;
}
.ms-left-cell {
margin-top: 40px;
}
.ms-left-cell {
margin-top: 40px;
}
.ms-left-buttion {
margin: 6px 0px 8px 30px;
}
.ms-left-buttion {
margin: 6px 0px 8px 30px;
}
/deep/ .el-form-item {
margin-bottom: 15px;
}
/deep/ .el-form-item {
margin-bottom: 15px;
}
/deep/ .instructions-icon {
font-size: 14px !important;
}
/deep/ .instructions-icon {
font-size: 14px !important;
}
.request-tabs {
margin: 20px;
min-height: 200px;
}
.request-tabs {
margin: 20px;
min-height: 200px;
}
.other-config {
padding: 15px;
}
.other-config {
padding: 15px;
}
</style>

View File

@ -23,7 +23,8 @@
<!-- 请求地址 -->
<el-form-item prop="path">
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="api.request.path" class="ms-htt-width"
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="api.request.path"
class="ms-htt-width"
size="small" :disabled="false"/>
</el-form-item>
@ -37,7 +38,10 @@
</el-dropdown-item>
<el-dropdown-item command="save_as_case">{{ $t('api_test.definition.request.save_as_case') }}
</el-dropdown-item>
<el-dropdown-item command="update_api">{{ $t('api_test.definition.request.update_api') }}</el-dropdown-item>
<el-dropdown-item command="update_api">{{
$t('api_test.definition.request.update_api')
}}
</el-dropdown-item>
<el-dropdown-item command="save_as_api">{{ $t('api_test.definition.request.save_as') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
@ -51,7 +55,8 @@
<div v-loading="loading">
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<!-- HTTP 请求参数 -->
<ms-api-request-form :isShowEnable="true" :definition-test="true" :headers="api.request.headers" :request="api.request"/>
<ms-api-request-form :isShowEnable="true" :definition-test="true" :headers="api.request.headers"
:request="api.request"/>
<!--返回结果-->
<!-- HTTP 请求返回数据 -->
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
@ -135,6 +140,23 @@ export default {
}
},
methods: {
setRequestParam(param) {
this.init();
if (param) {
if(param.headers){
this.api.request.headers = param.headers;
}
if(param.argument){
this.api.request.argument = param.argument;
}
if(param.body){
this.api.request.body = param.body;
}
if(param.rest){
this.api.request.rest = param.rest;
}
}
},
handleCommand(e) {
switch (e) {
case "load_case":
@ -301,19 +323,21 @@ export default {
this.versionEnable = response.data;
});
}
},
init() {
//
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request;
if (!this.api.environmentId && this.$store.state.useEnvironment) {
this.api.environmentId = this.$store.state.useEnvironment;
}
this.runLoading = false;
this.checkVersionEnable();
}
},
created() {
//
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request;
if (!this.api.environmentId && this.$store.state.useEnvironment) {
this.api.environmentId = this.$store.state.useEnvironment;
}
this.runLoading = false;
//this.getResult();
this.checkVersionEnable();
this.init();
}
}
</script>

View File

@ -11,56 +11,57 @@
<!-- 操作按钮 -->
<el-dropdown split-button type="primary" class="ms-api-buttion" @click="handleCommand('add')"
@command="handleCommand" size="small" style="float: right;margin-right: 20px" v-if="!runLoading">
{{$t('commons.test')}}
{{ $t('commons.test') }}
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="load_case">{{$t('api_test.definition.request.load_case')}}
<el-dropdown-item command="load_case">{{ $t('api_test.definition.request.load_case') }}
</el-dropdown-item>
<el-dropdown-item command="save_as_case">{{$t('api_test.definition.request.save_as_case')}}
<el-dropdown-item command="save_as_case">{{ $t('api_test.definition.request.save_as_case') }}
</el-dropdown-item>
<el-dropdown-item command="update_api">{{$t('api_test.definition.request.update_api')}}</el-dropdown-item>
<el-dropdown-item command="save_as_api">{{$t('api_test.definition.request.save_as')}}</el-dropdown-item>
<el-dropdown-item command="update_api">{{ $t('api_test.definition.request.update_api') }}</el-dropdown-item>
<el-dropdown-item command="save_as_api">{{ $t('api_test.definition.request.save_as') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-button size="small" type="primary" v-else @click.once="stop" style="float: right;margin-right: 20px">{{ $t('report.stop_btn') }}</el-button>
<el-button size="small" type="primary" v-else @click.once="stop" style="float: right;margin-right: 20px">
{{ $t('report.stop_btn') }}
</el-button>
<p class="tip">{{$t('test_track.plan_view.base_info')}} </p>
<p class="tip">{{ $t('test_track.plan_view.base_info') }} </p>
<!-- 执行环境 -->
<el-form-item prop="environmentId">
{{$t('api_test.definition.request.run_env')}}
{{ $t('api_test.definition.request.run_env') }}
<environment-select :type="'TCP'" :current-data="api" :project-id="projectId"/>
</el-form-item>
<!-- TCP 请求参数 -->
<!-- <p class="tip">{{$t('api_test.definition.request.req_param')}} </p>-->
<!-- <ms-basis-parameters :request="api.request" @callback="runTest" ref="requestForm"/>-->
<div v-if="api.method=='TCP'" v-loading="loading">
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<!-- <ms-basis-parameters :request="api.request" @callback="runTest" ref="requestForm"/>-->
<ms-tcp-format-parameters :request="api.request" @callback="runTest" ref="requestForm"/>
<!--返回结果-->
<!-- HTTP 请求返回数据 -->
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
<ms-request-result-tail :response="responseData" ref="runResult"/>
</div>
<div v-else-if="api.method=='ESB'" v-loading="loading">
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<esb-definition v-xpack v-if="showXpackCompnent" :show-script="true" :request="api.request" @callback="runTest" ref="requestForm"/>
<esb-definition v-xpack v-if="showXpackCompnent" :show-script="true" :request="api.request"
@callback="runTest" ref="requestForm"/>
</div>
</el-form>
<ms-jmx-step :request="api.request" :apiId="api.id" :response="responseData"/>
<div v-if="api.method=='ESB'">
<p class="tip">{{$t('api_test.definition.request.res_param')}}</p>
<esb-definition-response v-xpack v-if="showXpackCompnent" :is-api-component="false" :show-options-button="false" :request="api.request" :response-data="responseData" />
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
<esb-definition-response v-xpack v-if="showXpackCompnent" :is-api-component="false" :show-options-button="false"
:request="api.request" :response-data="responseData"/>
</div>
</el-card>
<!-- 加载用例 -->
<ms-api-case-list @apiCaseClose="apiCaseClose" @refresh="refresh" @selectTestCase="selectTestCase" :currentApi="api" :refreshSign="refreshSign"
<ms-api-case-list @apiCaseClose="apiCaseClose" @refresh="refresh" @selectTestCase="selectTestCase" :currentApi="api"
:refreshSign="refreshSign"
:loaded="loaded" :createCase="createCase"
ref="caseList"/>
@ -86,8 +87,8 @@ import MsJmxStep from "../step/JmxStep";
import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const esbDefinition = (requireComponent!=null&&requireComponent.keys().length) > 0 ? requireComponent("./apidefinition/EsbDefinition.vue") : {};
const esbDefinitionResponse = (requireComponent!=null&&requireComponent.keys().length) > 0 ? requireComponent("./apidefinition/EsbDefinitionResponse.vue") : {};
const esbDefinition = (requireComponent != null && requireComponent.keys().length) > 0 ? requireComponent("./apidefinition/EsbDefinition.vue") : {};
const esbDefinitionResponse = (requireComponent != null && requireComponent.keys().length) > 0 ? requireComponent("./apidefinition/EsbDefinitionResponse.vue") : {};
export default {
name: "RunTestTCPPage",
components: {
@ -125,8 +126,29 @@ export default {
versionEnable: false,
}
},
props: {apiData: {}, currentProtocol: String,syncTabs: Array, projectId: String},
props: {apiData: {}, currentProtocol: String, syncTabs: Array, projectId: String},
methods: {
setRequestParam(param) {
this.init();
if (this.api.method === "TCP" && param && this.api.request) {
if (param.reportType) {
this.api.request.reportType = param.reportType;
}
if (param.jsonDataStruct) {
this.api.request.jsonDataStruct = param.jsonDataStruct;
}
if (param.rawDataStruct) {
this.api.request.rawDataStruct = param.rawDataStruct;
}
if (param.xmlDataStruct) {
this.api.request.xmlDataStruct = param.xmlDataStruct;
}
this.$nextTick(() => {
this.$refs.requestForm.reload();
this.$refs.requestForm.setReportType(param.reportType);
});
}
},
handleCommand(e) {
switch (e) {
case "load_case":
@ -141,7 +163,7 @@ export default {
return this.$refs['requestForm'].validate();
}
},
refresh(){
refresh() {
this.$emit('refresh');
},
runTest() {
@ -232,10 +254,10 @@ export default {
if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {
this.api.response = JSON.parse(this.api.response);
}
if (this.api.tags instanceof Array) {
if (this.api.tags instanceof Array) {
this.api.tags = JSON.stringify(this.api.tags);
}
if(this.api.method==='ESB'){
if (this.api.method === 'ESB') {
this.api.esbDataStruct = JSON.stringify(this.api.request.esbDataStruct);
this.api.backEsbDataStruct = JSON.stringify(this.api.request.backEsbDataStruct);
}
@ -285,19 +307,22 @@ export default {
this.versionEnable = response.data;
});
}
},
init() {
//
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request;
this.runLoading = false;
this.getResult();
if (requireComponent != null && JSON.stringify(esbDefinition) !== '{}') {
this.showXpackCompnent = true;
}
this.checkVersionEnable();
}
},
created() {
//
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request;
this.runLoading = false;
this.getResult();
if (requireComponent != null && JSON.stringify(esbDefinition) !== '{}') {
this.showXpackCompnent = true;
}
this.checkVersionEnable();
this.init();
}
}
</script>