Search code examples
web-servicesgroovysoapui

How to add text with a property transfer in soapUI


I have a test suite in soapUI which has two test cases.

  • First test case has a payment request that has a Account No for example, 2356698.
  • The second request that I have is about creating a Autopay (recurring) Profile for the customer. In the request one of the elements is accountID with letters on it. Like this, 2356698REC.

Is there any way, I can do a property transfer and add those three letters REC after the account no. Considering I have to perform the test multiple times so the accountID will change every time. So I would like take the accountID from first request and transfer it to the second request but also want to add REC to it.

Is that possible through a property transfer or a groovy script?
Any kind of help will be appreciated.


Solution

  • Hope a test case might have been created in the soapui project.

    Add two SOAP request steps, you might have them already. Not required a property transfer or groovy script steps in between the two request steps.

    For the first request, add the Script Assertion with following code:

    //Check if there is response
    assert context.response, 'Response is empty'
    
    //provide the element name which data you need to extract, in this case accountId
    def requiredElement = 'accountId'
    
    def xml = new XmlSlurper().parseText(context.response)
    
    //extract account id value from xml
    def accountIdValue = xml.'**'.find{it.name() == requiredElement}?.text()
    
    //Store at test case level custom property
    context.testCase.setPropertyValue('ACCOUNT_ID', accountIdValue)
    

    In the second request, do the below change : This assumes that element name is AccountId, you can change as needed to suite your need.

    <AccountId>${#TestCase#ACCOUNT_ID}REC</AccountId>
    

    When the request is sent, soapui replaces with first steps extracted value in the second request.

    Even the above can be done with the help of Property transfer. Save the value to test case and use it as mentioned above for the second step with REC and property expansion.