fix (接口自动化): 修复场景步骤引用多个相同场景 执行结果重复问题 #1005615

--bug=1005615 --user=赵勇 【接口自动化】响应内... https://www.tapd.cn/55049933/s/1031900
This commit is contained in:
fit2-zhao 2021-08-03 18:06:26 +08:00 committed by fit2-zhao
parent bc913114e3
commit 4c5a27dece
9 changed files with 36 additions and 20 deletions

View File

@ -308,6 +308,14 @@ public abstract class MsTestElement {
return "";
}
public String getFullIndexPath(MsTestElement element, String path) {
if (element.getParent() == null) {
return path;
}
path = element.getIndex() + "_" + path;
return getFullIndexPath(element.getParent(), path);
}
public boolean isURL(String str) {
try {
if (StringUtils.isEmpty(str)) {

View File

@ -244,7 +244,8 @@ public class MsJDBCPostProcessor extends MsTestElement {
jdbcPostProcessor.setProperty(TestElement.TEST_CLASS, JDBCPostProcessor.class.getName());
jdbcPostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
jdbcPostProcessor.setProperty("MS-ID", this.getId());
jdbcPostProcessor.setProperty("MS-RESOURCE-ID", this.getResourceId()+ "_" + this.getIndex());
String indexPath = this.getIndex();
jdbcPostProcessor.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + this.getFullIndexPath(this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
jdbcPostProcessor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

@ -244,7 +244,8 @@ public class MsJDBCPreProcessor extends MsTestElement {
jdbcPreProcessor.setProperty(TestElement.TEST_CLASS, JDBCPreProcessor.class.getName());
jdbcPreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
jdbcPreProcessor.setProperty("MS-ID", this.getId());
jdbcPreProcessor.setProperty("MS-RESOURCE-ID", this.getResourceId()+ "_" + this.getIndex());
String indexPath = this.getIndex();
jdbcPreProcessor.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + this.getFullIndexPath(this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
jdbcPreProcessor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

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

View File

@ -158,7 +158,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if(StringUtils.isEmpty(this.getEnvironmentId())){
if (StringUtils.isEmpty(this.getEnvironmentId())) {
this.setEnvironmentId(this.useEnvironment);
}
// 非导出操作且不是启用状态则跳过执行
@ -182,7 +182,8 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
sampler.setProperty("MS-ID", this.getId());
sampler.setProperty("MS-RESOURCE-ID", this.getResourceId()+ "_" + this.getIndex());
String indexPath = this.getIndex();
sampler.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + this.getFullIndexPath(this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
@ -253,7 +254,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) {
if(this.getEnvironmentId() == null || el.getEnvironmentId() == null){
if (this.getEnvironmentId() == null || el.getEnvironmentId() == null) {
el.setEnvironmentId(useEnvironment);
}
@ -270,7 +271,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
private HttpConfig getHttpConfig(ParameterConfig config) {
if (config.isEffective(this.getProjectId())) {
String useEvnId = config.getConfig().get(this.getProjectId()).getApiEnvironmentid();
if(StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId,this.getEnvironmentId())){
if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) {
this.setEnvironmentId(useEvnId);
}
return getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig());
@ -585,7 +586,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
private Arguments httpArguments(List<KeyValue> list) {
Arguments arguments = new Arguments();
list.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> {
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue());
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue());
if (keyValue.getValue() == null) {
httpArgument.setValue("");
}

View File

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

View File

@ -204,7 +204,8 @@ public class MsTCPSampler extends MsTestElement {
tcpSampler.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
tcpSampler.setProperty("MS-ID", this.getId());
tcpSampler.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + this.getIndex());
String indexPath = this.getIndex();
tcpSampler.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + this.getFullIndexPath(this.getParent(), indexPath));
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
tcpSampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));

View File

@ -181,12 +181,13 @@ export default {
}
})
},
formatContent(hashTree, tree) {
formatContent(hashTree, tree, fullPath) {
if (hashTree) {
hashTree.forEach(item => {
if (item.enable) {
item.parentIndex = fullPath ? fullPath + "_" + item.index : item.index;
let name = item.name ? item.name : item.type;
let obj = {resId: item.resourceId + "_" + item.index, index: Number(item.index), label: name, value: {name: name, responseResult: {}, unexecute: true, testing: false}, children: [], unsolicited: true};
let obj = {resId: item.resourceId + "_" + item.parentIndex, index: Number(item.index), label: name, value: {name: name, responseResult: {}, unexecute: true, testing: false}, children: [], unsolicited: true};
tree.children.push(obj);
if (ELEMENTS.get("AllSamplerProxy").indexOf(item.type) != -1) {
obj.unsolicited = false;
@ -195,7 +196,7 @@ export default {
this.content.scenarioTotal += 1;
}
if (item.hashTree && item.hashTree.length > 0 && ELEMENTS.get("AllSamplerProxy").indexOf(item.type) === -1) {
this.formatContent(item.hashTree, obj);
this.formatContent(item.hashTree, obj, item.parentIndex);
}
}
})

View File

@ -533,7 +533,7 @@ export default {
},
resultEvaluationChild(arr, resourceId, status) {
arr.forEach(item => {
if (item.data.resourceId + "_" + item.data.index === resourceId) {
if (item.data.resourceId + "_" + item.data.parentIndex === resourceId) {
item.data.testing = false;
this.evaluationParent(item.parent, status);
}
@ -545,7 +545,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.index === resourceId) {
if (item.data.resourceId + "_" + item.data.parentIndex === resourceId) {
item.data.testing = false;
}
if (item.childNodes && item.childNodes.length > 0) {
@ -622,7 +622,7 @@ export default {
},
runningNodeChild(arr, resourceId) {
arr.forEach(item => {
if (item.data && item.data.resourceId + "_" + item.data.index === resourceId) {
if (item.data && item.data.resourceId + "_" + item.data.parentIndex === resourceId) {
item.data.testing = true;
this.runningEditParent(item.parent);
}
@ -634,7 +634,7 @@ export default {
runningEvaluation(resourceId) {
if (this.$refs.stepTree && this.$refs.stepTree.root) {
this.$refs.stepTree.root.childNodes.forEach(item => {
if (item.data && item.data.resourceId + "_" + item.data.index === resourceId) {
if (item.data && item.data.resourceId + "_" + item.data.parentIndex === resourceId) {
item.data.testing = true;
}
if (item.childNodes && item.childNodes.length > 0) {
@ -841,7 +841,7 @@ export default {
this.isBtnHide = true;
this.$refs.scenarioApiRelevance.open();
},
sort(stepArray, scenarioProjectId) {
sort(stepArray, scenarioProjectId,fullPath) {
if (!stepArray) {
stepArray = this.scenarioDefinition;
}
@ -866,7 +866,8 @@ export default {
}
}
// debug
let key = stepArray[i].resourceId + "_" + stepArray[i].index;
stepArray[i].parentIndex = fullPath ? fullPath + "_" + stepArray[i].index : stepArray[i].index;
let key = stepArray[i].resourceId + "_" + stepArray[i].parentIndex;
if (this.debugResult && this.debugResult.get(key)) {
stepArray[i].requestResult = this.debugResult.get(key);
stepArray[i].result = null;
@ -875,7 +876,7 @@ export default {
}
if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) {
this.stepSize += stepArray[i].hashTree.length;
this.sort(stepArray[i].hashTree, stepArray[i].projectId);
this.sort(stepArray[i].hashTree, stepArray[i].projectId,stepArray[i].parentIndex);
}
}
},