Property Expansion

Applies to ReadyAPI 3.51, last modified on March 04, 2024

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:

    ${DataSourceTestStep#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 Data Source test step. That is, the maximum row number should be less than the Row Per Iteration property of your Data Source 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.

    ReadyAPI cannot parse XML documents that contain the byte order mark (BOM) character.
Scope Description Example
#Project# Properties specified in the project. ${#Project#<Project property>}
#TestSuite# Properties specified in the parent test suite. ${#TestSuite#<Test suite property>}
#TestCase# Properties specified in the parent test case. ${#TestCase#<Test 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 virtual service.
Note: This scope is available only in virtual services.
${#MockService#<Virtual service property>}
#MockResponse# Properties declared in a virtual response.
Note: This scope is available only in virtual services.
${#MockResponse#<Response property>}
#SecurityTest# Properties declared in a security test.
Note: This scope is available only in security tests.
${#SecurityTest#<Security test 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.

Nest a property expansion

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

  • Refer to a property that contains another 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!

Use property expansions in scripts

You can use property expansions 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}' )

When a property expansion is invoked within the context.expand() element, ReadyAPI implicitly replaces it with the whole text of the property the expansion refers to. For instance, if in the previous example the username has the tester value, the resulting expression will be as follows:

def foo = context.expand( 'tester' )

With this in mind, you can construct more complex expressions by concatenating strings:

// The test case has the following properties:
// Username == tester
// ID = 12345

def foo = context.expand ( '${#TestCase#Username} ${#TestCase#ID}' )
// Identical to foo = context.expand('tester 12345')

def foo = context.expand ( 'mynameis${#TestCase#Username}123' )
//Identical to foo = context.expand('mynameistester123')

Isolate a 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

Watch the video
 
Highlight search results