Applies to ReadyAPI 2.2, last modified on November 17, 2017

Property expansion allows you to insert variable parts in a property value, request body, scripts, and so on. This topic describes how to specify property expansion manually, but you can specify it visually by using the Get Data dialog.

Syntax

The typical syntax of a property expansion is as follows:

${#Scope#Property-Name}

The full syntax includes a few more parameters:

${#Scope#Property-Name[::DataSource-Row][#Path-Expression]}

Where:

  • Scope – The scope to which the desired property belongs: #Project#, #TestCase#, and so on. You can find a complete list of available scopes below.

  • Property-Name – The name of the desired property.

  • DataSource-Row – Optional. Used for property expansions that refer to a data source property (column). If your test obtains several data source rows on each iteration, you can use this parameter to specify the row you need, for example:

    ${DataSouceTestStep#MyProperty::1}

    The index is zero-based. The sample expression above points to the second row of the row pool that is returned on an iteration.

    You specify the number of rows to get in the Row Per Iteration property of the DataSource test step. That is, the maximum row number should be less than the Row Per Iteration property of your DataSource test step.

    To learn more about how it works, see the Obtain Property Values of the Specific Row example.

  • Path-Expression – Optional. Meaningful for properties that store XML or JSON data. Specifies an XPath or JSONPath expression to obtain a specific value from the XML or JSON content.

Scope Parameter Values
Scope Description Example
#Project# Properties specified in the project. ${#Project#Project property}
#TestSuite# Properties specified in the parent test suite. ${#TestSuite#Suite property}
#TestCase# Properties specified in the parent test case. ${#TestCase#Case property}
TestStep# The name of the test step in the same test case. ${REST Request#Response}
#[TestSuite#TestCase#TestStep]#

To refer to properties in other test suites or test cases, use the full "path" to specify the desired scope.

The "path" part is enclosed in square brackets.

${#[Suite name#Case name#Step name]#Property name}

${#[Shared suite#Common]#Username}
#Global# Global property.
Note: You can omit this scope.
${#Global#Global Property}

or

${Global Property}
#System# System property.
Note: To see available system properties, select Help > System properties from the main menu.
${#System#os.name}
#Env# System environment properties. ${#Env#JAVA_HOME}
#MockService# Properties declared in a virt.
Note: This scope is available only in ServiceV.
${#MockService#Virt Property}
#MockResponse# Properties declared in a virt response.
Note: This scope is available only in ServiceV.
${#MockResponse#Response Property}
#SecurityTest# Properties declared in a security test.
Note: This scope is available only in Secure.
${#SecurityTest#Secure Property}

Dynamic Expression

The dynamic property is a form of property expansion where you insert a Groovy script to provide dynamic data.

To add Groovy to property expansion, use the following syntax:

${=Groovy code}

For example, the following expression generates a random number between 0 and 999:

${=(int)(Math.random()*1000)}

Depending on where you use the property expansion, you can use relevant scripting objects. For example, in the request test steps, you can use the request object:

  • The ${=request.name} expression evaluates to the name of the request test step.

  • The ${=request.operation.interface.project.name} expression evaluates to the name of the project.

Almost in any script, you can use the log object.

Nesting Property Expansion

You can use property expansion in another expression or its part. For example:

  • Refer to a property that contains other property expansion:

    Property Value Evaluated Value
    PropertyA Hello! Hello!
    PropExp ${#TestCase#PropertyA} Hello!
    Result ${#TestCase#PropExp} Hello!
  • Use the property expansion as part of an expression:

    Property Value Evaluated Value
    PropA Hello! Hello!
    PropB Good Morning! Good Morning!
    PropName PropA PropA
    Result ${#TestCase#${#TestCase#PropName}} Hello!
  • Use the property expansion to specify an XPath expression:

    Property Value Evaluated Value
    xml

    <property>
      <value id="123">Hello!</value>
    </property>

    <property>
      <value id="123">Hello!</value>
    </property>

    id 123 123
    xpath //value[@id=${#TestCase#id}]/text() //value[@id=123]/text()
    Result ${#TestCase#xml#${#TestCase#xpath}} Hello!

Using Property Expansion in Scripts

You can use property expansion in scripts. To get a value of a property in a groovy script, use the following syntax:

def foo = context.expand( 'Property expansion' )

For example, the following code snippet assigns the value of the Username test case property to the foo variable:

def foo = context.expand( '${#TestCase#Username}' )

Isolating Property Expansion

Sometimes, you may need to pass a property expansion without parsing it. For example, if you have a data source that contains multiple property expansions, and you want to pass these expansions to parse them later.

In this case, you need to isolate the property expansion. To do this, duplicate the $ symbol at the beginning of the expression. During the test run, ReadyAPI will remove the first symbol and pass the rest expression.

For example, if you specify the following expression –

$${#TestCase#Property}

– ReadyAPI will pass the following expression:

${#TestCase#Property}

See Also

Get Data Dialog
Property Transfer Test Step