布尔值与布尔变量对比报错问题咨询
布尔类型响应字段与变量匹配失败问题
我在尝试把布尔类型的响应字段和布尔变量做对比时遇到了问题,想确认这种基础对比方式是否可行,或者有没有其他布尔值对比方法。
响应示例
{ "data": { "updateNetworkSecurity": { "enabled": true } } }
当前代码与报错
- 变量赋值语句:
* def securityStatusInput = true - 匹配调用语句:
* match $.data.updateNetworkSecurity.enabled == securityStatusInput
执行后报错:
match failed: EACH_EQUALS $ | actual is not an array or list (BOOLEAN:BOOLEAN) true true
排查尝试
尝试数组索引匹配
修改匹配语句为:* match $.data.updateNetworkSecurity[0].enabled == securityStatusInput
报错如下:
match failed: EQUALS $ | actual path does not exist (STRING:BOOLEAN) '#notpresent' true
尝试通配符匹配
修改匹配语句为:* match $.data.updateNetworkSecurity[*].enabled == securityStatusInput
报错如下:
match failed: EQUALS $ | data types don't match (LIST:BOOLEAN) [] true
解决建议
简化匹配语法
框架报错提到EACH_EQUALS,可能是语法解析时误判了匹配类型。试试直接用响应对象字段对比:* match response.data.updateNetworkSecurity.enabled == securityStatusInput或者先直接对比字面量验证字段值:
* match $.data.updateNetworkSecurity.enabled == true确认响应结构稳定性
虽然当前响应里updateNetworkSecurity是单个对象,但报错涉及数组/列表,不排除某些场景下该字段会返回数组。可以先打印字段结构确认:* print response.data.updateNetworkSecurity改用断言脚本
如果match语法存在兼容问题,换用脚本断言的方式:* def isEnabled = response.data.updateNetworkSecurity.enabled * assert isEnabled == securityStatusInput
内容的提问来源于stack exchange,提问作者mike
相关产品推荐
相关产品推荐

