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"
@setDomain="setDomain"
@openScenario="openScenario"
@reloadResult="reloadResult"
@editScenarioAdvance="editScenarioAdvance"/>
</span>
</el-tree>
@ -515,6 +516,7 @@ export default {
dialogVisible:false,
newScenarioDefinition:[],
currentItem: {},
debugResults: [],
}
},
watch: {
@ -691,6 +693,7 @@ export default {
this.reqTotalTime = 0;
this.reqTotal = 0;
this.reqSuccess = 0;
this.debugResults = [];
},
clearResult(arr) {
if (arr) {
@ -787,7 +790,11 @@ export default {
})
} else if ((item.data && item.data.id + "_" + 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);
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) {
if (this.$refs.stepTree && this.$refs.stepTree.root) {
this.$refs.stepTree.root.childNodes.forEach(item => {
@ -846,6 +870,9 @@ export default {
}
}
this.runningEvaluation(e.data);
if (e.data && e.data.startsWith("result_")) {
this.debugResults.push(e.data);
}
this.message = getUUID();
if (e.data && e.data.indexOf("MS_TEST_END") !== -1) {
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 ApiBaseComponent from "../common/ApiBaseComponent";
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 {
name: "ApiScenarioComponent",
props: {
scenario: {},
currentScenario: {},
message: String,
node: {},
isMax: {
@ -117,9 +119,6 @@ export default {
this.scenario.projectId = getCurrentProjectID();
}
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 => {
if (response.data) {
this.scenario.loaded = true;
@ -128,7 +127,6 @@ export default {
obj = JSON.parse(response.data.scenarioDefinition);
this.scenario.hashTree = obj.hashTree;
}
this.setResult(this.scenario.hashTree, map);
this.scenario.projectId = response.data.projectId;
const pro = this.projectList.find(p => p.id === response.data.projectId);
if (!pro) {
@ -147,6 +145,7 @@ export default {
this.scenario.headers = obj.headers;
this.scenario.variables = obj.variables;
this.scenario.environmentMap = obj.environmentMap;
this.$emit('reloadResult');
this.$emit('refReload');
}
})
@ -196,31 +195,6 @@ export default {
runScenario.stepScenario = true;
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() {
this.scenario.run = false;
this.$emit('stopScenario');

View File

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

View File

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

View File

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