Working with SoapUI Properties – SoapUI Tutorial #8

This tutorial is all about SoapUI properties. In last SoapUI tutorial we saw how to add properties in Groovy script.

A property in SoapUI is similar to a variable/ parameter and in this tutorial will talk about how to use one in a service request and assign response value to it through scripting. Later, we will move on to property transfer test step and then importing properties.

This is the 8th tutorial in our SoapUI online training series.

What you will learn from this SoapUI Tutorial?

  • Different Faces of Properties
  • Integrating Properties in Service Request
  • Understanding Property Transfer Teststep
  • Load Properties Externally

working with soapui properties

There are two types of properties in SoapUI:

  1. Default Properties: included in the SoapUI installation. We can edit some of the default properties but not all.
  2. Custom/user-defined properties: These are defined by us at any level needed, such as global, project, test suite, test case or test step.

Most often, properties are used to store and retrieve the data while executing the test cases. Internally property will store the value in key pair format.

For example, in the below statement, “Local_Property_FromCurrency” is a key name and “USD” refers value. To access property value, we need to use property name.

testRunner.testCase.testSteps[“Properties”].setPropertyValue
( “Local_Property_FromCurrency“, ‘USD’)

Various property levels in SoapUI Pro

Let us discuss the various property levels in SoapUI Pro. In SoapUI there three levels of properties available.

Level #1. Project and Custom Properties

In this level, properties are divided into two sections. They are project properties and custom properties. These will appear at the bottom of the navigator panel when we click on the Project name. Project properties section has default properties which are created during the project creation for example, Name, Description, File etc.

In order to create our own properties, we can use custom properties tab. Click on the plus icon to create properties:

WORKING WITH PROPERTIES new 1

There are many other options available such as remove, move up, move down and sorting next to add. Any number of custom properties can be added and used by any sections(test suite, test cases) within the project.

Level #2. Test Suite and Custom Properties

These properties are visible only under the test suite. A test suite can contain any number of properties and they can be accessed from any test steps which belong to the said test suite.
Test suite properties appear when click on the respective test suite name under the project. To add custom properties as needed, click on custom properties tab and click on the ‘+’ sign under it.

Working with Properties(2)

Property #3. Test Case and Custom Properties

Test case properties are accessible within the test case. They are not accessible by other test case steps or even test suite under the project.

More details about properties with examples

Properties can store end points, login details, header information, and domain etc. even though we have discussed about writing and reading data to/from the properties, we are yet to discuss this topic in details with example.

The above discussed levels of properties are used in scripting to read the data.

#1. Reading properties:

We will look at how we can read properties in groovy script. In order to access different level properties, the following is the syntax:

Project: Syntax: ${# Project Name # Value }
Example:

def projectPro = testRunner.testCase.testSuite.project.getPropertyValue
( “Project_Level_Property” )
“Project_Level_Property” )
log.info (projectPro)

