fix(接口测试): 修复同名场景变量在单接口调试时取值错误问题

--bug=1013027 --user=赵勇 【接口测试】github#13289,新场景的变量跟旧场景是一样,使用的是旧场景的变量 https://www.tapd.cn/55049933/s/1168560
This commit is contained in:
fit2-zhao 2022-05-30 16:18:28 +08:00 committed by f2c-ci-robot[bot]
parent 6f79dad511
commit 426e5208a7
2 changed files with 53 additions and 1 deletions

View File

@ -235,6 +235,7 @@ export default {
environmentMap: this.envMap,
isShowNum: false,
response: {},
currentScenarioData: {},
}
},
created() {
@ -499,6 +500,8 @@ export default {
this.reload();
},
run() {
this.currentScenarioData = undefined;
this.getParentVariables(this.node);
let selectEnvId;
//
if (this.isApiImport || this.request.isRefEnvironment) {
@ -527,17 +530,48 @@ export default {
this.request.environmentId = selectEnvId;
}
this.request.customizeReq = this.isCustomizeReq;
//
let variables = [];
if(this.currentScenario && this.currentScenario.variables) {
JSON.parse(JSON.stringify(this.currentScenario.variables));
}
let debugData = {
id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario",
variables: this.currentScenario.variables, referenced: 'Created', headers: this.currentScenario.headers,
variables: variables, referenced: 'Created', headers: this.currentScenario.headers,
enableCookieShare: this.enableCookieShare, environmentId: selectEnvId, hashTree: [this.request],
};
//
if(this.currentScenarioData && this.currentScenarioData.variableEnable && this.currentScenarioData.variables){
if(!debugData.variables || debugData.variables.length === 0){
debugData.variables = this.currentScenarioData.variables;
}else if(this.currentScenarioData.variables){
//
debugData.variables.forEach(data =>{
this.currentScenarioData.variables.forEach(item =>{
if(data.type === item.type && data.name === item.name){
Object.assign(data,item);
}
})
});
}
}
this.runData.push(debugData);
this.request.requestResult = [];
this.request.result = undefined;
/*触发执行操作*/
this.reportId = getUUID();
},
getParentVariables(node){
if(!this.currentScenarioData) {
if (node && node.data && node.data.type === "scenario") {
this.currentScenarioData = node.data;
} else {
if (node.parent && node.parent.data) {
this.getParentVariables(node.parent);
}
}
}
},
stop() {
let url = "/api/automation/stop/" + this.reportId;
this.$get(url, () => {

View File

@ -148,6 +148,24 @@ export default {
}
this.scenario.run = true;
let runScenario = JSON.parse(JSON.stringify(this.scenario));
let variables = JSON.parse(JSON.stringify(this.currentScenario.variables));
//
if(runScenario && runScenario.variableEnable && runScenario.variables){
if(variables){
//
runScenario.variables.forEach(data =>{
variables.forEach(item =>{
if(data.type === item.type && data.name === item.name){
Object.assign(data,item);
}
})
});
}
}else{
runScenario.variables = variables;
}
runScenario.hashTree = [this.scenario];
runScenario.stepScenario = true;
this.$emit('runScenario', runScenario);