对于json响应,SoapUI的Script Assertion失败了

时间:2017-03-06 10:30:19

标签: json rest groovy soapui

我想检查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
}

2 个答案:

答案 0 :(得分:1)

here

查看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}"
        }
    }
}

答案 1 :(得分:0)

而是尝试:

roominfo.occupancySequenceOrder.every { it == 1 }

flatten()对平展List无效。

您也可以尝试:

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

如果您想比较列表。