Forum Discussion

thatsthat's avatar
thatsthat
Contributor
3 years ago
Solved

Rest request in a Test Case disables the Resource and Parameters fields / Add Parameter to Resource

After working through the details of a series of requests I have strung them together in to a Test Case by using the 'Add Request to Test Case' feature.

 

Once I do this .. the Resource and Parameters fields become greyed out ...I also can't add new fields to the Form or Request tabs (i.e. no plus sign) .. is this normal? I normally test Soap API's and I can easily pick up data from one request and pass it in to the next using ReadyApi but not here (perhaps my ignorance of Restful requests is showing).

 

This is my workflow (a portion of it):

 

Step 1 create a shopping cart which generates Cart Id 1001

Step 2 convert the cart by using the Id in Step 1

 

Unlike in Soap test cases I see no way of seeding the following request from a response if key fields are greyed out.

 

 

 

 

  • JoostDG's avatar
    JoostDG
    3 years ago

    Hi thatsthat  

    You can add cartid in the resource url directly in the api definitions, like this "/api/cart/{cartid}". I would prefer cartId to be honest, that's more in accordance with naming standards, but I guess cartid would work as well...

    Type should be template.

    Note that this will probably impact any test cases you already have (the values for cartid will get blanked out).

5 Replies

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    Hi thatsthat ,

    In readyAPI you have 2 main sections. First "APIs" is the place were you import your REST api definitions (e.g. via the swagger yaml file). Once you have the api's you can indeed use these to populate the second section "Functional Tests". Here you can do the actual testing via test suites and test cases. 

    Regarding your issue:

    In your API definitions (section 1) there should be a query parameter called "id" (or equivalent, don't know your exact naming conventions) for that resource. If not present, you can add them as "template" type. See below an example from my api definitions. It should become visible in your url of the resource between curly brackets. You cannot do this in the "functional tests" section.

    Note: I don't use the "form" tab a lot, as I indeed recall it's more tailored to soap requests. I use mostly "outline". 

     

     

     

     

    • richie's avatar
      richie
      Community Hero

      Hey thatsthat 

       

      Just a follow up to what JoostDG  has mentioned - if you consider the APIs as the parent record and the requests (test steps) in your testcase as the child record - that might help understand why you can't edit the fields in the teststep form.

      If you don't appreciate this point it can be a little confusing and you end up thinking there's a defect in ReadyAPI, but in fact it works this way as a consequence of this parent/child relationship - i.e. if you want to make changes, you can't change the child you have to go back up to the parent.

       

      Hence if you want to make structural changes to the URI of a teststep, you need to do it in the API section - not in the teststep.  You can only make non-structural changes in the teststep

       

      Although possibly annoying at first, this parent child relationship actually helps speed things up quite a bit.  You make a single change in the parent and it filters to all it's children.  It also means you don't have to go through any hassle when creating the teststeps - the method, domain, URI and payload (if there is one) is already built for you - then you can just tailor the specific parm values, etc. as required in the teststep (non-structural changes)

       

      Hope this helps a bit,

       

      nice one

       

      Rich

  • Thanks for clarifying this JoostDG .. and again to you richie for the bigger picture I needed that ..definitely more reading for me.

     

    Cool so change back on the API at self before I add to test case nice.

     

    Right so this is an odd request someone has put together ..the 'Id' of the shopping cart is in the Resource section i.e. 1441 below .. there is no query parameter:

     

    The valid request when sent looks like this:

     

    GET https://host/api/cart/1441?clientId=uavittrade

     

    So it makes sense to add one so I can pass it on (or call it from an earlier request).

    If I add the parameter like this:

    I see this:

    If I set a value in the cartid field and send the request I get a 'No such host is known error as I have compromised the url. You can see no cart id now is being passed:

     

    GET https://host/api/cart?clientId=uavittrade

     

    If I change the parameter from template to QUERY I see the cartid now in the Paramaters section at top right ..but this produces an invalid query

     

     

    https://host/api/cart?clientId=uavittrade&cartid=1441

     

    I somehow need to target the Resource .. is that possible? 

     

     

    • JoostDG's avatar
      JoostDG
      Frequent Contributor

      Hi thatsthat  

      You can add cartid in the resource url directly in the api definitions, like this "/api/cart/{cartid}". I would prefer cartId to be honest, that's more in accordance with naming standards, but I guess cartid would work as well...

      Type should be template.

      Note that this will probably impact any test cases you already have (the values for cartid will get blanked out).