Search code examples
xmlgroovypropertiessoapuixmlslurper

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


When I initiate a soap request, I receive a phone number with prefix 91 (eg. 919876543210) as a response.

I want to use this number as an input value in other request through transfer property but without the prefix 91 (eg. 9876543210).Please help in finding how to do so.

I am using free version SoapUI.


Solution

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

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

    Response = 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())