Home > Enterprise >  What types of dependencies available to do Api automation using selenium?
What types of dependencies available to do Api automation using selenium?

Time:09-06

I am using rest-assured dependency in my project for testing API's with selenium.

  1. Can anyone guide me why basically we use rest-assured dependency in API testing ? (Tried finding the answer from my seniors who developed our project framework and online, i couldnt get any answer why are we using this, it would help me if anyone guides me with the reason ?)

  2. And what are the other ways to do API automation using selenium ?

  3. why should we use them ? (in comparison with rest-assured ?)

Thank you.

CodePudding user response:

  1. Just because Rest-Assured (RA) is a code-based tool to test API. It supports:
  • make HTTP(s) request
  • extract value from response
  • assert response
  1. Selenium is tool to control web browser, it CANNOT do API testing.
  2. I don't know why you compare Selenium to Rest-Assured. They are 2 different tools that serves 2 different purposes.

CodePudding user response:

Selenium is not typically used for REST API testing. Selenium is a tool that can control web browser. Despite a web browser is a sort of HTTP client, it is very specific client that is intended for browsing web and maintain high level of user security. The above puts certain degree of restriction of what you can and cannot do with the browser. For example:

  1. You can only fire GET request from the address bar
  2. You can do POST request using HTML form but you have to have an HTML page with the form and fixed set of parameters
  3. You can overcome the above if have the page with any javascript client so that you can configure different requests configurations

Points 2 and 3 basically mean you have another level of communication in your framework and that level has to be properly maintained. That's because Web Browser is not naturally intended for interacting with API. But only with very narrow part of what HTTP can offer (again we can overcome that restriction by javascript code executed within the browser but that would be another level of complexity).

RestAssured is pure HTTP client with some handy and neat functionality allowing to easily manipulate with requests and responses. So it allows to fire any type of requests supported by HTTP protocol, parse responses responses and verify them (often all in a single statement).

The latter is naturally designed for interacting with REST API, does not introduce extra levels to your tests, does not have limitation like the browsers have.

Recap

The below schema demonstrates the difference of having your API tests implemented in both approaches:

  1. Selenium case:

Selenium binding lib -> Web Driver -> Browser -> API GET (rarely others - need to maintain special file for that)

  1. Rest-Assured case:

Rest-Assured lib -> API ANY SORT OF REQUESTS

P.S. - In the same way as RestAssured handles API case much effectively than Selenium, Selenium handles Web Testing in much more effective way than RestAssured since the latter cannot neither control browsers nor even execute JAvaScript code. That is why we have two such a powerful and great tools each of which perfectly serves the needs it naturally designed for.

  • Related