cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anyway to parameterize a REST APIs Query PARMS?

SOLVED
Community Hero

Is there anyway to parameterize a REST APIs Query PARMS?

Hi,

 

I've been trying to find alternative ways around the same problem - and I asked a similar question today but perhaps from a different perspective - so I apologise if this appears to be the same post although I dont think it is.

 

Oh - Ive just reread the other post - and it looks like i did ask virtually the same question - but I was rambling a lot and dont think I was very clear in my question - this I think is a lot clearer than my original post

 

Capture.PNG

 

 

If you look at the image above - you can see I tried parameterizing the REST QUERY PARM NAME value using a custom property I'd created on the testcase.

 

It didn't work - is there anyway to parameterize the actual name of the parm?

 

thanks - it seems a bit rubbish that you cant parameterize the parm name - there must be a way to do it .

 

 

can anyone steer me in the right direction?

 

thanks to all!

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

Hi @richie,

 

It should work but it is not ${TestCase#value} but ${#TestCase#value}.

 

ReadyApi has the following rules:

1. If you define the scope you put a # in front of it like in: {#TestCase#...}, {#Project#...} or ${#TestSuite#...}

2. If you are reffering to a test step you use it without a # like in ${GetSessionId#...}

 

Cheers!



If my answer helped please click on the 'Accept as Solution' button.
Contributor

Re: Is there anyway to parameterize a REST APIs Query PARMS?

@richie

using groovy we can add parameters at run time.kindly, try the below code snippet:-

*********************************************************************

def step=testRunner.testCase.getTestStepByName("REST")
def req=step.httpRequest
req.removeProperty("name")
req.getParams().each{
log.info it.value.name
}

//required to add field before setting the value  
req.addProperty("name")

// set the new field value
req.setPropertyValue("name","abc")

******************************************************************

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.Smiley Wink

11 REPLIES 11
Highlighted
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

Hi @richie,

 

It should work but it is not ${TestCase#value} but ${#TestCase#value}.

 

ReadyApi has the following rules:

1. If you define the scope you put a # in front of it like in: {#TestCase#...}, {#Project#...} or ${#TestSuite#...}

2. If you are reffering to a test step you use it without a # like in ${GetSessionId#...}

 

Cheers!



If my answer helped please click on the 'Accept as Solution' button.
Contributor

Re: Is there anyway to parameterize a REST APIs Query PARMS?

@richie

using groovy we can add parameters at run time.kindly, try the below code snippet:-

*********************************************************************

def step=testRunner.testCase.getTestStepByName("REST")
def req=step.httpRequest
req.removeProperty("name")
req.getParams().each{
log.info it.value.name
}

//required to add field before setting the value  
req.addProperty("name")

// set the new field value
req.setPropertyValue("name","abc")

******************************************************************

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.Smiley Wink

Community Manager

Re: Is there anyway to parameterize a REST APIs Query PARMS?

Hi @richie,

 

Do Lucian's and ashu248's suggestions help you? Please accept a solution to highlight the best answer and give Kudos to the replies that you like.

---------
Tanya Gorbunova
SmartBear Community Manager

Join the September Hub-bub to show off, learn and win
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

Hey @Lucian and All

 

specifying the property expansion scope didn't appear to work as hoped! Smiley Sad

 

I have the following specified as parms on my GET request

 

Name                                                              Value                                                                   Type

Namespace                                                   ${#TestSuite#Namespace}                               Template

Dataset                                                           ${#TestSuite#dataset}                                       Template

CertificateType_Name                                  ${Properties 1#CertificateType_Name}          Query

${#TestCase#QueryParmName}                 ${#TestCase#QueryParmName}                      Query

 

 

HOWEVER - the query string for the GET REST request reads as follows:

 

?CertificateType_Name=Other certificates&${#Testcase#QueryParmName}=QueryParmValue

 

 

 

n.b. the TestCase has the parameter 'QueryParmName' with the value 'QueryParmValue' specified -but I was hoping that instead of 

 

?CertificateType_Name=Other certificates&${#Testcase#QueryParmName}=QueryParmValue

 

It would generate as 

 

?CertificateType_Name=Other certificates&QueryParmName=QueryParmValue

 

 

As you can see - my query string doesn't appear to be replacing the query parm name as I want it to - despite using the correct prop expansion scope.

 

 

Can anyone clarify?  I'm sure I've done this before and it worked fine - I just cant remember how I managed it!

 

 

Thanks to all!

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

hey @richie,

 

I am sorry that this didn't work for you. I will come back with a response later today.



If my answer helped please click on the 'Accept as Solution' button.
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

Hey @Lucian

 

no pressure fella - I should be able to sort this out myself - I just cant see what I'm doing wrong!

 

nice one!

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

I only now get what you mean. You want to have something like a dynamic REST definition. I don't think this is possible.

 

The way I see it the REST definition (defined in the Projects tab) has nothing to do with the tests (from the SoapUI tab) that use the definition. Thus I can't see a way for you to change the definition dynamically from the request itself because the request itself SHOULD use the REST definition which is like a pattern for it. There may be some groovy workaround but I really doubt that this can be done out of the box.



If my answer helped please click on the 'Accept as Solution' button.
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

well thats not the answer I wanted! Smiley Sad

 

**bleep** - ok - groovy....my favourite!

 

thanks man!

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

Re: Is there anyway to parameterize a REST APIs Query PARMS?

I got bleeped!

 

wow - I don't remember using any profanity!?!??????

 

apologies to all!

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
New Here?
Join us and watch the welcome video:
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win