fix(接口测试): 修复场景调试结果显示问题 #github8902

This commit is contained in:
fit2-zhao 2022-01-12 19:06:59 +08:00 committed by fit2-zhao
parent 330dfa0f2e
commit 76d4f5dcb3
5 changed files with 42 additions and 31 deletions

View File

@ -220,6 +220,7 @@
@stopScenario="stop" @stopScenario="stop"
@setDomain="setDomain" @setDomain="setDomain"
@openScenario="openScenario" @openScenario="openScenario"
@reloadResult="reloadResult"
@editScenarioAdvance="editScenarioAdvance"/> @editScenarioAdvance="editScenarioAdvance"/>
</span> </span>
</el-tree> </el-tree>
@ -515,6 +516,7 @@ export default {
dialogVisible:false, dialogVisible:false,
newScenarioDefinition:[], newScenarioDefinition:[],
currentItem: {}, currentItem: {},
debugResults: [],
} }
}, },
watch: { watch: {
@ -691,6 +693,7 @@ export default {
this.reqTotalTime = 0; this.reqTotalTime = 0;
this.reqTotal = 0; this.reqTotal = 0;
this.reqSuccess = 0; this.reqSuccess = 0;
this.debugResults = [];
}, },
clearResult(arr) { clearResult(arr) {
if (arr) { if (arr) {
@ -787,7 +790,11 @@ export default {
}) })
} else if ((item.data && item.data.id + "_" + item.data.parentIndex === data.resourceId) } else if ((item.data && item.data.id + "_" + item.data.parentIndex === data.resourceId)
|| (item.data && item.data.resourceId + "_" + item.data.parentIndex === data.resourceId)) { || (item.data && item.data.resourceId + "_" + item.data.parentIndex === data.resourceId)) {
item.data.requestResult.push(data); if (item.data.requestResult) {
item.data.requestResult.push(data);
} else {
item.data.requestResult = [data];
}
// //
this.resultEvaluation(data.resourceId, data.success); this.resultEvaluation(data.resourceId, data.success);
item.data.testing = false; item.data.testing = false;
@ -802,6 +809,23 @@ export default {
} }
}) })
}, },
setParentIndex(stepArray, fullPath) {
for (let i in stepArray) {
// debug
stepArray[i].data.parentIndex = fullPath ? fullPath + "_" + stepArray[i].data.index : stepArray[i].data.index;
if (stepArray[i].childNodes && stepArray[i].childNodes.length > 0) {
this.setParentIndex(stepArray[i].childNodes, stepArray[i].data.parentIndex);
}
}
},
reloadResult() {
if (this.debugResults && this.debugResults.length > 0) {
this.setParentIndex(this.$refs.stepTree.root.childNodes);
this.debugResults.forEach(item => {
this.runningEvaluation(item);
})
}
},
runningEvaluation(resultData) { runningEvaluation(resultData) {
if (this.$refs.stepTree && this.$refs.stepTree.root) { if (this.$refs.stepTree && this.$refs.stepTree.root) {
this.$refs.stepTree.root.childNodes.forEach(item => { this.$refs.stepTree.root.childNodes.forEach(item => {
@ -846,6 +870,9 @@ export default {
} }
} }
this.runningEvaluation(e.data); this.runningEvaluation(e.data);
if (e.data && e.data.startsWith("result_")) {
this.debugResults.push(e.data);
}
this.message = getUUID(); this.message = getUUID();
if (e.data && e.data.indexOf("MS_TEST_END") !== -1) { if (e.data && e.data.indexOf("MS_TEST_END") !== -1) {
this.runScenario = undefined; this.runScenario = undefined;

View File

@ -71,12 +71,14 @@ import MsDubboBasisParameters from "../../../definition/components/request/dubbo
import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm"; import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm";
import ApiBaseComponent from "../common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
import {getCurrentProjectID, getCurrentWorkspaceId, getUUID, strMapToObj} from "@/common/js/utils"; import {getCurrentProjectID, getCurrentWorkspaceId, getUUID, strMapToObj} from "@/common/js/utils";
import {STEP} from "@/business/components/api/automation/scenario/Setting"; import {ELEMENT_TYPE, STEP, TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
import {KeyValue} from "@/business/components/api/definition/model/ApiTestModel";
export default { export default {
name: "ApiScenarioComponent", name: "ApiScenarioComponent",
props: { props: {
scenario: {}, scenario: {},
currentScenario: {},
message: String, message: String,
node: {}, node: {},
isMax: { isMax: {
@ -117,9 +119,6 @@ export default {
this.scenario.projectId = getCurrentProjectID(); this.scenario.projectId = getCurrentProjectID();
} }
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) { if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) {
let scenarios = JSON.parse(JSON.stringify(this.scenario.hashTree));
let map = new Map();
this.formatResult(map, scenarios);
this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => { this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => {
if (response.data) { if (response.data) {
this.scenario.loaded = true; this.scenario.loaded = true;
@ -128,7 +127,6 @@ export default {
obj = JSON.parse(response.data.scenarioDefinition); obj = JSON.parse(response.data.scenarioDefinition);
this.scenario.hashTree = obj.hashTree; this.scenario.hashTree = obj.hashTree;
} }
this.setResult(this.scenario.hashTree, map);
this.scenario.projectId = response.data.projectId; this.scenario.projectId = response.data.projectId;
const pro = this.projectList.find(p => p.id === response.data.projectId); const pro = this.projectList.find(p => p.id === response.data.projectId);
if (!pro) { if (!pro) {
@ -147,6 +145,7 @@ export default {
this.scenario.headers = obj.headers; this.scenario.headers = obj.headers;
this.scenario.variables = obj.variables; this.scenario.variables = obj.variables;
this.scenario.environmentMap = obj.environmentMap; this.scenario.environmentMap = obj.environmentMap;
this.$emit('reloadResult');
this.$emit('refReload'); this.$emit('refReload');
} }
}) })
@ -196,31 +195,6 @@ export default {
runScenario.stepScenario = true; runScenario.stepScenario = true;
this.$emit('runScenario', runScenario); this.$emit('runScenario', runScenario);
}, },
formatResult(map, scenarios) {
scenarios.forEach(item => {
if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1 && item.requestResult) {
let key = (item.id ? item.id : item.resourceId) + "_" + item.index;
if (map.has(key)) {
map.get(key).push(... item.requestResult);
} else {
map.set(key, item.requestResult);
}
}
if (item.hashTree && item.hashTree.length > 0) {
this.formatResult(map, item.hashTree);
}
})
},
setResult(array, scenarios) {
if (array && scenarios) {
array.forEach(item => {
let key = (item.id ? item.id : item.resourceId) + "_" + item.index;
if (scenarios.has(key)) {
item.requestResult = scenarios.get(key);
}
})
}
},
stop() { stop() {
this.scenario.run = false; this.scenario.run = false;
this.$emit('stopScenario'); this.$emit('stopScenario');

View File

@ -39,6 +39,7 @@
@setDomain="setDomain" @setDomain="setDomain"
@savePreParams="savePreParams" @savePreParams="savePreParams"
@editScenarioAdvance="editScenarioAdvance" @editScenarioAdvance="editScenarioAdvance"
@reloadResult="reloadResult"
/> />
</keep-alive> </keep-alive>
</div> </div>
@ -250,6 +251,9 @@ export default {
editScenarioAdvance(data) { editScenarioAdvance(data) {
this.$emit('editScenarioAdvance', data); this.$emit('editScenarioAdvance', data);
}, },
reloadResult() {
this.$emit('reloadResult');
}
} }
} }
</script> </script>

View File

@ -111,6 +111,9 @@
this.reload(); this.reload();
}, },
}, },
created() {
this.$emit('reloadResult');
},
methods: { methods: {
reload() { reload() {
this.loading = true this.loading = true

View File

@ -165,6 +165,9 @@ export default {
}, },
}; };
}, },
created() {
this.$emit('reloadResult');
},
watch: { watch: {
message() { message() {
this.reload(); this.reload();