Merge branch 'master' of https://github.com/metersphere/metersphere
Conflicts: frontend/src/business/components/api/definition/components/Run.vue
This commit is contained in:
commit
b7ddf4194a
|
@ -543,8 +543,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showAll() {
|
showAll() {
|
||||||
|
if (!this.customizeVisible) {
|
||||||
this.operatingElements = ELEMENTS.get("ALL");
|
this.operatingElements = ELEMENTS.get("ALL");
|
||||||
this.selectedTreeNode = undefined;
|
this.selectedTreeNode = undefined;
|
||||||
|
}
|
||||||
//this.reload();
|
//this.reload();
|
||||||
},
|
},
|
||||||
apiListImport() {
|
apiListImport() {
|
||||||
|
|
|
@ -124,6 +124,7 @@
|
||||||
},
|
},
|
||||||
languageChange(language) {
|
languageChange(language) {
|
||||||
this.jsr223ProcessorData.scriptLanguage = language;
|
this.jsr223ProcessorData.scriptLanguage = language;
|
||||||
|
this.$emit("languageChange");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<el-input size="small" v-model="assertion.desc" :placeholder="$t('api_test.request.assertions.script_name')"
|
<el-input size="small" v-model="assertion.desc" :placeholder="$t('api_test.request.assertions.script_name')"
|
||||||
class="quick-script-block"/>
|
class="quick-script-block"/>
|
||||||
<ms-jsr233-processor ref="jsr233" :is-read-only="isReadOnly" :jsr223-processor="assertion" :templates="templates"
|
<ms-jsr233-processor ref="jsr233" :is-read-only="isReadOnly" :jsr223-processor="assertion" :templates="templates"
|
||||||
:height="300"/>
|
:height="300" @languageChange="quickScript"/>
|
||||||
<template v-slot:footer v-if="!edit">
|
<template v-slot:footer v-if="!edit">
|
||||||
<ms-dialog-footer
|
<ms-dialog-footer
|
||||||
@cancel="close"
|
@cancel="close"
|
||||||
|
@ -145,7 +145,7 @@
|
||||||
}
|
}
|
||||||
this.quickScript();
|
this.quickScript();
|
||||||
},
|
},
|
||||||
quickScript() {
|
beanShellOrGroovyScript() {
|
||||||
if (this.assertion.variable && this.assertion.operator) {
|
if (this.assertion.variable && this.assertion.operator) {
|
||||||
let variable = this.assertion.variable;
|
let variable = this.assertion.variable;
|
||||||
let operator = this.assertion.operator;
|
let operator = this.assertion.operator;
|
||||||
|
@ -184,7 +184,7 @@
|
||||||
script += "result = value != void && value.length() > 0;\n";
|
script += "result = value != void && value.length() > 0;\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let msg = "assertion [" + desc + "]: false;"
|
let msg = (operator != "is empty" && operator != "is not empty") ? "assertion [" + desc + "]: false;" : "value " + operator
|
||||||
script += "if (!result){\n" +
|
script += "if (!result){\n" +
|
||||||
"\tmsg = \"" + msg + "\";\n" +
|
"\tmsg = \"" + msg + "\";\n" +
|
||||||
"\tAssertionResult.setFailureMessage(msg);\n" +
|
"\tAssertionResult.setFailureMessage(msg);\n" +
|
||||||
|
@ -197,6 +197,68 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
pythonScript() {
|
||||||
|
if (this.assertion.variable && this.assertion.operator) {
|
||||||
|
let variable = this.assertion.variable;
|
||||||
|
let operator = this.assertion.operator;
|
||||||
|
let value = this.assertion.value || "";
|
||||||
|
let desc = "${" + variable + "} " + operator + " '" + value + "'";
|
||||||
|
let msg = "";
|
||||||
|
let script = "value = vars.get(\"" + variable + "\");\n"
|
||||||
|
switch (this.assertion.operator) {
|
||||||
|
case "==":
|
||||||
|
script += "if value != \"" + value + "\" :\n";
|
||||||
|
break;
|
||||||
|
case "!=":
|
||||||
|
script += "if value == \"" + value + "\" :\n";
|
||||||
|
break;
|
||||||
|
case "contains":
|
||||||
|
script += "if value.find(\"" + value + "\") != -1:\n";
|
||||||
|
msg = "value " + operator + " " + value + ": false;";
|
||||||
|
break;
|
||||||
|
case "not contains":
|
||||||
|
script += "if value.find(\"" + value + "\") == -1:\n";
|
||||||
|
msg = "value " + operator + " " + ": false;";
|
||||||
|
break;
|
||||||
|
case ">":
|
||||||
|
desc = "${" + variable + "} " + operator + " " + value;
|
||||||
|
script += "if value is None or int(value) < " + value + ":\n";
|
||||||
|
msg = "value " + operator + " " + value + ": false;";
|
||||||
|
break;
|
||||||
|
case "<":
|
||||||
|
desc = "${" + variable + "} " + operator + " " + value;
|
||||||
|
script += "if value is None or int(value) > " + value + ":\n";
|
||||||
|
msg = "value " + operator + " " + value + ": false;";
|
||||||
|
break;
|
||||||
|
case "is empty":
|
||||||
|
desc = "${" + variable + "} " + operator
|
||||||
|
script += "if value is not None:\n";
|
||||||
|
msg = "value " + operator + ": false;";
|
||||||
|
break;
|
||||||
|
case "is not empty":
|
||||||
|
desc = "${" + variable + "} " + operator
|
||||||
|
script += "if value is None:\n";
|
||||||
|
msg = "value " + operator + ": false;";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
script +=
|
||||||
|
"\tmsg = \" " + msg + "\";" +
|
||||||
|
"\tAssertionResult.setFailureMessage(msg);" +
|
||||||
|
"\tAssertionResult.setFailure(true);";
|
||||||
|
|
||||||
|
this.assertion.desc = desc;
|
||||||
|
this.assertion.script = script;
|
||||||
|
this.$refs.jsr233.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
quickScript() {
|
||||||
|
if (this.assertion.scriptLanguage == 'beanshell' || this.assertion.scriptLanguage == 'groovy' || this.assertion.scriptLanguage == 'javascript') {
|
||||||
|
this.beanShellOrGroovyScript();
|
||||||
|
} else {
|
||||||
|
this.pythonScript();
|
||||||
|
}
|
||||||
|
},
|
||||||
detail() {
|
detail() {
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
},
|
},
|
||||||
|
|
|
@ -132,7 +132,7 @@ export default {
|
||||||
filterNode(value, data) {
|
filterNode(value, data) {
|
||||||
if (!value) return true;
|
if (!value) return true;
|
||||||
if (data.label) {
|
if (data.label) {
|
||||||
return data.label.indexOf(value) !== -1;
|
return data.label.indexOf(value.toLowerCase()) !== -1;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
|
@ -319,6 +319,7 @@ export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleCtrlSEvent(event, func) {
|
export function handleCtrlSEvent(event, func) {
|
||||||
if (event.keyCode === 83 && event.ctrlKey) {
|
if (event.keyCode === 83 && event.ctrlKey) {
|
||||||
// console.log('拦截到 ctrl + s');//ctrl+s
|
// console.log('拦截到 ctrl + s');//ctrl+s
|
||||||
|
@ -330,12 +331,15 @@ export function handleCtrlSEvent(event, func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function strMapToObj(strMap) {
|
export function strMapToObj(strMap) {
|
||||||
|
if (strMap) {
|
||||||
let obj = Object.create(null);
|
let obj = Object.create(null);
|
||||||
for (let [k, v] of strMap) {
|
for (let [k, v] of strMap) {
|
||||||
obj[k] = v;
|
obj[k] = v;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function objToStrMap(obj) {
|
export function objToStrMap(obj) {
|
||||||
let strMap = new Map();
|
let strMap = new Map();
|
||||||
|
|
Loading…
Reference in New Issue