需要在SoapUI中的下一个请求中使用的修剪响应值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了需要在SoapUI中的下一个请求中使用的修剪响应值相关的知识,希望对你有一定的参考价值。

当我发起肥皂请求时,我收到一个带有前缀91的电话号码(例如919876543210)作为回复。

我希望通过传输属性将此数字用作其他请求中的输入值,但不使用前缀91(例如9876543210)。请帮助查找如何执行此操作。

我正在使用免费版SoapUI。

答案

您不必使用Property Transfer步骤。

相反,使用以下代码为第一个请求测试步骤添加Script Assertion,它的作用是:

  • 从响应中提取isdn
  • 修剪不需要的价值
  • 将其设置为测试用例级别
  • 在下一个请求中使用Property Expansion使用上面存储的值
//Check if there is response
assert context.response

//Parse response and extract isdn value
def isdn = new XmlSlurper().parseText(context.response).'**'.find {it.name() == 'MSISDN'}.text()

//Trim first 2 digits and store at test case level
context.testCase.setPropertyValue('MSISDN', isdn.substring(2, isdn.size()))

在发送请求中,需要10位数字,用作<elementname>${#TestCase#MSISDN}</elementname>

发送第二个请求时,将替换实际值。

另一答案
//Check if there is response
//assert context.response

def input = context.expand('$ {MSISDN}')

Response = testRunner.testCase.testSteps [“JDBC请求的副本”] .testRequest.response.contentAsString

//Parse response and extract isdn value

def isdn = new XmlSlurper()。parseText(Response)。'**'。find {it.name()=='MSISDN'}。text()

//Trim first 2 digits and store at test case level

context.setProperty('MSISDN',isdn.substring(2,isdn.size()))

log.info isdn.substring(2,isdn.size())

以上是关于需要在SoapUI中的下一个请求中使用的修剪响应值的主要内容,如果未能解决你的问题,请参考以下文章

soapui测试 - 提取响应值并在平面文本中使用它

利用groovy脚本获取soapui中请求和响应的值

邮递员:如何从 html 响应中提取值并将其传递给邮递员中的下一个请求

利用groovy脚本获取soapui中请求和响应的值

soapui怎么让响应报文换行

如何从 Spring MVC 中的请求参数中修剪空格