cancel
Showing results for 
Search instead for 
Did you mean: 

Property Expansion and Groovy Script

Occasional Contributor

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 4
Super Contributor

Re: Property Expansion and Groovy Script

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
Occasional Contributor

Re: Property Expansion and Groovy Script

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
Super Contributor

Re: Property Expansion and Groovy Script

Hi,

oh.. sorry.. in that try using

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

instead!

regards,

/Ole
eviware.com
Occasional Contributor

Re: Property Expansion and Groovy Script

Hi Ole,

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

/Noel 
New Here?
Join us and watch the welcome video:
SmartBear + Cucumber