fix(接口测试): 修复jsonPath断言结果为空数组时失败的缺陷

--bug=1026795 --user=王孝刚
【接口测试】github#24857,【接口测试】登录接口-后置提取参数,其中age参数是返回值中不存在的字段,断言能成功
https://www.tapd.cn/55049933/s/1385105
This commit is contained in:
wxg0103 2023-06-21 19:23:46 +08:00 committed by fit2-zhao
parent 4fd4152bcf
commit 2c11c028f9
1 changed files with 4 additions and 0 deletions

View File

@ -126,6 +126,7 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
public boolean isUseRegex() { public boolean isUseRegex() {
return getPropertyAsBoolean(ISREGEX, true); return getPropertyAsBoolean(ISREGEX, true);
} }
private static final String KEY_PRE = "[]";
private void doAssert(String jsonString) { private void doAssert(String jsonString) {
Object value = JsonPath.read(jsonString, getJsonPath()); Object value = JsonPath.read(jsonString, getJsonPath());
@ -235,6 +236,9 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
private boolean isEquals(Object subj) { private boolean isEquals(Object subj) {
String str = DocumentUtils.objectToString(subj, decimalFormatter); String str = DocumentUtils.objectToString(subj, decimalFormatter);
if (StringUtils.equals(str,KEY_PRE)) {
return false;
}
if (isUseRegex()) { if (isUseRegex()) {
if (USE_JAVA_REGEX) { if (USE_JAVA_REGEX) {
return JMeterUtils.compilePattern(getExpectedValue()).matcher(str).matches(); return JMeterUtils.compilePattern(getExpectedValue()).matcher(str).matches();