Forum Discussion

richie's avatar
richie
Community Hero
6 years ago
Solved

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

 

12 Replies

    • richie's avatar
      richie
      Community Hero

      Hey nmrao 

       

      yeah - I'm still talking about the same thing - I'm getting boring - right? :)

       

      So - yeah - I have a REST GET API where the query parameters on the request correspond to attributes of tables.  This will be for a reference data service providing lots of different internal systems with referencedata when required.

       

      So - say I have a table called 'PersonalDetails' with the following attributes: ID, firstname, lastname, country, phonenumber and multiple records populate this table - but for now lets use the following data

       

      ID = 123456

      firstname = rich

      lastname = jones

      country = uk

      phonenumber = 07958 985 000

       

      In the system - namespace is a grouping of tables and dataset is an alias for tables - the following GET URI 

       

      my GET URI --> http://help.azurewebsites.net/api/1/{namespace}/{dataset}?queryparm1=value&queryparm2=value

       

      the RAW of the above would be as follows:

       

      http://help.azurewebsites.net/api/1/biology/PersonalDetails?firstname=rich&lastname=jones

       

      Now - cos I can't parameterize the QueryParm names (values I can parameterize, but not the names) with the OTB functionality - the only option left to me is to hardcode multiple REST requests in the Projects section of ReadyAPI! essentially hardcoding the QueryParameters.  I have 1500 tests at the moment - thats a lot of requests in my project.

       

      Hence the reason I'm trying to put something together that allows me to call the queryparms and values to build the query string of my GET request from say a Properties step.

       

      For example - if I can query the table and extract the columns and a single record's values - I can build a Properties step containing all attributes and the values and then hopefully I can build the REST requests QueryParameters from the attributes and values set in the Properties step 

       

      (OR - I can just create a single properties file at the start and load in the table attributes and 1 record's values for later use)

       

       

      I hope I've been clear - I know I tend to ramble a bit - but its to try and ensure I've been clear in my query.

       

      Thanks for providing the URL - I have questions about this - but I'll ask in a separate post

       

      Again thanks to all and Rao for helping me out so much!  I even submitted a support call to SmartBear - but they don't support groovy coding so I know they're just gonna reject my support request - but I thought it was worth a shot!

       

      richie

       

       

      • nmrao's avatar
        nmrao
        Champion Level 3

        richie,

        Thank you for your patience. Bear with me, few more questions.

        1.  You like to query db and then use the data in GET call of REST. correct? If yes, then the issue which you are mentioning for REST query parameters will be an issue even to do dynamic sql query as well. Isn't it?

        2. The final objective is to compare sql query response with REST call (GET with query parameters) response. Is this understanding correct?