fix(接口测试): 修复循环控制器单独执行收不到结果问题
This commit is contained in:
parent
f808535bbf
commit
c89260ce86
|
@ -14,6 +14,8 @@ public class RunDefinitionRequest {
|
||||||
|
|
||||||
private String reportId;
|
private String reportId;
|
||||||
|
|
||||||
|
private String runMode;
|
||||||
|
|
||||||
private boolean isDebug;
|
private boolean isDebug;
|
||||||
|
|
||||||
private boolean saved;
|
private boolean saved;
|
||||||
|
|
|
@ -374,9 +374,9 @@ public class ApiScenarioExecuteService {
|
||||||
}
|
}
|
||||||
uploadBodyFiles(request.getBodyFileRequestIds(), bodyFiles);
|
uploadBodyFiles(request.getBodyFileRequestIds(), bodyFiles);
|
||||||
FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles);
|
FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles);
|
||||||
|
String runMode = StringUtils.isEmpty(request.getRunMode()) ? ApiRunMode.SCENARIO.name() : request.getRunMode();
|
||||||
// 调用执行方法
|
// 调用执行方法
|
||||||
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(request.getId(), request.getId(), ApiRunMode.SCENARIO.name(), hashTree);
|
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(request.getId(), request.getId(), runMode, hashTree);
|
||||||
runRequest.setDebug(true);
|
runRequest.setDebug(true);
|
||||||
jMeterService.run(runRequest);
|
jMeterService.run(runRequest);
|
||||||
return request.getId();
|
return request.getId();
|
||||||
|
|
|
@ -12,6 +12,7 @@ export default {
|
||||||
components: {},
|
components: {},
|
||||||
props: {
|
props: {
|
||||||
environment: Map,
|
environment: Map,
|
||||||
|
runMode: String,
|
||||||
debug: Boolean,
|
debug: Boolean,
|
||||||
reportId: String,
|
reportId: String,
|
||||||
runData: Object,
|
runData: Object,
|
||||||
|
@ -69,7 +70,7 @@ export default {
|
||||||
testPlan.hashTree.push(threadGroup);
|
testPlan.hashTree.push(threadGroup);
|
||||||
this.sort(testPlan.hashTree);
|
this.sort(testPlan.hashTree);
|
||||||
let reqObj = {
|
let reqObj = {
|
||||||
id: this.reportId, reportId: this.reportId, scenarioName: this.runData.name, saved: this.saved,
|
id: this.reportId, reportId: this.reportId, scenarioName: this.runData.name, saved: this.saved, runMode: this.runMode,
|
||||||
scenarioId: this.runData.id, testElement: testPlan, projectId: getCurrentProjectID(), environmentMap: strMapToObj(map),
|
scenarioId: this.runData.id, testElement: testPlan, projectId: getCurrentProjectID(), environmentMap: strMapToObj(map),
|
||||||
environmentType: this.environmentType, environmentGroupId: this.environmentGroupId, environmentJson: JSON.stringify(strMapToObj(map))
|
environmentType: this.environmentType, environmentGroupId: this.environmentGroupId, environmentJson: JSON.stringify(strMapToObj(map))
|
||||||
};
|
};
|
||||||
|
|
|
@ -89,16 +89,7 @@
|
||||||
<template v-slot:result>
|
<template v-slot:result>
|
||||||
<div v-loading="loading">
|
<div v-loading="loading">
|
||||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
|
<p class="tip">{{ $t('api_test.definition.request.res_param') }} </p>
|
||||||
<div v-if="request.result">
|
<div v-if="showXpackCompnent&&request.backEsbDataStruct != null">
|
||||||
<div v-for="(scenario,h) in request.result.scenarios" :key="h">
|
|
||||||
<el-tabs v-model="request.activeName" closable class="ms-tabs">
|
|
||||||
<el-tab-pane v-for="(item,i) in scenario.requestResults" :label="'循环'+(i+1)" :key="i" style="margin-bottom: 5px">
|
|
||||||
<api-response-component :currentProtocol="request.protocol" :apiActive="true" :result="item"/>
|
|
||||||
</el-tab-pane>
|
|
||||||
</el-tabs>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else-if="showXpackCompnent&&request.backEsbDataStruct != null">
|
|
||||||
<esb-definition-response
|
<esb-definition-response
|
||||||
:currentProtocol="request.protocol"
|
:currentProtocol="request.protocol"
|
||||||
:request="request"
|
:request="request"
|
||||||
|
@ -147,7 +138,6 @@ import ApiBaseComponent from "../common/ApiBaseComponent";
|
||||||
import ApiResponseComponent from "./ApiResponseComponent";
|
import ApiResponseComponent from "./ApiResponseComponent";
|
||||||
import CustomizeReqInfo from "@/business/components/api/automation/scenario/common/CustomizeReqInfo";
|
import CustomizeReqInfo from "@/business/components/api/automation/scenario/common/CustomizeReqInfo";
|
||||||
import TemplateComponent from "@/business/components/track/plan/view/comonents/report/TemplateComponent/TemplateComponent";
|
import TemplateComponent from "@/business/components/track/plan/view/comonents/report/TemplateComponent/TemplateComponent";
|
||||||
import {ENV_TYPE} from "@/common/js/constants";
|
|
||||||
import {getUrl} from "@/business/components/api/automation/scenario/component/urlhelper";
|
import {getUrl} from "@/business/components/api/automation/scenario/component/urlhelper";
|
||||||
|
|
||||||
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
||||||
|
@ -256,6 +246,10 @@ export default {
|
||||||
environmentType(val) {
|
environmentType(val) {
|
||||||
this.envType = val;
|
this.envType = val;
|
||||||
},
|
},
|
||||||
|
'$store.state.currentApiCase.debugLoop'() {
|
||||||
|
this.forStatus();
|
||||||
|
this.reload();
|
||||||
|
},
|
||||||
'$store.state.currentApiCase.resetDataSource'() {
|
'$store.state.currentApiCase.resetDataSource'() {
|
||||||
if (this.request.id && this.request.referenced !== 'REF') {
|
if (this.request.id && this.request.referenced !== 'REF') {
|
||||||
this.initDataSource();
|
this.initDataSource();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<ms-run :debug="true" :environment="envMap" :reportId="reportId" :run-data="debugData" @runRefresh="runRefresh" ref="runTest"/>
|
<ms-run :debug="true" :environment="envMap" :reportId="reportId" :runMode="'DEFINITION'" :run-data="debugData" @runRefresh="runRefresh" ref="runTest"/>
|
||||||
<api-base-component @copy="copyRow" @active="active(controller)" @remove="remove" :data="controller" :draggable="draggable" :is-max="isMax" :show-btn="showBtn" color="#02A7F0" background-color="#F4F4F5" :title="$t('api_test.automation.loop_controller')" v-loading="loading">
|
<api-base-component @copy="copyRow" @active="active(controller)" @remove="remove" :data="controller" :draggable="draggable" :is-max="isMax" :show-btn="showBtn" color="#02A7F0" background-color="#F4F4F5" :title="$t('api_test.automation.loop_controller')" v-loading="loading">
|
||||||
|
|
||||||
<template v-slot:headerLeft>
|
<template v-slot:headerLeft>
|
||||||
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
<template v-slot:message>
|
<template v-slot:message>
|
||||||
<span v-if="requestResult && requestResult.scenarios && requestResult.scenarios.length > 0 " style="color: #8c939d;margin-right: 10px">
|
<span v-if="requestResult && requestResult.scenarios && requestResult.scenarios.length > 0 " style="color: #8c939d;margin-right: 10px">
|
||||||
<!--{{$t('api_test.automation.loop_name')}}{{requestResult.scenarios.length}}次 成功{{success}}次 失败{{error}}次-->
|
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ import ApiBaseComponent from "../common/ApiBaseComponent";
|
||||||
import ApiResponseComponent from "./ApiResponseComponent";
|
import ApiResponseComponent from "./ApiResponseComponent";
|
||||||
import MsRun from "../DebugRun";
|
import MsRun from "../DebugRun";
|
||||||
import {getUUID} from "@/common/js/utils";
|
import {getUUID} from "@/common/js/utils";
|
||||||
import {ELEMENT_TYPE, STEP} from "../Setting";
|
import {STEP} from "../Setting";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsLoopController",
|
name: "MsLoopController",
|
||||||
|
@ -118,8 +117,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
activeName: "first",
|
requestResult: new Map(),
|
||||||
requestResult: {responseResult: {}},
|
|
||||||
success: 0,
|
success: 0,
|
||||||
error: 0,
|
error: 0,
|
||||||
debugData: {},
|
debugData: {},
|
||||||
|
@ -159,6 +157,7 @@ export default {
|
||||||
value: "is not empty",
|
value: "is not empty",
|
||||||
},
|
},
|
||||||
stepFilter: new STEP,
|
stepFilter: new STEP,
|
||||||
|
messageWebSocket: {},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -168,6 +167,35 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
initMessageSocket() {
|
||||||
|
let protocol = "ws://";
|
||||||
|
if (window.location.protocol === 'https:') {
|
||||||
|
protocol = "wss://";
|
||||||
|
}
|
||||||
|
const uri = protocol + window.location.host + "/ws/" + this.reportId;
|
||||||
|
this.requestResult = new Map();
|
||||||
|
this.messageWebSocket = new WebSocket(uri);
|
||||||
|
this.messageWebSocket.onmessage = this.onDebugMessage;
|
||||||
|
},
|
||||||
|
onDebugMessage(e) {
|
||||||
|
if (e.data && e.data.startsWith("result_")) {
|
||||||
|
let data = JSON.parse(e.data.substring(7));
|
||||||
|
let resourceId = data.resourceId.split("_")[0];
|
||||||
|
if (this.requestResult.has(resourceId)) {
|
||||||
|
this.requestResult.get(resourceId).push(data);
|
||||||
|
} else {
|
||||||
|
this.requestResult.set(resourceId, [data]);
|
||||||
|
}
|
||||||
|
} else if (e.data && e.data.indexOf("MS_TEST_END") !== -1) {
|
||||||
|
this.loading = false;
|
||||||
|
this.node.expanded = true;
|
||||||
|
this.messageWebSocket.close();
|
||||||
|
// 把请求结果分给各个请求
|
||||||
|
this.setResult(this.controller.hashTree);
|
||||||
|
this.$store.state.currentApiCase = {debugLoop: getUUID()};
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
getCode() {
|
getCode() {
|
||||||
if (this.node && this.node.data.code && this.node.data.debug) {
|
if (this.node && this.node.data.code && this.node.data.debug) {
|
||||||
if (this.node.data.code && this.node.data.code === 'error') {
|
if (this.node.data.code && this.node.data.code === 'error') {
|
||||||
|
@ -178,25 +206,6 @@ export default {
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
initResult() {
|
|
||||||
if (this.controller) {
|
|
||||||
switch (this.controller.loopType) {
|
|
||||||
case "LOOP_COUNT":
|
|
||||||
this.requestResult = this.controller.countController && this.controller.countController.requestResult ? this.controller.countController.requestResult : {};
|
|
||||||
break;
|
|
||||||
case "FOREACH":
|
|
||||||
this.requestResult = this.controller.forEachController && this.controller.forEachController.requestResult ? this.controller.forEachController.requestResult : {};
|
|
||||||
break;
|
|
||||||
case "WHILE":
|
|
||||||
this.requestResult = this.controller.whileController && this.controller.whileController.requestResult ? this.controller.whileController.requestResult : {};
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.getFails();
|
|
||||||
this.activeName = this.requestResult && this.requestResult.scenarios && this.requestResult.scenarios.length > 0 ? this.requestResult.scenarios[0].name : "";
|
|
||||||
},
|
|
||||||
switchChange() {
|
switchChange() {
|
||||||
if (this.controller.hashTree && this.controller.hashTree.length > 1) {
|
if (this.controller.hashTree && this.controller.hashTree.length > 1) {
|
||||||
this.$warning(this.$t('api_test.automation.loop_message'));
|
this.$warning(this.$t('api_test.automation.loop_message'));
|
||||||
|
@ -214,7 +223,6 @@ export default {
|
||||||
this.recursive(item.hashTree, count);
|
this.recursive(item.hashTree, count);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
this.$warning(this.$t('api_test.automation.loop_message'));
|
this.$warning(this.$t('api_test.automation.loop_message'));
|
||||||
this.controller.countController.proceed = true;
|
this.controller.countController.proceed = true;
|
||||||
|
@ -282,33 +290,15 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
runRefresh() {
|
runRefresh() {
|
||||||
this.getReport();
|
this.initMessageSocket();
|
||||||
},
|
|
||||||
getFails() {
|
|
||||||
this.error = 0;
|
|
||||||
this.success = 0;
|
|
||||||
if (this.requestResult.scenarios && this.requestResult.scenarios !== null) {
|
|
||||||
this.requestResult.scenarios.forEach((scenario) => {
|
|
||||||
if (scenario.requestResults) {
|
|
||||||
scenario.requestResults.forEach((item) => {
|
|
||||||
if (item.error > 0) {
|
|
||||||
this.error++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.success = this.requestResult.scenarios && this.requestResult.scenarios !== null ? this.requestResult.scenarios.length - this.error : 0;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setResult(hashTree) {
|
setResult(hashTree) {
|
||||||
if (hashTree) {
|
if (hashTree) {
|
||||||
hashTree.forEach((item) => {
|
hashTree.forEach((item) => {
|
||||||
if (item.type === "HTTPSamplerProxy" || item.type === "DubboSampler" || item.type === "JDBCSampler" || item.type === "TCPSampler") {
|
if (item.type === "HTTPSamplerProxy" || item.type === "DubboSampler" || item.type === "JDBCSampler" || item.type === "TCPSampler") {
|
||||||
item.result = this.requestResult;
|
item.activeName = "0";
|
||||||
item.activeName = this.activeName;
|
|
||||||
item.active = true;
|
item.active = true;
|
||||||
item.requestResult = [];
|
item.requestResult = this.requestResult.get(item.resourceId);
|
||||||
}
|
}
|
||||||
if (item.hashTree && item.hashTree.length > 0) {
|
if (item.hashTree && item.hashTree.length > 0) {
|
||||||
this.setResult(item.hashTree);
|
this.setResult(item.hashTree);
|
||||||
|
@ -316,61 +306,11 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getReport() {
|
|
||||||
if (this.reportId) {
|
|
||||||
let url = "/api/scenario/report/get/" + this.reportId;
|
|
||||||
this.$get(url, (response) => {
|
|
||||||
this.report = response.data || {};
|
|
||||||
if (response.data) {
|
|
||||||
if (this.isNotRunning) {
|
|
||||||
try {
|
|
||||||
this.requestResult = JSON.parse(this.report.content);
|
|
||||||
if (!this.requestResult) {
|
|
||||||
this.requestResult = {scenarios: []};
|
|
||||||
}
|
|
||||||
this.controller.requestResult = this.requestResult;
|
|
||||||
switch (this.controller.loopType) {
|
|
||||||
case "LOOP_COUNT":
|
|
||||||
this.controller.countController.requestResult = this.requestResult;
|
|
||||||
break;
|
|
||||||
case "FOREACH":
|
|
||||||
this.controller.forEachController.requestResult = this.requestResult;
|
|
||||||
break;
|
|
||||||
case "WHILE":
|
|
||||||
this.controller.whileController.requestResult = this.requestResult;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.getFails();
|
|
||||||
this.activeName = this.requestResult && this.requestResult.scenarios && this.requestResult.scenarios !== null && this.requestResult.scenarios.length > 0 ? this.requestResult.scenarios[0].name : "";
|
|
||||||
// 把请求结果分给各个请求
|
|
||||||
this.setResult(this.controller.hashTree);
|
|
||||||
this.$emit("refReload", this.node);
|
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
this.loading = false;
|
|
||||||
this.node.expanded = true;
|
|
||||||
this.reload();
|
|
||||||
} else {
|
|
||||||
setTimeout(this.getReport, 2000);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.loading = false;
|
|
||||||
this.$error(this.$t("api_report.not_exist"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
hasEmptyOperator() {
|
hasEmptyOperator() {
|
||||||
return !!this.controller.operator && this.controller.operator.indexOf("empty") > 0;
|
return !!this.controller.operator && this.controller.operator.indexOf("empty") > 0;
|
||||||
},
|
},
|
||||||
isNotRunning() {
|
|
||||||
return "Running" !== this.report.status;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue