cancel
Showing results for 
Search instead for 
Did you mean: 

Properties in SoapUI - case study

Highlighted
Community Hero

Properties in SoapUI - case study

The possibility to use properties is a very important aspect in SoapUI automation. And although they are widely used they tend to be not very well understood. Indeed the name 'property' seems a little unfit for an element that (by all means) is presented by SmartBear as a variable to hold certain values for later use in the test execution cycle. For instance, one can have a 'sessionId' element to hold the current session string or one can have a 'cookie' element to hold some cookie value and so on.

 

1. Defining properties

 

Properties can be defined at the project level, at the test suite level, at the test case level or in a special properties step. For instance, in order to define or edit a property at the test case level one must click on the desired test case in the left hand navigator and then just select the 'Custom Properties' tab. This is similar for any test suite or project.

 testcase_level_property.png

As said before there is also the possibility to use a special 'properties step'. This step must be created inside a certain test case thus its properties will only be available inside that particular test case.

 

2018-02-21_08h19_53.png

 

2. Reading properties

 

2.1 Referencing in SoapUI steps

 

When wanting to reference a property, attention has to be paid to the level at which it was defined. There are different syntaxes that need to be written depending on it as presented in the table below:

 

Level at which it is defined
Syntax
Example property name
Example request
Project level ${#Project#Property} Port http://myserver:${#Project#Port}
Test suite level ${#TestSuite#Property} Port http://myserver:${#TestSuite#Port}
Test case level ${#TestCase#Property} Port http://myserver:${#TestCase#Port}
Special properties step ${#Property} Port http://myserver:${#Port}

 

Following the above example, if one would have a project level property named Port with the value 8080, then that property could be used anywhere in the project by simply referencing it like ${#Project#Port}. Example:

 

2018-02-21_09h06_43.png

 

When sending the request, the value of the ${#Project#Port} would be replaced by its value (in our example 8080).

 
2.2 Referencing in scripts

 

In order to read a property in a script the following syntax is required:

 

/**
 * Notes:
 *   There are 4 properties defined at 4 levels: project, test suite, test case and special properties step level
 *   The special properties step is simply called 'Properties'
 */
def stepProperty      = testRunner.testCase.getTestStepByName( "Properties" ).getPropertyValue( "myCustomProperty" )
def testCaseProperty  = testRunner.testCase.getPropertyValue( "myCustomProperty" )
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue( "myCustomProperty" )
def projectProperty   = testRunner.testCase.testSuite.project.getPropertyValue( "myCustomProperty" )

 

3. Updating properties

 

Updating tests can be done using a groovy script or a special transfer property step. Both of the methods are simple and straightforward but for the purpuse of this article only a groovy script example will be shown:

/**
 * Notes:
 *   This script changes 4 properties defined at 4 levels: project, test suite, test case and special properties step level
 *   The special properties step is simply called 'Properties'
 */
testRunner.testCase.getTestStepByName( "Properties" ).setPropertyValue( "myCustomProperty", "newSpecialValue" )
testRunner.testCase.setPropertyValue( "myCustomProperty", "newTestCaseValue" )
testRunner.testCase.testSuite.setPropertyValue( "myCustomProperty", "newTestSuiteValue" )
testRunner.testCase.testSuite.project.setPropertyValue( "myCustomProperty", "newProjectValue" )

 



If my answer helped please click on the 'Accept as Solution' button.
Tags (1)
2 REPLIES 2
Highlighted
Community Hero

Re: Properties in SoapUI - case study

@Lucian

 

this really lays out the subject nicely - I've a new starter and this post will really help - so cheers!

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Properties in SoapUI - case study

Robot wink



If my answer helped please click on the 'Accept as Solution' button.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors