我的XML响应包含许多信息,其中一个类似于MyURL,并且包含最后应包含的网址myid
。
我怎样才能在Soapui中创建断言,以检查URL是否包含myid
,如果它看起来像这样:
<stream audio="eng"> <myURL>http://xxxxxx.test.com/test26/test32456749&myid=12345678910</myURL>
</stream>
ID仅在刷新后变化,长度应保持不变。
答案 0 :(得分:1)
你走了:
使用脚本断言进行获得响应的相同测试步骤。按照在线评论。
//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