Forum Discussion

Arjan's avatar
Arjan
New Contributor
7 years ago
Solved

How can I use a variable in Property transfer?

I want to use a variable in the Property transfer screen. I use JSONPATH to extract an ID (see screenshot) I use the variable: invoice_id = 1041   When I use the following JSONPATH expression I ge...
  • PaulMS's avatar
    PaulMS
    7 years ago

    A test case property can be used with JSONPath match assertions and XPath property transfers so JSONPath property transfer should work as well. It seems to be a defect because $ is a special character for JSONPath and property expansion.

     

    Groovy script can be used as a workaround

    (removed single quotes around id in JSONPath for this example)

     

    def sourcename = 'source test step name'
    def propname = 'test case property name'
    def jsonpath = '$[*][?(@.displayName=="${#TestCase#AccountNumber}")].id'
    
    transfervalue = context.expand("\${${sourcename}#Response#${jsonpath}}")
    context.testCase.setPropertyValue(propname, transfervalue)
    log.info transfervalue