feat (接口定义): 调试增加停止功能

This commit is contained in:
fit2-zhao 2021-08-23 10:20:48 +08:00 committed by fit2-zhao
parent ee5f101ca3
commit 57333057ea
6 changed files with 629 additions and 580 deletions

View File

@ -1,7 +1,6 @@
package io.metersphere.api.jmeter;
import io.metersphere.commons.utils.LogUtil;
import org.apache.jmeter.engine.JMeterEngine;
import org.apache.jmeter.engine.JMeterEngineException;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jorphan.collections.HashTree;
@ -17,7 +16,7 @@ public class LocalRunner {
}
public void run(String report) {
JMeterEngine engine = new StandardJMeterEngine();
StandardJMeterEngine engine = new StandardJMeterEngine();
engine.configure(jmxTree);
try {
engine.runTest();
@ -29,7 +28,7 @@ public class LocalRunner {
public void stop(String report) {
try {
JMeterEngine engine = MessageCache.runningEngine.get(report);
StandardJMeterEngine engine = MessageCache.runningEngine.get(report);
if (engine != null) {
engine.stopTest();
MessageCache.runningEngine.remove(report);

View File

@ -1,6 +1,6 @@
package io.metersphere.api.jmeter;
import org.apache.jmeter.engine.JMeterEngine;
import org.apache.jmeter.engine.StandardJMeterEngine;
import javax.websocket.Session;
import java.util.HashMap;
@ -12,6 +12,6 @@ public class MessageCache {
public static ConcurrentHashMap<String, Session> reportCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, JMeterEngine> runningEngine = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, StandardJMeterEngine> runningEngine = new ConcurrentHashMap<>();
}

View File

@ -1,10 +1,13 @@
<template>
<div class="card-container" v-loading="loading">
<div class="card-container">
<el-card class="card-content">
<el-button v-if="scenario" style="float: right;margin-right: 20px" size="small" type="primary"
@click="handleCommand"> {{ $t('commons.test') }}
</el-button>
<el-button size="small" type="primary" class="ms-api-buttion" style="float: right;margin-right: 20px" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" style="float: right;margin-right: 20px">
{{ $t('commons.test') }}
@ -12,22 +15,20 @@
<el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<!-- 请求参数 -->
<ms-basis-parameters :request="request" ref="requestForm"/>
<!-- 请求返回数据 -->
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<ms-request-result-tail :response="responseData" :currentProtocol="currentProtocol" ref="debugResult"/>
<div v-loading="loading">
<!-- 请求参数 -->
<ms-basis-parameters :request="request" ref="requestForm"/>
<!-- 请求返回数据 -->
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
<ms-request-result-tail :response="responseData" :currentProtocol="currentProtocol" ref="debugResult"/>
</div>
<ms-jmx-step :request="request" :response="responseData"/>
<!-- 执行组件 -->
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
</el-card>
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{$t('commons.save')}}</el-button>
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{ $t('commons.save') }}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list @refreshModule="refreshModule" :loaded="false" ref="caseList"/>
@ -36,126 +37,136 @@
</template>
<script>
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsBasisParameters from "../request/dubbo/BasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsBasisParameters from "../request/dubbo/BasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {
MsRequestResultTail,
MsResponseResult,
MsRequestMetric,
MsResponseText,
MsRun,
MsBasisParameters,
MsJmxStep,
MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
testCase: {},
},
data() {
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
},
debugForm: {method: REQ_METHOD[0].id},
options: [],
responseData: {type: 'TCP', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
export default {
name: "ApiConfig",
components: {
MsRequestResultTail,
MsResponseResult,
MsRequestMetric,
MsResponseText,
MsRun,
MsBasisParameters,
MsJmxStep,
MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
testCase: {},
},
data() {
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
},
debugForm: {method: REQ_METHOD[0].id},
options: [],
responseData: {type: 'TCP', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
isStop: false
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.request = createComponent("DubboSampler");
}
},
watch: {
debugResultId() {
this.getResult()
}
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
} else {
this.request = createComponent("DubboSampler");
this.runDebug();
}
},
watch: {
debugResultId() {
this.getResult()
}
refreshModule() {
this.$emit('refreshModule');
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
}
else {
this.runDebug();
}
},
refreshModule() {
this.$emit('refreshModule');
},
runDebug() {
this.loading = true;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
stop() {
this.isStop = false;
let url = "/api/automation/stop/" + this.reportId;
this.$get(url, () => {
this.loading = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
},
saveAs() {
let obj = {request: this.request};
obj.request.id = getUUID();
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
this.$success(this.$t('report.test_stop_success'));
});
},
runDebug() {
this.loading = true;
this.isStop = true;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.loading = false;
this.isStop = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
},
saveAs() {
let obj = {request: this.request};
obj.request.id = getUUID();
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
}
}
</script>
<style scoped>

View File

@ -1,9 +1,9 @@
<template>
<div class="card-container" v-loading="loading">
<div class="card-container">
<el-card class="card-content">
<el-form :model="debugForm" :rules="rules" ref="debugForm" :inline="true" label-position="right">
<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 :label="$t('api_report.request')" prop="url">
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="debugForm.url"
@ -15,33 +15,42 @@
</el-form-item>
<el-form-item>
<el-button v-if="scenario" size="small" type="primary" @click="handleCommand"> {{ $t('commons.test') }}
<el-button size="small" type="primary" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" v-if="testCase===undefined && !scenario">
{{$t('commons.test')}}
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="save_as">{{$t('api_test.definition.request.save_as_case')}}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-form-item>
<div v-else>
<el-dropdown split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" v-if="testCase===undefined && !scenario">
{{ $t('commons.test') }}
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<el-button v-if="scenario" size="small" type="primary" @click="handleCommand">
{{ $t('commons.test') }}
</el-button>
</el-form-item>
</el-form>
<div v-loading="loading">
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<!-- HTTP 请求参数 -->
<ms-api-request-form :isShowEnable="true" :headers="request.headers" :request="request" :response="responseData"/>
</el-form>
<!-- HTTP 请求返回数据 -->
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<ms-request-result-tail :response="responseData" ref="debugResult"/>
<ms-jmx-step :request="request" :response="responseData"/>
<!-- HTTP 请求返回数据 -->
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
<ms-request-result-tail :response="responseData" ref="debugResult"/>
<!-- 执行组件 -->
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
<ms-jmx-step :request="request" :response="responseData"/>
<!-- 执行组件 -->
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
</div>
</el-card>
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{$t('commons.save')}}</el-button>
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{ $t('commons.save') }}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list :currentApi="debugForm" @refreshModule="refreshModule" :loaded="false" ref="caseList"/>
@ -49,202 +58,210 @@
</template>
<script>
import MsApiRequestForm from "../request/http/ApiHttpRequestForm";
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getCurrentUser, getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsJmxStep from "../step/JmxStep";
import {KeyValue} from "../../model/ApiTestModel";
import MsApiCaseList from "../case/ApiCaseList";
import MsApiRequestForm from "../request/http/ApiHttpRequestForm";
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getCurrentUser, getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsJmxStep from "../step/JmxStep";
import {KeyValue} from "../../model/ApiTestModel";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {
MsRequestResultTail,
MsResponseResult,
MsApiRequestForm,
MsRequestMetric,
MsResponseText,
MsRun,
MsJmxStep,
MsApiCaseList
},
props: {
currentProtocol: String,
testCase: {},
scenario: Boolean,
},
data() {
let validateURL = (rule, value, callback) => {
try {
new URL(this.debugForm.url);
callback();
} catch (e) {
callback(this.$t('api_test.request.url_invalid'));
}
};
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [
{max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'},
/*
{validator: validateURL, trigger: 'blur'}
*/
],
},
debugForm: {method: REQ_METHOD[0].id, environmentId: ""},
options: [],
responseData: {type: 'HTTP', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
reportId: "",
reqOptions: REQ_METHOD,
createCase: "",
request: {},
export default {
name: "ApiConfig",
components: {
MsRequestResultTail,
MsResponseResult,
MsApiRequestForm,
MsRequestMetric,
MsResponseText,
MsRun,
MsJmxStep,
MsApiCaseList
},
props: {
currentProtocol: String,
testCase: {},
scenario: Boolean,
},
data() {
let validateURL = (rule, value, callback) => {
try {
new URL(this.debugForm.url);
callback();
} catch (e) {
callback(this.$t('api_test.request.url_invalid'));
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.createHttp();
}
},
watch: {
debugResultId() {
this.getResult()
},
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
}
else {
this.runDebug();
}
},
createHttp() {
this.request = createComponent("HTTPSamplerProxy");
},
runDebug() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.loading = true;
this.request.url = this.debugForm.url;
this.request.method = this.debugForm.method;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
}
})
},
refreshModule() {
this.$emit('refreshModule');
},
runRefresh(data) {
this.responseData = data;
this.loading = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.debugForm.id = null;
this.request.id = getUUID();
this.debugForm.request = this.request;
this.debugForm.userId = getCurrentUser().id;
this.debugForm.status = "Underway";
this.debugForm.protocol = this.currentProtocol;
this.$emit('saveAs', this.debugForm);
}
else {
return false;
}
})
},
saveAs() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.request.id = getUUID();
this.request.method = this.debugForm.method;
this.request.path = this.debugForm.path;
this.protocol = this.currentProtocol;
this.debugForm.id = this.request.id;
this.debugForm.request = this.request;
this.debugForm.userId = getCurrentUser().id;
this.debugForm.status = "Underway";
this.debugForm.protocol = this.currentProtocol;
this.debugForm.saved = true;
this.$refs.caseList.saveApiAndCase(this.debugForm);
}
else {
return false;
}
})
},
urlChange() {
if (!this.debugForm.url) return;
let url = this.getURL(this.debugForm.url);
if (url && url.pathname) {
if (this.debugForm.url.indexOf('?') != -1) {
this.debugForm.url = decodeURIComponent(this.debugForm.url.substr(0, this.debugForm.url.indexOf("?")));
}
this.debugForm.path = url.pathname;
} else {
this.debugForm.path = url;
}
},
getURL(urlStr) {
try {
let url = new URL(urlStr);
url.searchParams.forEach((value, key) => {
if (key && value) {
this.request.arguments.splice(0, 0, new KeyValue({name: key, required: false, value: value}));
}
});
return url;
} catch (e) {
return urlStr;
}
};
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [
{max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'},
/*
{validator: validateURL, trigger: 'blur'}
*/
],
},
debugForm: {method: REQ_METHOD[0].id, environmentId: ""},
options: [],
responseData: {type: 'HTTP', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
reportId: "",
reqOptions: REQ_METHOD,
createCase: "",
request: {},
isStop: false,
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.createHttp();
}
},
watch: {
debugResultId() {
this.getResult()
},
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
} else {
this.runDebug();
}
},
stop() {
this.isStop = false;
let url = "/api/automation/stop/" + this.reportId;
this.$get(url, () => {
this.loading = false;
this.$success(this.$t('report.test_stop_success'));
});
},
createHttp() {
this.request = createComponent("HTTPSamplerProxy");
},
runDebug() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.loading = true;
this.isStop = true;
this.request.url = this.debugForm.url;
this.request.method = this.debugForm.method;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
}
})
},
refreshModule() {
this.$emit('refreshModule');
},
runRefresh(data) {
this.responseData = data;
this.loading = false;
this.isStop = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.debugForm.id = null;
this.request.id = getUUID();
this.debugForm.request = this.request;
this.debugForm.userId = getCurrentUser().id;
this.debugForm.status = "Underway";
this.debugForm.protocol = this.currentProtocol;
this.$emit('saveAs', this.debugForm);
} else {
return false;
}
})
},
saveAs() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.request.id = getUUID();
this.request.method = this.debugForm.method;
this.request.path = this.debugForm.path;
this.protocol = this.currentProtocol;
this.debugForm.id = this.request.id;
this.debugForm.request = this.request;
this.debugForm.userId = getCurrentUser().id;
this.debugForm.status = "Underway";
this.debugForm.protocol = this.currentProtocol;
this.debugForm.saved = true;
this.$refs.caseList.saveApiAndCase(this.debugForm);
} else {
return false;
}
})
},
urlChange() {
if (!this.debugForm.url) return;
let url = this.getURL(this.debugForm.url);
if (url && url.pathname) {
if (this.debugForm.url.indexOf('?') != -1) {
this.debugForm.url = decodeURIComponent(this.debugForm.url.substr(0, this.debugForm.url.indexOf("?")));
}
this.debugForm.path = url.pathname;
} else {
this.debugForm.path = url;
}
},
getURL(urlStr) {
try {
let url = new URL(urlStr);
url.searchParams.forEach((value, key) => {
if (key && value) {
this.request.arguments.splice(0, 0, new KeyValue({name: key, required: false, value: value}));
}
});
return url;
} catch (e) {
return urlStr;
}
},
}
}
</script>
<style scoped>
.ms-http-input {
width: 500px;
margin-top: 5px;
}
.ms-http-input {
width: 500px;
margin-top: 5px;
}
</style>

