Search code examples
testingselenium-ide

API Testing in Selenium IDE


How can Selenium IDE be utilized for API Testing. i.e. Pushing the request to server and getting the response.


Solution

  • This can be done using Javascript - XMLHttpRequest Method.

    Create Request, set headers & other parameters, and hit the Server with the body.

    Command : Execute Script

    Target :

    var req = new XMLHttpRequest();
    var url = '<URL of PAI to test>';
    var method = Method to test (GET/POST/PUT/DELETE)>';
    req.setRequestHeader('Content-type', 'application/json');
    req.open(method, url, false);
    req.send(<{REQUEST BODY}>);
    

    Value : <Any variable name to store response>

    Screenshot for reference