fix(接口测试): 修复报告场景步骤调试问题

--bug=1009281 --user=赵勇 [github#8902]接口自动化中部分引用场景会存在执行后无执行记录 https://www.tapd.cn/55049933/s/1090091
This commit is contained in:
fit2-zhao 2022-01-10 17:34:43 +08:00 committed by fit2-zhao
parent f83465d901
commit 0283f7b38d
9 changed files with 57 additions and 18 deletions

View File

@ -154,7 +154,7 @@ public class MsDubboSampler extends MsTestElement {
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
sampler.setProperty("MS-ID", this.getId());
String indexPath = this.getIndex();
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath));
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
ElementUtil.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

@ -200,7 +200,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
sampler.setProperty("MS-ID", this.getId());
String indexPath = this.getIndex();
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath));
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
ElementUtil.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

@ -302,7 +302,7 @@ public class MsJDBCSampler extends MsTestElement {
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
sampler.setProperty("MS-ID", this.getId());
String indexPath = this.getIndex();
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath));
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
ElementUtil.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

@ -244,7 +244,7 @@ public class MsTCPSampler extends MsTestElement {
tcpSampler.setName(this.getName());
tcpSampler.setProperty("MS-ID", this.getId());
String indexPath = this.getIndex();
tcpSampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath));
tcpSampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
ElementUtil.getScenarioSet(this, id_names);
tcpSampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

@ -79,6 +79,7 @@ public class ApiScenarioReportStructureService {
StepTreeDTO dto = null;
if (element != null && element.getBoolean("enable")) {
String referenced = element.getString("referenced");
String type = element.getString("type");
if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) {
if (StringUtils.equals(element.getString("type"), "scenario")) {
ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id"));
@ -87,10 +88,10 @@ public class ApiScenarioReportStructureService {
}
}
}
String resourceId = element.getString("resourceId");
String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id");
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
if (StringUtils.isNotEmpty(resourceId) && StringUtils.isNotEmpty(apiScenario.getId()) && !resourceId.contains(apiScenario.getId())) {
resourceId = apiScenario.getId() + "=" + element.getString("resourceId");
resourceId = apiScenario.getId() + "=" + resourceId;
}
}
dto = new StepTreeDTO(apiScenario.getName(), resourceId, element.getString("type"), 1);
@ -116,10 +117,11 @@ public class ApiScenarioReportStructureService {
}
}
}
String resourceId = element.getString("resourceId");
String type = element.getString("type");
String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id");
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
if (StringUtils.isNotEmpty(resourceId) && StringUtils.isNotEmpty(id) && !resourceId.contains(id)) {
resourceId = id + "=" + element.getString("resourceId");
resourceId = id + "=" + resourceId;
}
}
StepTreeDTO children = new StepTreeDTO(element.getString("name"), resourceId, element.getString("type"), element.getIntValue("index"));

View File

@ -162,7 +162,10 @@ export default {
if (item.enable) {
item.parentIndex = fullPath ? fullPath + "_" + item.index : item.index;
let name = item.name ? item.name : this.getType(item.type);
let obj = {pid: pid, resId: item.resourceId + "_" + item.parentIndex, index: Number(item.index), label: name, value: {name: name, responseResult: {}, unexecute: true, testing: false}, children: [], unsolicited: true};
let obj = {
pid: pid, resId: (item.type === 'JSR223Processor' ? item.resourceId : item.id) + "_" + item.parentIndex, index: Number(item.index), label: name,
value: {name: name, responseResult: {}, unexecute: true, testing: false}, children: [], unsolicited: true
};
tree.children.push(obj);
if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1) {
obj.unsolicited = false;

View File

@ -730,7 +730,7 @@ export default {
},
resultEvaluationChild(arr, resourceId, status) {
arr.forEach(item => {
if (item.data.resourceId + "_" + item.data.parentIndex === resourceId) {
if (item.data.id + "_" + item.data.parentIndex === resourceId) {
item.data.testing = false;
this.evaluationParent(item.parent, status);
}
@ -742,7 +742,7 @@ export default {
resultEvaluation(resourceId, status) {
if (this.$refs.stepTree && this.$refs.stepTree.root) {
this.$refs.stepTree.root.childNodes.forEach(item => {
if (item.data.resourceId + "_" + item.data.parentIndex === resourceId) {
if (item.data.id + "_" + item.data.parentIndex === resourceId) {
item.data.testing = false;
}
if (item.childNodes && item.childNodes.length > 0) {
@ -774,7 +774,7 @@ export default {
let data = JSON.parse(resultData.substring(7));
if (data.method === 'Request' && data.subRequestResults && data.subRequestResults.length > 0) {
data.subRequestResults.forEach(subItem => {
if (item.data && item.data.resourceId + "_" + item.data.parentIndex === subItem.resourceId) {
if (item.data && item.data.id + "_" + item.data.parentIndex === subItem.resourceId) {
subItem.requestResult.console = data.responseResult.console;
item.data.requestResult.push(subItem);
//
@ -783,14 +783,15 @@ export default {
item.data.debug = true;
}
})
} else if (item.data && item.data.resourceId + "_" + 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.requestResult.push(data);
//
this.resultEvaluation(data.resourceId, data.success);
item.data.testing = false;
item.data.debug = true;
}
} else if (item.data && item.data.resourceId + "_" + item.data.parentIndex === resultData) {
} else if (item.data && item.data.id + "_" + item.data.parentIndex === resultData) {
item.data.testing = true;
this.runningEditParent(item.parent);
}
@ -802,13 +803,13 @@ export default {
runningEvaluation(resultData) {
if (this.$refs.stepTree && this.$refs.stepTree.root) {
this.$refs.stepTree.root.childNodes.forEach(item => {
if (item.data && item.data.resourceId + "_" + item.data.parentIndex === resultData) {
if (item.data && item.data.id + "_" + item.data.parentIndex === resultData) {
item.data.testing = true;
} else if (resultData && resultData.startsWith("result_")) {
let data = JSON.parse(resultData.substring(7));
if (data.method === 'Request' && data.subRequestResults && data.subRequestResults.length > 0) {
data.subRequestResults.forEach(subItem => {
if (item.data && item.data.resourceId + "_" + item.data.parentIndex === subItem.resourceId) {
if (item.data && item.data.id + "_" + item.data.parentIndex === subItem.resourceId) {
item.data.requestResult.push(subItem);
//
this.resultEvaluation(subItem.resourceId, subItem.success);
@ -816,7 +817,8 @@ export default {
item.data.debug = true;
}
})
} else if (item.data && item.data.resourceId + "_" + 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.requestResult.push(data);
//
this.resultEvaluation(data.resourceId, data.success);

View File

@ -466,6 +466,7 @@ export default {
this.mergeHashTree(req.hashTree);
}
this.initDataSource();
this.forStatus();
this.sort();
this.reload();
}

View File

@ -71,6 +71,7 @@ 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";
export default {
name: "ApiScenarioComponent",
@ -116,6 +117,9 @@ 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;
@ -124,6 +128,7 @@ 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) {
@ -168,7 +173,8 @@ export default {
loading: false,
isShowInput: false,
isShowNum: false,
isSameSpace: true
isSameSpace: true,
stepFilter: new STEP,
}
},
computed: {
@ -189,6 +195,31 @@ export default {
runScenario.hashTree = [this.scenario];
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');