Forum Discussion

ykrrishna's avatar
ykrrishna
Occasional Contributor
8 years ago

sending REST request with parameterised (JSON) data by testcomplete for testing

With TestComplete, I would like to send a parameterised JSON Request (probably with a different method each time.

(FYI, am dealing with REST apis)

 

What could I possibly require to achieve this ? and How to do this with just the python scripting ? If that is not feasible, how to perform the same with the integration of SOAPUI.

7 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    Currently I'm building up system to test our REST Api's just using requests library in python.

    This is success and more flexible than SOAP UI (for me)

    can add libraries like this

     

    only down side is it's functional testing only 

    let me know if need more info

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      I just use an  ServerXMLHTTP object. (https://msdn.microsoft.com/en-us/library/ms766431(v=vs.85).aspx)

       

      This is just for sending to a RESTful API during tests. There are limits to what you can do and check with it. But if you just need to drive things via an API and interpret the responses, it does the job fine.

       

      NisHera - I've been using the Requests library for Python in something outside of TestComplete and it is indeed a very nice HTTP handler. Makes things VERY simple to use. Only drawback I've found is that by making everything so simple, it sometimes goes a little too far. If a request fails, it seems to automatically try again - which I don't always want. And it can hit the usual problem in Python where a connection can get "stuck" open (although his happens a LOT more using urllib2). But I wrap the whole thing in an Eventlet to stop a connection getting stuck permanently. That, and the default logging level for the library is set way too high. But that's easy to turn down. (Just make sure you also set the same level for the urllib3 library - which it uses - as it's that that generates a lot of the unwanted "info" level log messages.)

    • ykrrishna's avatar
      ykrrishna
      Occasional Contributor

      NisHeraColin_McCraeAlexKaraskevin_kapell

      Thanks for the reply.

       

      NisHera

      I do have imported the required libraries earlier but I am getting a timeout error.

       

      Is it ok if I ask for the code samples for how you are handling your request and response from the URLs ? As I am also working on REST I hope that will be a great help

       

      Thanks All

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        Mine is VBScript ...

         

            ' Set up the POST
            Set json_object = CreateObject("MSXML2.ServerXMLHTTP")
            json_object.open "POST", <URL-OF-ENDPOINT>, False
            json_object.setRequestHeader "Content-Type", "application/json"
            ' Send the JSON
            json_object.send <JSON-DATA>
            ' Grab the reply code from the server
            reply = json_object.status

        I use it as send only. (Hence always using "POST") The response is a simple response code. Which I normally expect to be a 200. And of course, it triggers some actions from the service it hits which are reflected on the website I run the tests against.

         

         

        With a "GET" request, you get a JSON/XML blob in the response which you can parse.

         

        <URL-OF-ENDPOINT> is the API endpoint you want to hit.

         

        <JSON-DATA> is a string I build in code. It's only relevant to the application I'm testing obviously.

         

        Pretty straightforward. More reading here: https://msdn.microsoft.com/en-us/library/ms766431(v=vs.85).aspx

  • kevin_kapell's avatar
    kevin_kapell
    Frequent Contributor

    For API Testing you can use SOUPUI but if you do not have a tool already consider using Postman & Newman (both free). Newman is a command line interface for running Postman collections. TestComplete can trigger the Newman script.