如果输出后条件没有显示正确的信息

时间:2017-01-12 11:47:49

标签: groovy

我在groovy中的if条件有点问题。

实际上我想查看我设置的属性值,并确保从JSON传递的响应中的每个实例都包含与属性值相同的值,然后它应该等于匹配。现在,当我记录location_idlocation_id_request时,我得到了预期的值。但是,在我的if语句中,似乎仍然表明位置id不匹配,让我相信我的if条件不正确。我需要将if条件更改为输出正确的消息。

下面是我对下面的日志信息的代码:

import groovy.json.JsonSlurper 

def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)

def location_id = json.reviews.location_id
assert location_id != null
def location_id_request = messageExchange.modelItem.testStep.testCase.getPropertyValue("locationid")
assert location_id.every {it == location_id_request}

log.info location_id_request
log.info location_id

if (location_id == location_id_request)
    log.info "Good News, location match!"
else
    log.info "Test has failed, location do not match!"

按正确顺序记录信息:

location_id_request:INFO:000000
location_id:INFO:[000000, 000000, 000000, 000000, 000000]
if condition output:INFO:Test has failed, location do not match!

1 个答案:

答案 0 :(得分:2)

您将StringNumber?)与List进行比较 - 它不会起作用。相反,请尝试检查location_id location_id_request上是否存在List

if (location_id in location_id_request) { //... }