我工作的API,它使乘驾预订和JSON响应列表,我需要检查DestinationEstimatedTravelTime不应该是0或Null
通过脚本断言预期:它应该扫描所有可用的阵列响应,并检查条件的“DestinationETA”应该是大于0。
下面是我的回应的图像
下面是我用我已经使用了循环的代码。
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 ")
}
}
你的错误是因为你在未来把它叫做jsosl
在一个地方,然后jsos1
(最后一个字符是小写L则1)
你可以改变你的代码:
assert json.Results.every { it.DestinationETA }
作为常规,0
或null
是false
我正在就这个问题和我我自己找到了解决办法
//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
}