如何在soap UI中使用groovy动态获取数组参数值

时间:2017-03-07 12:42:33

标签: json rest groovy soapui

我有API和很多参数。我正在使用OrderInterface将特定参数的值赋入groovy脚本。

Orderable会为数组参数或基于id的参数返回 null

成功

  • context.title
  • context.name

无法获得价值

  • context.location [],context.location [id]
  • context.department [],context.department [id]

在API中,我传递位置和部门ID以获取数据。

例如:location [id] = 556d6dDRE666deda5c

那么如何使用groovy获取参数值,其中参数是数组或有id。

1 个答案:

答案 0 :(得分:1)

根据提供的数据使用以下Script Assertion

//Check the response is not empty
assert context.response, 'Response is empty or null'

//Define expected values
def expectedLocationId = 'Your value here'
def expectedSkills = ['.NET']

def json = new groovy.json.JsonSlurper().parseText(context.response)

log.info "Skills : ${json.data.skills}"

log.info "Location id : ${json.location.id}"

//Assertions:

assert expectedLocationId == json.location.id, 'Location id not matching'
assert expectedSkills == json.data.skills, 'Skills not matching'
相关问题