Selenium Interview Question 2 – Can Selenium Be Used For API Automation?

Selenium official website introduce Selenium as “Selenium automates browsers. “. A browser is an interface or abstraction between “How it looks?” (Front end of an application) and “How something is actually performed?” (Middleware and backend of an application). Selenium is for “How it looks?” part of an application only.

Selenium is designed to automate front end of an application. It is NOT supposed to do API testing automation. I see many posts around this topic where authors have shown they automated API using Selenium. They use RestAssured or Apache HTTP Client ( Both for Java) with Selenium and perform API automation. You are not actually doing API automation using Selenium. You are extending your framework to do so. API testing using these libraries are meant to automate API as we have Selenium to automate front end. If Selenium provides you ways to automate API without using any third party libraries, then you can say Yes! Selenium automates API. But as of now Selenium is only for front end.

Recently , I have seen a post on LinkedIn where a guy automated API testing using executeScript() method provided by Selenium. Selenium provides you a way to execute JavaScript commands. JavaScript provides
XMLHttpRequest Object to send HTTP request You can develop codes to hit request and assert response. You can execute above code by passing in to executeScript() method of Selenium.

Agree it is done using Selenium but not a recommended way.


3 thoughts on “Selenium Interview Question 2 – Can Selenium Be Used For API Automation?

  1. Hey thanks Amod for elaborating on that.

    Then when we use Actions or Robots and POI don’t we say that with selenium we can read excel file, Upload a file. Use windows control, we use Test NG for better control over the test.

    So is it not the same thing where using third party we have extended the capabilities of selenium

    1. Again its not extension of capabilities of Selenium. Its extension of framework. Your framework may do multiple things using different libraries.

Leave a Reply

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