XML 响应中 URL 部分的 Soapui 断言
Soapui assertion for part of URL in XML response
我有 XML 响应,其中包含许多信息,其中之一类似于 MyURL 并包含 URL,它应该包含在末尾 myid
。
我如何在 Soapui 中创建断言来检查 URL 是否包含 myid
如果它看起来像这样:
<stream audio="eng"> <myURL>http://xxxxxx.test.com/test26/test32456749&myid=12345678910</myURL>
</stream>
刷新后 ID 正在改变,只有长度应该保持不变。
给你:
在获得该响应的同一测试步骤中使用脚本断言。关注在线评论。
//Check if the response is not empty
assert context.response, 'Response is null or empty'
//Chang the name of the element to find if required
def elementToFind = 'myURL'
def xml = new XmlSlurper().parseText(context.response)
def node = xml.'**'.find{it.name() == elementToFind }
//Check if there is such element
assert elementToFind == node?.name(), "$elementToFind does not exists in the response"
//Get the parameters from the url
def params = node.text().toURL().query?.split('&')
//Convert it map / properties
def props = params.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) }}
log.info props.myid
我有 XML 响应,其中包含许多信息,其中之一类似于 MyURL 并包含 URL,它应该包含在末尾 myid
。
我如何在 Soapui 中创建断言来检查 URL 是否包含 myid
如果它看起来像这样:
<stream audio="eng"> <myURL>http://xxxxxx.test.com/test26/test32456749&myid=12345678910</myURL>
</stream>
刷新后 ID 正在改变,只有长度应该保持不变。
给你:
在获得该响应的同一测试步骤中使用脚本断言。关注在线评论。
//Check if the response is not empty
assert context.response, 'Response is null or empty'
//Chang the name of the element to find if required
def elementToFind = 'myURL'
def xml = new XmlSlurper().parseText(context.response)
def node = xml.'**'.find{it.name() == elementToFind }
//Check if there is such element
assert elementToFind == node?.name(), "$elementToFind does not exists in the response"
//Get the parameters from the url
def params = node.text().toURL().query?.split('&')
//Convert it map / properties
def props = params.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) }}
log.info props.myid