如何从 SOAPUI 响应中获取特定的 属性 值?

How to get the specific property value from SOPAUI response?

每当我执行测试用例时,我都会得到 属性 作为响应的值 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["my_client_update"] == ["s"]

请提出解决方案。

你的 Script Assertion 几乎接近,除了一个陈述有微不足道的问题。

这是您需要的脚本,请注意下面的脚本对日期使用简单的正则表达式,因为它是动态的。当然,您也可以按照自己方便的方式使用。

/**
* 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"
}