Applies to Ready! API 2.0, last modified on June 19, 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.

Transfer Property Values

You can specify property expansion to use a property value of one test item in another.

The syntax of the property expression is:

${[#Scope#]Property Name[#Path Expression]}

Where:

  • Scope – A scope in which the desired property is declared. The following table lists available 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}
  • Property Name – The name of the desired property.

  • Path Expression – An XPath or JSONPath expression to obtain a specific value from an XML or JSON content.

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}' )

See Also

Get Data Dialog
Property Transfer Test Step