soapUI: Properties

I wanted to jump into a survey of the various test steps in this post, but quickly realized that an explanation of properties was necessary first.  Properties are a key concept in soapUI that can make test suites more flexible and modular.  You can define and reference your own custom properties (which you can think of as being akin to variables in soapUI) or use "built-in" properties to reference bits of information between test steps and test cases-- for example, referencing part of one request test step's response XML to use as an input parameter in another request test step.

Properties are available at multiple levels in soapUI, including the environment, system, global, project, test suite, test case, and test step levels.  System properties are visible in the Help - System Properties window.  Global properties can be viewed or set in the File - Preferences window.  Properties for other levels are visible in the Navigator panel when you click on the relevant node.


Project properties panel

In some cases, properties can also be loaded from or saved to external files (see the screenshot below of a test suite Custom Properties tab; the two rightmost icons at the top of the dialog are for loading and saving from external files).  Properties are saved in the file in propertyname=propertyvalue pairs; e.g.:

ElName=Mercury
ExpectedVal=80

Properties can be referenced (soapUI documentation calls this property expansion) from almost anywhere in soapUI-- in Contains assertions as the string to match, within a request, etc.  To reference a property, the general syntax is "${[#PropertyScope#]PropertyName[#XPathExpression]}".  PropertyScope can be "Env", "System", "Global", "Project", "TestSuite", and "TestCase" (in the screenshot above, the Hermes Config property references the user.home System property).  To reference properties from a preceding test step, the syntax is "${TestStepName#PropertyName[#XPathExpression]}-- note that the leading hash mark (#) before the scope is omitted when referencing a test step.  The test step where you're putting your reference and the test step being referenced must be within the same test case.  XPath expressions are optional and only valid where the property being referenced is valid XML (for test requests, the request and response are both made available as properties).

Let's go back to the test suite created in the last post for our Periodic Table web service.  Note that three of the four operations provided by the web service take an element name as their input parameter: GetAtomicNumber, GetAtomicWeight, GetElementSymbol.  Suppose we wanted to use the same element to test all three.  Instead of hard-coding an element into our requests, we can define a test suite level property and then use that property in all three of our test requests.

Let's try that now.  In the Navigator panel, click on the test suite node.  In the Properties panel (click the Properties button at the bottom of the Navigator panel if you don't see it), click on the "Custom Properties" tab, and add a new property called ElNameProp (via the left-most button at the top), giving it "Silver" as its value.


ElNameProp created at the test suite level

Now go into the GetAtomicNumber, GetAtomicWeight, and GetElementSymbol test requests and modify each to use our test suite's ElNameProp where an element name is required. Our reference expression is "${#TestSuite#ElNameProp}". Here's the reference in the GetAtomicNumber test request:


ElNameProp used in the GetAtomicNumber test request

Now try running each of the modified test requests-- the value "Silver" is plugged into each of the requests where we reference our ElNameProp property (you can see some of the appropriate response data for the GetAtomicNumber request in the screenshot above).

5 comments:

  1. Hi there. Thanks for the informative tutorial! I spotted a small typo up above. When you explain how to create a property you call the property "ElPropName", but then when you're referencing it later in the tutorial you reference a property called "ElNameProp", and so if I follow the steps exactly it doesn't work

    ReplyDelete
    Replies
    1. Thanks, Shaun... it should hopefully be corrected now...

      Delete
  2. Nice Post....on the properties.

    ReplyDelete
  3. Hi, please explain in which file format I can save properties files.

    ReplyDelete
    Replies
    1. The default dialogs for loading properties from a file seem to look for text files with a .properties extension, but it looks like a plain old .txt extension works, too.

      Delete

Please be respectful of others (myself included!) when posting comments. Unfortunately, I may not be able to address (or even read) all comments immediately, and I reserve the right to remove comments periodically to keep clutter to a minimum ("clean" posts that aren't disrespectful or off-topic should stay on the site for at least 30 days to give others a chance to read them). If you're looking for a solution to a particular issue, you're free to post your question here, but you may have better luck posting your question on the main forum belonging to your tool's home site (links to these are available on the navigation bar on the right).