Xml 如何从SOPAUI响应中获取特定属性值?
每当我执行测试用例时,我都会得到属性值作为响应Xml 如何从SOPAUI响应中获取特定属性值?,xml,api,groovy,soapui,Xml,Api,Groovy,Soapui,每当我执行测试用例时,我都会得到属性值作为响应myscoreArun/ten2016-12-20 这里的键是myscore,值是Arun/ten2016-12-20。日期将动态更改,因为今天日期将附加文本“Arun/ten” 我尝试添加下面的groovy脚本代码,但它不起作用 today = new Date().format("yyyy-MM-dd") log.info today def s=log.info("Arun/ten" + today); assert messageExch
myscore
Arun/ten2016-12-20
这里的键是myscore
,值是Arun/ten2016-12-20
。日期将动态更改,因为今天日期将附加文本“Arun/ten”
我尝试添加下面的groovy脚本代码,但它不起作用
today = new Date().format("yyyy-MM-dd")
log.info today
def s=log.info("Arun/ten" + today);
assert messageExchange.responseHeaders["my_client_update"] == ["s"]
我希望传递此脚本
与我在脚本断言中传递的相同,如下所示
断言messageExchange.responseHeaders[“我的客户机更新”]==[“s”]
请建议解决方案。您的
脚本断言
几乎接近了,只是有一条语句有一个小问题
下面是您需要的脚本,请注意下面的脚本使用的是简单的日期正则表达式,因为它是动态的。当然,您也可以按照自己方便的方式使用
/**
* Below is the Script Assertion
* Retrieves the specified header and asserts against the expected value
**/
//Change the header key as needed.
def requiredHeaderKey = 'my_client_update'
//Change the expected value for the above Header key
//Note that below one is using the regular expression to accommodate dynamic date in the header value
def expectedRequiredHeaderValue = "Arun/ten\\d{4}-\\d{2}-\\d{2}"
//You may not be required to change beyond this point of the script.
//Check if the response has headers
assert messageExchange.responseHeaders, "There are no headers in the response"
//Get & Check if the response has required Header and its value is not empty
def requiredHeaderValue = messageExchange.responseHeaders[requiredHeaderKey]
assert requiredHeaderValue, "Value of the response header ${requiredHeaderKey} is empty or null"
if (requiredHeaderValue instanceof List) {
log.info "Requested header value is ${requiredHeaderValue[0]}"
assert requiredHeaderValue[0] ==~ expectedRequiredHeaderValue, "Response header value is not matching with the expected value"
}
请编辑问题并添加原始响应。@Rao感谢您的编辑,这里的响应不是问题,重点是通过SOAPUI在响应中获得的属性除非我们知道响应内容及其响应标题,否则很难理解问题本身。屏幕截图在这里也会有帮助。是的,谢谢。我会更新屏幕截图@RaoThank@you进行编辑。那么,现在我们要检查什么?格式为Arun/ten的值是今天的日期还是指定格式的任何日期?谢谢。Ro建议一些好的在线教程或书籍来学习Groovy脚本。如果有用的话,请考虑Apple & Up投票。您应该能够在线查找和学习groovy。问题是要能够在SoapUI中使用它,就要知道API。我觉得这很有帮助。是的,非常感谢你,我会查看视频的,当然@Rao