Test suite: Syntax: ${# TestSuite # Value }
Example:

def testPro = testRunner.testCase.testSuite.getPropertyValue(‘Testsuite_Property’)
log.info (testPro)

Test case: Syntax: $ {# TestCase # Value }
Example:

def testcasePro = testRunner.testCase.getPropertyValue(‘Testcase_Property’)
log.info (testcasePro)

Refer the screenshot below:

Working with Properties(3)

#2. Writing to properties:

To do this, we have to use setPropertyValue method.

Syntax: setPropertyValue (“property name”,”value”)

If we assign values to unknown properties, then SoapUI will create these properties newly. For existing properties will receive the values during the assignment.

#3. Removing Properties through Script:

This can be done by right-clicking on the property name from the property panel. Then click on the Remove option from the context menu.
To do this using script for removing the custom properties use the following statements for project, test suite or test case levels respectively:

testRunner.testCase.testSuite.project.removeProperty( “Testcase_Property” );
testRunner.testCase.testSuite.removeProperty( “Testcase_Property” );
testRunner.testCase.removeProperty( “Testcase_Property” );

The above scripts are not optimum when we have multiple properties in each level as these steps have to be repeated several times for each property. An alternative is to iterate the properties through the script as below:

testRunner.testCase.properties.each
{
           key,value ->
           testRunner.testCase.removeProperty(key)
}

The above script will iterate till the last property available under the test case. “Key” refers the name of the property where as “value” denotes actual value of the property. We can modify the above script to remove the bulk property list present in various levels.

#4. Add property:

AddProperty method is used for this whose syntax is:

addProperty ( property name );

This can be adapted for each level as below:

testRunner.testCase.testSuite.project.addProperty(‘ProjectProperty1’)
testRunner.testCase.testSuite.addProperty(‘TestsuiteProperty1’)
testRunner.testCase.addProperty(‘TestcaseProperty1’)

After executing the above scripts, click on the project/test suite/test case name. Check the custom properties tab in property panel and the created property appears here. See below for reference:

------------

WORKING WITH PROPERTIES new 2

Using properties in services

In this section, we will learn how we can use the properties in services and we are going to use the above scripts for adding, assigning, retrieving property data with currency converter web service.

Integrating Properties in Service:

Let us start adding test steps as shown in the below screenshot.

Working with Properties(5)

In the above screenshot, AddProperties_Script test step contains the following script which adds two properties such as Property_FromCurrency and Property_ToCurrency.

// Add Properties
testRunner.testCase.addProperty(‘Property_FromCurrency’)
testRunner.testCase.addProperty(‘Property_ToCurrency’)

// Assign values to the Properties
testRunner.testCase.setPropertyValue(‘Property_FromCurrency’,’USD’)
testRunner.testCase.setPropertyValue(‘Property_ToCurrency’,’INR’)

In the ServiceRequest_CurrencyConverter_1 contains the request with input parameters as seen below:

Working with Properties(6)

Assigned values in the properties will be transferred to these parameters during the execution. Following this test step, GetResponseData_Script test step has the script that will get the response value and show the result in the log. Here’s the script.

// Get Response data from the service
def response = context.expand( ‘${ServiceRequest_Currency
Converter_1#Response}’ )
def parsedResponse = new XmlSlurper().parseText(response)
String convertedValue = parsedResponse.Body.ConversionRateResponse.
ConversionRateResult.text()
log.info(convertedValue)

Once all the steps are ready, double click on the test suite name and run the test suite. Then, double click on the ServiceRequest_CurrencyConverter_1 and see the response section.

This is what we would find:

  • Response will be received
  • Open the script log to see the resultant data that is converted based on input parameters

This is how we can pass the parameters to the input request and get the response through the script using properties. Going further we can also pass the response value to another service as input.

Property Transfer

The property transfer test step transfers the property data from one property to another during the execution. Let us see in brief how we can create property transfer test step and how the property value is transferred between two properties.

  • Right click on the test case name under the test suite
  • Click Add Step and then click Properties option from context menu
  • Repeat the above steps to create the second property. See the below screenshot:

Working with Properties(7)

  • Now we have to add property transfer test step.
  • Right click on the test case name and click property transfer option from the context menu
  • Enter your desired property transfer name and then click OK
  • Click Add i.e. plus sign in the property transfer tool bar
  • Specify the transfer name and then click OK button
  • In the right side panel, there are two sections available: Source and Target.

Choose the source as Properties and property as Property_Zipcode. Do the same in the target section. Choose Target_Property from the property drop down. When run icon, the property value will be transferred from Property_Zipcode to Target_Property.

(Click on image for enlarged view)

WORKING WITH PROPERTIES new 3

See the transferred value as shown in the below screenshot.

WORKING WITH PROPERTIES new 4

Note: Source property should contain the default value.

In addition to this, there are many options available in the property transfer screen.

  • Fail Transfer on Error
  • Transfer Text Content
  • Transfer to All
  • Entitize Transferred Value(s)
  • Set Null on Missing Source
  • Ignore Empty/Missing Values
  • Use XQuery
  • Transfer Child Nodes

Load Properties from External Source:

To load properties from an external source, follow these steps.

  • Add Properties test step under the test case
  • Enter the property step name and then click OK
  • In the property panel under the navigation panel, click Custom Properties tab
  • Click Working with Properties icon to load the properties from the external property file

Note: Property file should be saved or present on your computer. To save the properties click  icon.

Then, go to the respective drive and pick the property as shown below:

Working with Properties(9)

On OK, we can see the loaded properties and their values in the Custom Properties tab.

Conclusion

Well, that’s properties for us!

Each level properties have their own characteristics. During your SoapUI practice, try to include properties whenever possible with the groovy script test step for adding, removing, assigning and retrieving property data. This is not only useful when you practice with the services but also critical for real application testing as this technique is very helpful to assert your test cases.

Transferring properties among test steps is easier than writing repeated scripts to create new. SoapUI also gives the wonderful feature to import and export properties. This feature will be useful when we are using common properties such as login details, session details etc., for multiple projects. That way, we don’t have to create the same properties again and again for multiple projects. We can simply change in the property value against the properties based on the projects.

Next tutorial #9: In next SoapUI tutorial we will learn Conditional Statements in Groovy like:

  • Boolean Statements
  • Iteration Statements
  • Arrays in Groovy

That’s it for today. Keep reading and we will see you in the next tutorial. Please share your questions, comments and experiences below.

Recommended reading

12 comments ↓

#1 krishna iva

hi
didnot get notification of 7th tutorial?

#2 Sunil

Hi,

Can you please explain how we can save/populate Soap/Rest Response values in Properties?

#3 Swati Seela

@Sunil: You can save the response values by clicking on the required request and choosing the “Dump file” location in its properties. Thanks!

#4 Mohit

Hi, I am fresher currently working as a QA (software tester) in a small company. I am scared about my career growth . i want to ask what is the career growth as QA. What should i do to enhance my skills and in which city i should move so that i can get a good package. Thanks Please reply ASAP

#5 Gaurav Khurana

whats the difference between context and testrunner ? are they exchangeable ?

i tried to set testcase prooperty and use them inside request like ${from} but this approach was only working for global properties and not for testcase/testsuite properties
by just putting ${property_name} how system will understand which property we are talking about

PathLanguage is also shown in property transfer screen apart from Source/Property ( i am using SOAP NG version), by default the value is ?

Can you elaborate more on the last part,how in a file we can place properties and load them(external source) ?

Also if you can explain the code of getting response in a little detail ‘// Get Response data from the service” ?
what if there are 2 responses from API, as of now we had only 1 amount returned

when we can directly set a property as explained in earlier tutorial, then adding them first ? is there a special need to add them ?

#6 Vertika

Hi,

I have given the location in DUMP FILE option in Request Properties. But my file is not generated at the location i.e. response is not getting saved. Please help!

#7 Fox

I just want to know, I transfer the value to the property, then, how can I access it in another request, not using any code, just want the value.
I try the to set the “Token” value as #{#CaseName#Token}, failed.

As I know in Jmeter, I can set a value to a property, for example, “Token”. After that, anywhere, we can get the value of the “Token” by using “$Token”, but I can’t find this way works in SoapUI, now the problem is that, I can ge the value , and set it to a property, then, I don’t know how to access it.

#8 Ram

Detailed tutorial…

#9 sathya

kindly give the tutorial for soapui open source version not for pro..open source only by most peoples..

i can say u r giving the generic example here but focus on open source.

its my request

thanks
sathya

#10 Rishi

How can we save any data from response XML to property file.

#11 Niveditha

Hi,

I am using Excel DataSink for extracting some properties from SOAP response… it is only saving latest iteration results…Is there any way not to replace the previous run results.

#12 Ruchi

Just to add..while adding property from external file we have to give syntax as below
Property_Zipcode=5020

Leave a Comment