Trim SoapUI 下一次请求需要使用的响应值

Trim response value which needs to be used in next request in SoapUI

当我发起 soap 请求时,我收到一个前缀为 91 的 phone 号码(例如 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位数字的地方,使用as <elementname>${#TestCase#MSISDN}</elementname>

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

//Check if there is response
//assert context.response

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

响应 = testRunner.testCase.testSteps["Copy of JDBC Request"].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())