Mob into Restful

Suppose that you just joined a startup whose application relies heavily on its Restful Service. How to approach the automation of its Rest API?

First, let’s see how we test Rest API stage by stage

  • Basic correctness of API: check status code, headers, response body
  • Data-driven:Send requests with edge data(for request query string & request body)
  • Complex scenarios: Combo of different sequences of requests
  • Discoverability of the API
  • Consumption of different representations for the same resource

Test data we need

  • List of resources that API provides
  • Data: for Query string or Request body
  • Expected response payload(Json or xml)

Manually collecting those data could be cumbersome and time-consuming. Before we automate Rest API, let’s automate data-gathering for Rest API first!

Step 1: Capture Rest Traffic Using BrowserMobProxy and Selenium
We can use BrowserMobProxy and Selenium to capture all the traffic in the web. In this case, we are only interested in the traffic from/to our Rest API service , so do apply request filter for proxy server.

While proxy server is running, we can run selenium automation test suite(if any) at the same time, just to trigger corresponding Rest API calls. Proxy will catch all REST traffic and save it in .har file

If no selenium automation for smoke test yet, no worries, just run BrowserMobProxy server in standalone mode, and launch browser & apply proxy setting manually, and go through smoke test suite manually so that all kind of Rest Requests are triggered.

Step 2: Extract Test Data from .har File
A typical Rest API Test Case would need the following info:

  • Resource URI
  • Data for query string, or data for request body
  • Payload(Json or XML)

And all these data can be extracted from .har file that we saved in step 1. See here on how ot parse .har file.

Step 3: Automate these Rest API Test Cases Following This Process
Now with all the data ready, we can really start to automate Rest API !

Leave a Reply

Your email address will not be published. Required fields are marked *