if condition not displaying correct message after output

試著忘記壹切 提交于 2020-01-30 11:52:52

问题


I am having a little issue with my if condition in groovy.

Virtually I want to look at a property value I've set and ensure that is every instance on the response delivered from the JSON contains the same value as the property value, then it should equal a match. Now when I log the location_id and location_id_request, I am getting the values expected. However, in my if statement it seems to still state that that the location id does not match, making me believe that my if condition is incorrect. What do I need to change my if condition to, to output the correct message.

Below is the code I have with the log information underneath:

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!"

Log information in correct order:

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:


You compare a String (Number?) with List - it won't work. Instead, try to check if given location_id is present on location_id_request List:

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


来源:https://stackoverflow.com/questions/41612455/if-condition-not-displaying-correct-message-after-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!