SoapUI 的脚本断言对于 json 响应失败

SoapUI's Script Assertion is failing for the json response

我想检查 occupanysequenceorder 的每个实例是否与为此字段输入的请求相匹配。当我执行 log.error 时,它会输出:

ERROR:[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
ERROR:1

因此,当请求输入 1 时,这意味着列表中的所有实例都需要等于 1,上面就是这样做的。但是,当我执行断言时:

assert roominfo.occupancySequenceOrder.flatten() == occupancysequenceorder_request

它抛出一个错误的断言,我不确定为什么?我怎样才能让脚本断言通过它执行相关检查。我将断言更改为 assert roominfo.occupancySequenceOrder.flatten().contains(occupancysequenceorder_request) 并且它通过了,但我不确定这是否真的进行了正确的检查以确保 occupanysequenceorder 的每个实例都匹配输入的请求。

代码如下:

json.testregions.each { roominfo ->
   log.error roominfo.occupancySequenceOrder.flatten()
   log.error occupancysequenceorder_request
   assert roominfo.occupancySequenceOrder.flatten() == occupancysequenceorder_request
}

宁愿尝试:

roominfo.occupancySequenceOrder.every { it == 1 }

flatten()List.

没有影响

您也可以试试:

roominfo.occupancySequenceOrder.unique() == [1]

如果您想比较列表。

查看 OP 的其他问题及其来自

的数据

您可以尝试以下 Script Assertion :

//Check if the response is not empty
assert context.response, "Response is empty or null"
//Modify the value of the quest or read it thru properties if you want
def requestValue = 1

def json = new groovy.json.JsonSlurper().parseText(context.response)

json.regions.each { region ->
    region.hotels.each { hotel ->
        hotel.roomInformation. each { room ->
            assert room.occupancySequenceOrder == requestValue, "Value did not match for room ${room.hotelRoomId}"
        }
    }
}