4

I am trying to use SOAPUI to send a request to a REST API. Is there a way to use variables?

E.g if the post request looks like this

{
   "eventType": "check",
   "emailAddress": "email@emailtesting.com",
   "source": "mobile",
   "customerSegment": "gold",
   "custId": "1111111111"
}

Can I use variables instead of let's say the value gold?

5

SoapUI supports something called "properties" which are essentially the variables you asked for. After setting a property, whether manually or by a Groovy script, properties can be included in your individual test steps. SoapUI will expand a properties reference to whatever the property's value is. Property references look like this: ${property_name}.

Property: CustSegment = Gold
{ "eventType": "check", 
"emailAddress": "email@emailtesting.com", 
"source": "mobile", 
"customerSegment": "${CustSegment}", 
"custId": "1111111111" }
2

Got an answer from the SoapUI forum:

depends where "do the variables belong" - you choose a scope eg. custId (i believe it is sth like customerID) in TestCase scope, if you need the custId visible in all teststeps

Lets have the example on TestCase scope - you go to Custom Properties tab in soapui (left bottom corner), create there a property (variable) you need = "custId" with value "1111". Then this variable is accessible in all testSteps:

{
"eventType": "check",
"emailAddress": "email@emailtesting.com",
"source": "mobile",
"customerSegment": "gold",
"custId": "${#TestCase#custId}" [-> will expand to 1111]
}
1

As mentioned above, you can use script properties and a data source.

Data source is my preference as you can build data driven tests, but not in the free version.

You can also create a Groovey step that can either return a const or calculated value and then access that value in your request as described above.

0

Also you can get it from a data source like excel file. For example if you want to get CustId column of your excel you can use following :

{

   "eventType": "check",

   "emailAddress": "email@emailtesting.com",

   "source": "mobile",

   "customerSegment": "gold",

   "custId": $(DataSource#CustId)

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.