fix(接口测试): 修复循环控制器执行结果处理问题

--bug=1016052 --user=赵勇 [接口测试]接口场景中循环控制器使用csv 变量while循环调试除了“不等于”条件,其他都失败 https://www.tapd.cn/55049933/s/1228643
This commit is contained in:
fit2-zhao 2022-08-22 10:36:04 +08:00 committed by f2c-ci-robot[bot]
parent ec4a4c3131
commit e5ffb7e295
4 changed files with 41 additions and 22 deletions

View File

@ -17,7 +17,7 @@
</template> </template>
<template v-slot:button> <template v-slot:button>
<el-button @click="runDebug" :disabled="!controller.enable" :tip="$t('api_test.run')" icon="el-icon-video-play" style="background-color: #409EFF;color: white;padding: 5px" size="mini" circle/> <el-button @click="conn" :disabled="!controller.enable" :tip="$t('api_test.run')" icon="el-icon-video-play" style="background-color: #409EFF;color: white;padding: 5px" size="mini" circle/>
</template> </template>
<div v-if="controller.loopType==='LOOP_COUNT'" draggable v-loading="loading"> <div v-if="controller.loopType==='LOOP_COUNT'" draggable v-loading="loading">
<el-row> <el-row>
@ -90,6 +90,7 @@ 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 {STEP} from "../Setting"; import {STEP} from "../Setting";
import {getReportMessageSocket} from "@/business/components/api/automation/api-automation";
export default { export default {
name: "MsLoopController", name: "MsLoopController",
@ -167,6 +168,7 @@ export default {
}, },
stepFilter: new STEP, stepFilter: new STEP,
messageWebSocket: {}, messageWebSocket: {},
uuid: "",
}; };
}, },
watch: { watch: {
@ -176,16 +178,15 @@ export default {
}, },
methods: { methods: {
initMessageSocket() { initMessageSocket() {
let protocol = "ws://"; this.uuid = getUUID();
if (window.location.protocol === 'https:') { this.messageWebSocket = getReportMessageSocket(this.uuid);
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; this.messageWebSocket.onmessage = this.onDebugMessage;
}, },
onDebugMessage(e) { onDebugMessage(e) {
//
if (e && e.data === "CONN_SUCCEEDED") {
this.runDebug();
}
if (e.data && e.data.startsWith("result_")) { if (e.data && e.data.startsWith("result_")) {
let data = JSON.parse(e.data.substring(7)); let data = JSON.parse(e.data.substring(7));
this.debugCode(data); this.debugCode(data);
@ -199,14 +200,28 @@ export default {
this.loading = false; this.loading = false;
this.node.expanded = true; this.node.expanded = true;
this.messageWebSocket.close(); this.messageWebSocket.close();
// // //
this.setResult(this.controller.hashTree); this.setResult(this.controller.hashTree);
this.$store.state.currentApiCase = {debugLoop: getUUID()}; this.$store.state.currentApiCase = {debugLoop: getUUID()};
this.reload(); this.reload();
} }
}, },
debugCode(data){ clear(hashTree) {
if(data && this.node && this.node.data) { if (hashTree) {
hashTree.forEach((item) => {
if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1) {
item.requestResult = [];
item.result = undefined;
item.code = undefined;
}
if (item.hashTree && item.hashTree.length > 0) {
this.setResult(item.hashTree);
}
});
}
},
debugCode(data) {
if (data && this.node && this.node.data) {
if (data.error > 0) { if (data.error > 0) {
this.node.data.code = "error"; this.node.data.code = "error";
} else { } else {
@ -259,8 +274,7 @@ export default {
} }
} }
}, },
conn() {
runDebug() {
if (!this.controller.hashTree || this.controller.hashTree.length < 1) { if (!this.controller.hashTree || this.controller.hashTree.length < 1) {
this.$warning("当前循环下没有请求,不能执行"); this.$warning("当前循环下没有请求,不能执行");
return; return;
@ -269,11 +283,17 @@ export default {
this.$warning(this.$t('api_test.automation.debug_message')); this.$warning(this.$t('api_test.automation.debug_message'));
return; return;
} }
this.requestResult.clear();
this.clear(this.controller.hashTree);
this.initMessageSocket();
},
runDebug() {
this.loading = true; this.loading = true;
let currentEnvironmentId; let currentEnvironmentId;
let resourceId = this.currentScenario.id + "_" + this.controller.projectId;
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has((this.currentScenario.id + "_" + this.controller.projectId))) { && this.$store.state.scenarioEnvMap.has(resourceId)) {
currentEnvironmentId = this.$store.state.scenarioEnvMap.get((this.currentScenario.id + "_" + this.controller.projectId)); currentEnvironmentId = this.$store.state.scenarioEnvMap.get(resourceId);
} }
this.debugData = { this.debugData = {
id: this.currentScenario.id, id: this.currentScenario.id,
@ -289,8 +309,8 @@ export default {
if (this.node && this.node.data) { if (this.node && this.node.data) {
this.node.data.debug = true; this.node.data.debug = true;
} }
this.reportId = getUUID().substring(0, 8); this.reportId = this.uuid;
this.node.data.code=""; this.node.data.code = "";
this.node.data.testing = false; this.node.data.testing = false;
this.node.data.debug = true; this.node.data.debug = true;
}, },
@ -324,7 +344,6 @@ export default {
}); });
}, },
runRefresh() { runRefresh() {
this.initMessageSocket();
}, },
errorRefresh() { errorRefresh() {
this.loading = false; this.loading = false;
@ -332,7 +351,7 @@ export default {
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 (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1 && this.requestResult.has(item.id)) {
item.activeName = "0"; item.activeName = "0";
item.active = true; item.active = true;
item.requestResult = this.requestResult.get(item.id); item.requestResult = this.requestResult.get(item.id);

View File

@ -961,7 +961,7 @@ export default {
test_execute_again: 'Test Execute Again', test_execute_again: 'Test Execute Again',
export: 'Export', export: 'Export',
export_to_ms_format: 'Export to MeterSphere format', export_to_ms_format: 'Export to MeterSphere format',
export_jmeter_format: 'Export to Jmeter format', export_jmeter_format: 'Export to JMeter format',
export_to_swagger3_format: 'Export to Swagger3.0 format', export_to_swagger3_format: 'Export to Swagger3.0 format',
compare: 'Compare', compare: 'Compare',
generation_error: 'Report generation error, unable to view, please check log details!', generation_error: 'Report generation error, unable to view, please check log details!',

View File

@ -965,7 +965,7 @@ export default {
downloadZipFile: '下载执行文件', downloadZipFile: '下载执行文件',
export: '导出', export: '导出',
export_to_ms_format: '导出 MeterSphere 格式', export_to_ms_format: '导出 MeterSphere 格式',
export_jmeter_format: '导出 Jmeter 格式', export_jmeter_format: '导出 JMeter 格式',
export_to_swagger3_format: '导出 Swagger3.0 格式', export_to_swagger3_format: '导出 Swagger3.0 格式',
compare: '报告对比', compare: '报告对比',
generation_error: '报告生成错误, 无法查看, 请检查日志详情!', generation_error: '报告生成错误, 无法查看, 请检查日志详情!',

View File

@ -965,7 +965,7 @@ export default {
downloadZipFile: '下載執行文件', downloadZipFile: '下載執行文件',
export: '導出', export: '導出',
export_to_ms_format: '導出 MeterSphere 格式', export_to_ms_format: '導出 MeterSphere 格式',
export_jmeter_format: '導出 Jmeter 格式', export_jmeter_format: '導出 JMeter 格式',
export_to_swagger3_format: '導出 Swagger3.0 格式', export_to_swagger3_format: '導出 Swagger3.0 格式',
compare: '報告對比', compare: '報告對比',
generation_error: '報告生成錯誤, 無法查看, 請檢查日誌詳情!', generation_error: '報告生成錯誤, 無法查看, 請檢查日誌詳情!',