Conflicts:
	frontend/src/business/components/api/definition/components/Run.vue
This commit is contained in:
shiziyuan9527 2021-03-01 10:27:46 +08:00
commit b7ddf4194a
6 changed files with 139 additions and 70 deletions

View File

@ -543,8 +543,10 @@ export default {
}
},
showAll() {
if (!this.customizeVisible) {
this.operatingElements = ELEMENTS.get("ALL");
this.selectedTreeNode = undefined;
}
//this.reload();
},
apiListImport() {

View File

@ -124,6 +124,7 @@
},
languageChange(language) {
this.jsr223ProcessorData.scriptLanguage = language;
this.$emit("languageChange");
},
}
}

View File

@ -44,7 +44,7 @@
<el-input size="small" v-model="assertion.desc" :placeholder="$t('api_test.request.assertions.script_name')"
class="quick-script-block"/>
<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">
<ms-dialog-footer
@cancel="close"
@ -145,7 +145,7 @@
}
this.quickScript();
},
quickScript() {
beanShellOrGroovyScript() {
if (this.assertion.variable && this.assertion.operator) {
let variable = this.assertion.variable;
let operator = this.assertion.operator;
@ -184,7 +184,7 @@
script += "result = value != void && value.length() > 0;\n";
break;
}
let msg = "assertion [" + desc + "]: false;"
let msg = (operator != "is empty" && operator != "is not empty") ? "assertion [" + desc + "]: false;" : "value " + operator
script += "if (!result){\n" +
"\tmsg = \"" + 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() {
this.visible = true;
},

View File

@ -132,7 +132,7 @@ export default {
filterNode(value, data) {
if (!value) return true;
if (data.label) {
return data.label.indexOf(value) !== -1;
return data.label.indexOf(value.toLowerCase()) !== -1;
}
return false;
},

View File

@ -319,6 +319,7 @@ export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
}
}
}
export function handleCtrlSEvent(event, func) {
if (event.keyCode === 83 && event.ctrlKey) {
// console.log('拦截到 ctrl + s');//ctrl+s
@ -330,12 +331,15 @@ export function handleCtrlSEvent(event, func) {
}
export function strMapToObj(strMap) {
if (strMap) {
let obj = Object.create(null);
for (let [k, v] of strMap) {
obj[k] = v;
}
return obj;
}
return null;
}
export function objToStrMap(obj) {
let strMap = new Map();