fix(接口自动化): 检查场景步骤是否都是全路径

This commit is contained in:
fit2-zhao 2021-03-30 19:54:18 +08:00
parent 6313a66662
commit 5d78d51091
3 changed files with 233 additions and 109 deletions

View File

@ -767,7 +767,7 @@
}, },
runDebug() { runDebug() {
/*触发执行操作*/ /*触发执行操作*/
let sign = this.$refs.envPopover.checkEnv(); let sign = this.$refs.envPopover.checkEnv(this.scenarioDefinition);
if (!sign) { if (!sign) {
return; return;
} }

View File

@ -44,8 +44,8 @@ export default {
setProjectEnvMap(map) { setProjectEnvMap(map) {
this.$emit("setProjectEnvMap", map); this.$emit("setProjectEnvMap", map);
}, },
checkEnv() { checkEnv(data) {
return this.$refs.envSelect.checkEnv(); return this.$refs.envSelect.checkEnv(data);
} }
} }

View File

@ -31,6 +31,7 @@
<script> <script>
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel"; import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig";
import {ELEMENTS} from "./Setting";
export default { export default {
name: "EnvironmentSelect", name: "EnvironmentSelect",
@ -46,7 +47,8 @@ export default {
result: {}, result: {},
projects: [], projects: [],
environments: [], environments: [],
dialogVisible: false dialogVisible: false,
isFullUrl: true,
} }
}, },
methods: { methods: {
@ -102,8 +104,125 @@ export default {
this.$emit('setProjectEnvMap', map); this.$emit('setProjectEnvMap', map);
this.$emit('close'); this.$emit('close');
}, },
checkEnv() { getApiInfo(request) {
if (request.id && request.referenced === 'REF') {
let requestResult = request.requestResult;
let url = request.refType && request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
let enable = request.enable;
this.$get(url + request.id, response => {
if (response.data) {
Object.assign(request, JSON.parse(response.data.request));
request.name = response.data.name;
request.enable = enable;
if (response.data.path && response.data.path != null) {
request.path = response.data.path;
request.url = response.data.url;
this.setUrl(request.path);
}
if (response.data.method && response.data.method != null) {
request.method = response.data.method;
}
request.requestResult = requestResult;
request.id = response.data.id;
request.disabled = true;
request.root = true;
if (!request.projectId) {
request.projectId = response.data.projectId;
}
this.reload();
this.sort();
} else {
request.referenced = "Deleted";
}
})
}
},
getScenario(scenario) {
this.result = this.$get("/api/automation/getApiScenario/" + scenario.id, response => {
if (response.data) {
scenario.loaded = true;
let obj = {};
if (response.data.scenarioDefinition) {
obj = JSON.parse(response.data.scenarioDefinition);
scenario.hashTree = obj.hashTree;
}
//scenario.disabled = true;
scenario.name = response.data.name;
if (!scenario.projectId) {
scenario.projectId = response.data.projectId;
}
scenario.headers = obj.headers;
scenario.variables = obj.variables;
scenario.environmentMap = obj.environmentMap;
this.$emit('refReload');
} else {
scenario.referenced = "Deleted";
}
})
},
recursiveSorting(arr) {
for (let i in arr) {
if (arr[i].referenced === 'REF') {
//
if (arr[i].type === "HTTPSamplerProxy") {
//
this.getApiInfo(arr[i]);
//
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (arr[i].type === "scenario") {
this.getScenario(arr[i]);
}
} else {
if (arr[i].type === "HTTPSamplerProxy") {
//
if (arr[i].enable) {
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
}
},
checkFullUrl(scenarioDefinition) {
for (let i in scenarioDefinition) {
// ID
let request = scenarioDefinition[i];
if (request.referenced === 'REF') {
if (request.type === "HTTPSamplerProxy") {
this.getApiInfo(request);
//
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (request.type === "scenario") {
this.getScenario(request);
}
} else {
if (request.type === "HTTPSamplerProxy") {
//
if (request.enable) {
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(scenarioDefinition[i].hashTree);
}
}
},
checkEnv(data) {
let sign = true; let sign = true;
this.isFullUrl = true;
if (this.data.length > 0) { if (this.data.length > 0) {
this.data.forEach(dt => { this.data.forEach(dt => {
if (!dt.selectEnv) { if (!dt.selectEnv) {
@ -121,8 +240,13 @@ export default {
} }
}) })
} else { } else {
// this.checkFullUrl(data);
// sign = this.isFullUrl;
sign = false; sign = false;
} }
//
} }
if (!sign) { if (!sign) {