Create API Test Automation with REST Assured

What is REST-assured?

There are many ways to perform the REST assured API testing like using POSTMAN client, cURL, JMeter, SOAPUI. Apart from that, Java-based API test framework can be used (Apache HTTP Client, Jersey Test Framework and Rest assured).

Testing and validating REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of using these languages into the Java domain.

Example: This example for basicly usage of Rest Assured for your API Automation. We are trying to get some data from API response.

(GET) –> https://reqres.in/api/users/2

Response:

{
"data": {
"id": 2,
"email": "janet.weaver@reqres.in",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
},
"ad": {
"company": "StatusCode Weekly",
"url": "http://statuscode.org/",
"text": "A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things."
}
}

Automation Script: We have learned how is dummy API working and responding manually. Now we are ready to automate this with Rest Assured. Finally we will add 3 test assertions (verifications). If any assertion fails, test will be marked as failed.

  • Response Status is 200 (successfull)
  • Body data.email value equals to “janet.weaver@reqres.in”
  • Getting reponse less than 2 seconds.

when().
        get("/api/users/2").
then().
        statusCode(200).
        body("data.email", equalTo("janet.weaver@reqres.in")).
        time(lessThan(2000L));

You can read this tutorial “Quick Start with API Automation” to learn how to do it with MomentumSuite.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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