
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Cypress Support for API Automation Testing
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
Response
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
cy.request('https://jsonplaceholder.cypress.io/comments').as('cn') //request aliasing with @cn cy.get('@cn').should((response) => { expect(response.body).to.have.length(500) expect(response).to.have.property('headers') })
Advertisements