Knowledge Base Article

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.

 

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.

 

 

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:

 

 

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" )

 

Published 4 years ago
Version 1.0
No CommentsBe the first to comment