Umair Khan
Umair Khan

Reputation: 5

How to add text with a property transfer in soapUI

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

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.

Upvotes: 0

Views: 1210

Answers (1)

Rao
Rao

Reputation: 21369

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.

Upvotes: 0

Related Questions