如果在输出后没有显示正确的信息 [英] if condition not displaying correct message after output

查看:105
本文介绍了如果在输出后没有显示正确的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



几乎我想看看我设置的属性值,并确保每个实例对于从JSON传递的响应包含与属性值相同的值,那么它应该等于匹配。现在当我登录 location_id location_id_request 时,我得到了预期的值。但是,在我的if语句中,它似乎仍然声明位置标识不匹配,使我相信我的条件不正确。我需要改变我的if条件,以输出正确的信息。



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

  import groovy.json.JsonSlurper 
$ b def response = messageExchange.response.responseContent
def json = new JsonSlurper( ).parseText(response)
$ b $ 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好消息,位置匹配!
else
log.info测试失败,位置不匹配!

记录信息的顺序正确:

 location_id_request:INFO:000000 
location_id:INFO:[000000,000000,000000,000000,000000]
条件输出:INFO:测试失败,位置不比赛!


解决方案

/ code>( Number ?)与 List - 它不起作用。请尝试检查 location_id 是否存在于 location_id_request List

  if(location_id_request中的location_id){// ...} 


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!

解决方案

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) { //... }

这篇关于如果在输出后没有显示正确的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