[英]Need to check the Value should not be Null or 0 from whole Array list using Groovy script Assertion
I am working API which give the list of Ride booking and from the Json response i need to check the DestinationEstimatedTravelTime should not be 0 or Null 我正在使用API,该API提供了骑行预订列表,并且从Json响应中我需要检查DestinationEstimatedTravelTime应该不为0还是Null
Expected via script Assertion: it should scan all the available Array Response and check condition that the "DestinationETA" should be greater then 0. 通过脚本声明期望:它应该扫描所有可用的数组响应,并检查条件“ DestinationETA”应大于0。
Below is the image of my Response 以下是我的回应图片
Below is the code that i have used I have used For loop. 以下是我使用过的代码,用于For循环。
import groovy.json.JsonSlurper
//grab response
def response = messageExchange.response.responseContent
def jsosl = new JsonSlurper().parseText(response)
for(int i =0 ; i < jsos1.size(); i++)
{
if(Results[i].DestinationETA == 0 | Results[i].DestinationETA != "Null" )
{
log.info("Values are greater than 0")
}
else
{
log.info("test case Fail ")
}
}
Your error is because you call it jsosl
in one place, then jsos1
in the next 您的错误是因为您在一个地方将其
jsosl
,然后在另一个地方将其jsos1
(last character is a lowercase L then a 1) (最后一个字符是小写字母L,然后是1)
You could change your code to: 您可以将代码更改为:
assert json.Results.every { it.DestinationETA }
As in groovy, 0
or null
is false
与groovy一样,
0
或null
为false
I was working on this and I my self found the solution 我正在为此工作,我自己找到了解决方案
//Import file
import groovy.json.JsonSlurper
import com.eviware.soapui.model.testsuite.TestRunner.*
import com.eviware.soapui.model.testsuite.*
import com.eviware.soapui.model.*
//Grab Response
def response = messageExchange.response.responseContent
def json = new groovy.json.JsonSlurper().parseText(response)
//take count
def count = json.Results.size()
for(int i=0; i<count; i++) //loop to traverse to each object
{
log.info(json.Results[i].DestinationETA) // print result
assert json.Results[i].DestinationETA != null
assert json.Results[i].DestinationETA != 0
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.