View File

@ -1,11 +1,13 @@
<template>
<div class="card-container" v-loading="loading">
<div class="card-container">
<el-card class="card-content">
<el-button v-if="scenario" style="float: right;margin-right: 20px" size="small" type="primary"
@click="handleCommand"> {{ $t('commons.test') }}
</el-button>
<el-button size="small" type="primary" class="ms-api-buttion" style="float: right;margin-right: 20px" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" style="float: right;margin-right: 20px">
{{ $t('commons.test') }}
@ -13,23 +15,21 @@
<el-dropdown-item command="save_as">{{ $t('api_test.definition.request.save_as_case') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<!-- JDBC 请求参数 -->
<ms-basis-parameters :request="request" @callback="runDebug" ref="requestForm"/>
<!-- JDBC 请求返回数据 -->
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<ms-request-result-tail :response="responseData" :currentProtocol="currentProtocol" ref="debugResult"/>
<div v-loading="loading">
<!-- JDBC 请求参数 -->
<ms-basis-parameters :request="request" @callback="runDebug" ref="requestForm"/>
<!-- JDBC 请求返回数据 -->
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
<ms-request-result-tail :response="responseData" :currentProtocol="currentProtocol" ref="debugResult"/>
</div>
<ms-jmx-step :request="request" :response="responseData"/>
<!-- 执行组件 -->
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
</el-card>
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{$t('commons.save')}}</el-button>
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{ $t('commons.save') }}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list @refreshModule="refreshModule" :loaded="false" ref="caseList"/>
@ -39,126 +39,136 @@
</template>
<script>
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsBasisParameters from "../request/database/BasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsBasisParameters from "../request/database/BasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {
MsRequestResultTail,
MsResponseResult,
MsRequestMetric,
MsResponseText,
MsRun,
MsBasisParameters,
MsJmxStep,
MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
testCase: {},
},
data() {
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
},
debugForm: {method: REQ_METHOD[0].id},
options: [],
responseData: {type: 'JDBC', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
export default {
name: "ApiConfig",
components: {
MsRequestResultTail,
MsResponseResult,
MsRequestMetric,
MsResponseText,
MsRun,
MsBasisParameters,
MsJmxStep,
MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
testCase: {},
},
data() {
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
},
debugForm: {method: REQ_METHOD[0].id},
options: [],
responseData: {type: 'JDBC', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
isStop: false,
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
}
}
} else {
this.request = createComponent("JDBCSampler");
}
},
watch: {
debugResultId() {
this.getResult()
}
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
} else {
this.request = createComponent("JDBCSampler");
this.$refs['requestForm'].validate();
}
},
watch: {
debugResultId() {
this.getResult()
}
refreshModule() {
this.$emit('refreshModule');
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
}
else {
this.$refs['requestForm'].validate();
}
},
refreshModule() {
this.$emit('refreshModule');
},
runDebug() {
this.loading = true;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
stop() {
this.isStop = false;
let url = "/api/automation/stop/" + this.reportId;
this.$get(url, () => {
this.loading = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
},
saveAs() {
let obj = {request: this.request};
obj.request.id = getUUID();
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
this.$success(this.$t('report.test_stop_success'));
});
},
runDebug() {
this.loading = true;
this.isStop = true;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.loading = false;
this.isStop = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
},
saveAs() {
let obj = {request: this.request};
obj.request.id = getUUID();
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
}
}
</script>
<style scoped>

