Does cypress support api automation testing also?

Yes Cypress supports API automating testing also. XHR is known as the XML HTTP Request. It is an API which is used as an object. Its methods pass data between a server and browser. An XHR object can obtain data from a server in the form of a Response.

Cypress can not only be used for UI automation, but can also be used to supervise the network traffic by directly acquiring the XHR objects. It is capable of mocking or stubbing a Response. An XHR information is obatined in the Network tab in the browser.

XHR Header


To trigger an XHR request, the command cy.request() is used. The method cy.intercept() redirects the Responses to the matching requests.

Implementation XHR request

//request aliasing with @cn
cy.get('@cn').should((response) => {

Updated on: 25-Jun-2021


Kickstart Your Career

Get certified by completing the course

Get Started