fix(接口自动化): 修复IF条件为空时无法保存问题

This commit is contained in:
fit2-zhao 2021-07-19 12:29:45 +08:00 committed by fit2-zhao
parent 3f978b505c
commit fa03fada52
1 changed files with 18 additions and 14 deletions

View File

@ -76,25 +76,29 @@ public class MsIfController extends MsTestElement {
}
public String getContentValue() {
String content = this.variable;
Pattern regex = Pattern.compile("\\$\\{([^}]*)\\}");
Matcher matcher = regex.matcher(content);
StringBuilder stringBuilder = new StringBuilder();
while (matcher.find()) {
stringBuilder.append(matcher.group(1) + ",");
try {
String content = this.variable;
Pattern regex = Pattern.compile("\\$\\{([^}]*)\\}");
Matcher matcher = regex.matcher(content);
StringBuilder stringBuilder = new StringBuilder();
while (matcher.find()) {
stringBuilder.append(matcher.group(1) + ",");
}
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
if (StringUtils.isEmpty(stringBuilder.toString())) {
return this.variable;
}
return stringBuilder.toString();
} catch (Exception e) {
return null;
}
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
if (StringUtils.isEmpty(stringBuilder.toString())) {
return this.variable;
}
return stringBuilder.toString();
}
public String getCondition() {
String key = getContentValue();
String variable = key.equals(this.variable) ? "\"" + this.variable + "\"" : "vars.get('" + key + "')";
String variable = (StringUtils.isEmpty(key) || key.equals(this.variable)) ? "\"" + this.variable + "\"" : "vars.get('" + key + "')";
String operator = this.operator;
String value;
if (StringUtils.equals(operator, "<") || StringUtils.equals(operator, ">")) {