fix(接口自动化): 修复脚本断言推荐模版兼容性问题。

This commit is contained in:
fit2-zhao 2021-06-01 11:19:07 +08:00 committed by fit2-zhao
parent a89d22ceeb
commit d1d7cb7c72
1 changed files with 8 additions and 3 deletions

View File

@ -153,6 +153,7 @@
let operator = this.assertion.operator; let operator = this.assertion.operator;
let value = this.assertion.value || ""; let value = this.assertion.value || "";
let desc = "${" + variable + "} " + operator + " '" + value + "'"; let desc = "${" + variable + "} " + operator + " '" + value + "'";
let msgScript = "\" + value + \" " + operator + " '" + value + "'";
let script = "value = vars.get(\"" + variable + "\");\n" let script = "value = vars.get(\"" + variable + "\");\n"
switch (this.assertion.operator) { switch (this.assertion.operator) {
case "==": case "==":
@ -169,24 +170,28 @@
break; break;
case ">": case ">":
desc = "${" + variable + "} " + operator + " " + value; desc = "${" + variable + "} " + operator + " " + value;
msgScript = "\" + value + \" " + operator + " " + value;
script += "number = Integer.parseInt(value);\n" + script += "number = Integer.parseInt(value);\n" +
"result = number > " + value + ";\n"; "result = number > " + value + ";\n";
break; break;
case "<": case "<":
desc = "${" + variable + "} " + operator + " " + value; desc = "${" + variable + "} " + operator + " " + value;
msgScript = "\" + value + \" " + operator + " " + value;
script += "number = Integer.parseInt(value);\n" + script += "number = Integer.parseInt(value);\n" +
"result = number < " + value + ";\n"; "result = number < " + value + ";\n";
break; break;
case "is empty": case "is empty":
desc = "${" + variable + "} " + operator desc = "${" + variable + "} " + operator;
msgScript = "\" + value + \" " + operator;
script += "result = value == void || value.length() == 0;\n"; script += "result = value == void || value.length() == 0;\n";
break; break;
case "is not empty": case "is not empty":
desc = "${" + variable + "} " + operator desc = "${" + variable + "} " + operator;
msgScript = "\" + value + \" " + operator;
script += "result = value != void && value.length() > 0;\n"; script += "result = value != void && value.length() > 0;\n";
break; break;
} }
let msg = (operator != "is empty" && operator != "is not empty") ? "assertion [" + desc + "]: false;" : "value " + operator let msg = (operator !== "is empty" && operator !== "is not empty") ? "assertion [" + msgScript + "]: 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" +