Forum Discussion

Noel_Murphy's avatar
Noel_Murphy
Occasional Contributor
17 years ago

Property Expansion and Groovy Script

Hi there,

If I have a property attached to my project called FILE_PATH, can I make a direct reference to it within Groovy script.

${#Project#FILE_PATH}

or do I have to use something like context.getProperty("FILE_PATH")

Finally I would like to know if its possible to make a change to this properties value and then save the change to the project.

Thanks,

Noel

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    you can either get the property value with

    context.expand( '${#Project#FILE_PATH}' )

    or get and set the property valuewith

    def prop = testRunner.testCase.testSuite.project.properties["FILE_PATH"]

    // set
    prop.value = ...

    If you want to save the project then do

    testRunner.testCase.testSuite.project.save()

    should do the trick!

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    oh.. sorry.. in that try using

    mockResponse.mockOperation.mockService.project.properties["FILE_PATH"]

    instead!

    regards,

    /Ole
    eviware.com
  • Noel_Murphy's avatar
    Noel_Murphy
    Occasional Contributor
    Hi Ole,

    Thank you so much for the quick response.

    I can get the prop = context.expand( '${#Project#FILE_PATH}' ) to work but not the def prop = testRunner.testCase.testSuite.project.properties["FILE_PATH"]

    This is because I'm running a peice of groovy script from the mock response editor and its not invoked with testrunner.

    Is there a way around this?

    Thanks,

    Noel
  • Noel_Murphy's avatar
    Noel_Murphy
    Occasional Contributor
    Hi Ole,

    Thanks again for the speedy response, I have it working now.

    /Noel