A bit more groovy help? Populating a REST URI with Properties Set On TestCase?
Hey!
I'm currently trying to play around with some groovy snippets people have helped me with to build a REST request using parameters saved as properties on the TestCase object - but surprise, surprise! it doesnt work!
to reiterate - I was thinking about setting a couple of properties on the TestCase object and then grabbing the values to build the REST URI.
So - I was thinking have a groovy step, followed by a REST step - the groovy is as follows:
// get CommodityType_Name and EffectiveFrom properties from TestCase - i.e. properties were set at TestCase level level def prop1 = testRunner.testCase.getPropertyValue( "CommodityType_Name" ) def prop2 = testRunner.testCase.getPropertyValue( "EffectiveFrom" ) // write the CommodityType_Name to the REST Request step testRunner.testCase.testSteps["REST Request"].setPropertyValue( "CommodityType_Name", prop1 ) log.info("prop1") // write the EffectiveFrom to the REST Request step testRunner.testCase.testSteps["REST Request"].setPropertyValue( "EffectiveFrom", prop2 ) log.info("prop2")
First things first - according to some help Lucian gave me last week - I'm thinking my mistake here is that I need to expand the property first (but I don't know the syntax to do this on my "getProperty line" line) - currently my log.info debug attempt is returning the propertynames rather than the values - would anyone know how to do this?
Finally - when I run the test case - I was 'hoping' that the CommodityType_Name and EffectiveFrom parms and values would be built into the REST URI - they weren't. Would anyone know what I'm doing wrong here?
LowPriority: Finally - and i know this is a little open subject so shouldnt be asking - but its always so frustrating my having to ask you guys for coding help....does anyone know any "SoapUI groovy from scratch, no previous coding experience" books/resources/artefacts I can pick up? There's lots of stuff out there - but its for the person who can already code - I need something that can teach me about it knowing absolutely nothing, the groovy tutorials out there aren't tailored for someone with my minimal coding skillset!
Thanks guys - appreciate all/any advice/guidance/help you can give me!
richie
richie ,
Here is the working groovy script which reads properties from Properties Test step(add this step if you are going to test below script) and use them as query parameters and make the REST Call (sample for GET call ).
Note that this does not use native REST Request Test step to make rest call. In stead uses a library which needs to be copied under READYAPI_HOME/bin/ext directory and restart the tool before running.
Please change variables as per your environment and give it a try.