View File

@ -1,9 +1,9 @@
<template>
<div class="card-container" v-loading="loading">
<div class="card-container">
<el-card class="card-content">
<el-form :model="debugForm" :rules="rules" ref="debugForm" :inline="true" label-position="right">
<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 :label="$t('api_test.request.tcp.server')" prop="server">
<el-input v-model="request.server" maxlength="300" show-word-limit size="small"/>
</el-form-item>
@ -13,7 +13,9 @@
<el-form-item>
<el-button v-if="scenario" size="small" type="primary" @click="handleCommand"> {{ $t('commons.test') }}
</el-button>
<el-button size="small" type="primary" @click="stop" v-if="isStop">
{{ $t('report.stop_btn') }}
</el-button>
<el-dropdown v-else split-button type="primary" class="ms-api-buttion" @click="handleCommand"
@command="handleCommand" size="small" style="float: right;margin-right: 20px">
{{ $t('commons.test') }}
@ -24,22 +26,21 @@
</el-dropdown>
</el-form-item>
</el-form>
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<!-- TCP 请求参数 -->
<!-- <tcp-basis-parameters :request="request" @callback="runDebug" ref="requestForm"/>-->
<ms-tcp-format-parameters :request="request" @callback="runDebug" ref="requestForm"/>
<!-- TCP 请求返回数据 -->
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<ms-request-result-tail :response="responseData" :currentProtocol="currentProtocol" ref="debugResult"/>
<div v-loading="loading">
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<!-- TCP 请求参数 -->
<ms-tcp-format-parameters :request="request" @callback="runDebug" ref="requestForm"/>
<!-- TCP 请求返回数据 -->
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
<ms-request-result-tail :response="responseData" :currentProtocol="currentProtocol" ref="debugResult"/>
</div>
<ms-jmx-step :request="request" :response="responseData"/>
<!-- 执行组件 -->
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
</el-card>
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{$t('commons.save')}}</el-button>
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as_api')"> {{ $t('commons.save') }}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list @refreshModule="refreshModule" :loaded="false" ref="caseList"/>
@ -49,123 +50,134 @@
</template>
<script>
import MsApiRequestForm from "../request/http/ApiHttpRequestForm";
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsTcpFormatParameters from "@/business/components/api/definition/components/request/tcp/TcpFormatParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
import MsApiRequestForm from "../request/http/ApiHttpRequestForm";
import MsResponseResult from "../response/ResponseResult";
import MsRequestMetric from "../response/RequestMetric";
import {getUUID} from "@/common/js/utils";
import MsResponseText from "../response/ResponseText";
import MsRun from "../Run";
import {createComponent} from "../jmeter/components";
import {REQ_METHOD} from "../../model/JsonData";
import MsRequestResultTail from "../response/RequestResultTail";
import MsTcpFormatParameters from "@/business/components/api/definition/components/request/tcp/TcpFormatParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {
MsJmxStep,
MsTcpFormatParameters,
MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun, MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
testCase: {},
},
data() {
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
},
debugForm: {method: REQ_METHOD[0].id},
options: [],
responseData: {type: 'TCP', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
});
}
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.debugForm.url = this.request.path;
export default {
name: "ApiConfig",
components: {
MsJmxStep,
MsTcpFormatParameters,
MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun, MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
testCase: {},
},
data() {
return {
rules: {
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
},
debugForm: {method: REQ_METHOD[0].id},
options: [],
responseData: {type: 'TCP', responseResult: {}, subRequestResults: []},
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
isStop: false,
}
},
created() {
if (this.testCase) {
if (this.testCase.id) {
//
let url = "/api/definition/report/getReport/" + this.testCase.id;
this.$get(url, response => {
if (response.data) {
let data = JSON.parse(response.data.content);
this.responseData = data;
}
}
} else {
this.request = createComponent("TCPSampler");
});
}
},
watch: {
debugResultId() {
this.getResult()
}
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
this.request = this.testCase.request;
if (this.request) {
this.debugForm.method = this.request.method;
if (this.request.url) {
this.debugForm.url = this.request.url;
} else {
this.$refs['requestForm'].validate();
this.debugForm.url = this.request.path;
}
},
refreshModule() {
this.$emit('refreshModule');
},
runDebug() {
this.loading = true;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.loading = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
},
saveAs() {
let obj = {request: this.request};
obj.server = this.debugForm.server;
obj.port = this.debugForm.port;
obj.request.id = getUUID();
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
} else {
this.request = createComponent("TCPSampler");
}
},
watch: {
debugResultId() {
this.getResult()
}
},
methods: {
handleCommand(e) {
if (e === "save_as") {
this.saveAs();
} else if (e === 'save_as_api') {
this.saveAsApi();
} else {
this.$refs['requestForm'].validate();
}
},
refreshModule() {
this.$emit('refreshModule');
},
stop() {
this.isStop = false;
let url = "/api/automation/stop/" + this.reportId;
this.$get(url, () => {
this.loading = false;
this.$success(this.$t('report.test_stop_success'));
});
},
runDebug() {
this.loading = true;
this.isStop = true;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.loading = false;
this.isStop = false;
this.$refs.debugResult.reload();
},
saveAsApi() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
},
saveAs() {
let obj = {request: this.request};
obj.server = this.debugForm.server;
obj.port = this.debugForm.port;
obj.request.id = getUUID();
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
}
}
</script>
<style scoped>