Forum Discussion

mikek's avatar
mikek
New Contributor
15 years ago

Context won't expand certain properties inside a Groovy class

Hi,

I'm trying to do a REST request which calls a groovy class for one of it's parameters, the call looks like this:
${=MyClass.call("${#Project#property}", request, context, log)}


The context which is passed is the DefaultPropertyExpansionContext.
Inside the Groovy class's method I need to access the request parameters, but some of them require expansion.

This is where I get stuck, since if I try to expand the property I get nothing.
The context will only expand properties on the project level, but not any lower (TestCase/TestSuite).

Example from the script:
log.info(s + "=" +  request.getPropertyValue(s))
log.info(s + "=" + context.expand("'" + request.getPropertyValue(s))+ "'")


Which prints out:
Tue Apr 13 09:40:56 IDT 2010:INFO:method=activateContent
Tue Apr 13 09:40:56 IDT 2010:INFO:method='activateContent'
Tue Apr 13 09:40:56 IDT 2010:INFO:msisdn=${#TestCase#phoneNumber}
Tue Apr 13 09:40:56 IDT 2010:INFO:msisdn=''
Tue Apr 13 09:40:56 IDT 2010:INFO:operator_id=${#TestSuite#operatorId}
Tue Apr 13 09:40:56 IDT 2010:INFO:operator_id=''


Please advise as to how this can be done.

Regard,
Mike
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I created a method in an external script like this:


    class TestUtils {
        def static externalExpand(propertyString, context, log) {
        log.info propertyString + " = " + context.expand( propertyString )
        }
    }


    and passed the property in a Groovy script step like this:

    TestUtils.expand("\${#TestCase#test}",context, log)


    and got this:

    Tue Apr 13 11:04:07 EDT 2010:INFO:${#TestCase#test} = 123456789


    I have no single quotes around the passed property value in the external method.

    Does this help?