Forum Discussion

richie's avatar
richie
Community Hero
6 years ago
Solved

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

 

 

 

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

  • 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!

  • 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

  • Lucian's avatar
    Lucian
    Community Hero

    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!

    • richie's avatar
      richie
      Community Hero

      Hey Lucian and All

       

      specifying the property expansion scope didn't appear to work as hoped! :(

       

      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

      • Lucian's avatar
        Lucian
        Community Hero

        hey richie,

         

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

  • 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

    • TanyaYatskovska's avatar
      TanyaYatskovska
      SmartBear Alumni (Retired)

      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.