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.
#ThanksForReading