Las URLs que usa el profesor en esta clase son:
https://pokeapi.co/api/v2/pokemon/ditto
https://pokeapi.co/api/v2/pokemon-species/1
Introducción al curso
Presentación del curso
Instalación de recursos
Cookies y Localstorage
Cookies
Local Storage
Emulando dispositivos
Emulando dispositivos
Instalando plugins
Usando xpaths
Flaky tests
¿Qué son los Flaky Tests?
Interceptando Network Requests
Interceptando request
Buenas prácticas
Patrones de diseño: Page Object Model
Custom commands
Variables de entorno
Cypress.env
Visual testing
Visual testing
Seguridad
Seguridad en Cypress
Navegación entre pestañas del mismo sitio
Navegar entre diferentes dominios en diferentes tests
Navegar entre diferentes dominios en diferentes tests y compartir información entre ambas páginas
Data Driven Test
Cypress fixtures
BDD
Configuración de plugins y steps dinámicos
Shared Step Definitions
Data Driven Test por medio de Scenarios Outline
Reportes
Múltiples reportes
Allure report
Docker
Cypress con docker container
Dashboard
Usando dashboard de Cypress
Alternativas gratuitas al Dashboard de Cypress
CI/CD
Jenkins
Final
Cypress Scenario recorder plugin
You don't have access to this class
Keep learning! Join and start boosting your career
When we talk about automated tests, it is key that they are resilient to unexpected changes in third-party applications or libraries. Often, they fail due to bugs not so much in our code, but in those libraries or services we use. These services may be unstable or not allocate enough resources to us in test environments. This is where Cypress, a popular testing tool, provides us with effective options such as network request interception to improve the reliability of our tests.
For those who are already familiar with Cypress, the CI.request command allows you to make requests to APIs directly:
cy.request('https://pokeapi.co/api/v2/pokemon/ditto').then((response) => { expect(response.body).to.have.property('name', 'ditto'); expect(response.status).to.eq(200); });
This command is especially useful for authenticating users or simulating interactions with backend services. However, it does not allow us to validate how our interface handles these network requests.
The intercept feature in Cypress covers this limitation. It allows capturing and modifying requests, as well as validating that certain queries are performed when interacting with the interface.
We can intercept a GET request to analyze how the application responds:
cy.intercept('GET', '**/pokemon/1').as('getBulbasaur');cy.visit('/some-page');cy.contains('Bulbasaur').should('be.visible');
cy.wait('@getBulbasaur').then((interception) => { expect(interception.response.body.name).to.eq('bulbasaur'); expect(interception.response.statusCode).to.eq(200);});
cy.wait
to wait for the intercepted request to complete, allowing us to verify that the response is as expected.What if an API is known to be slow? We can adjust the timeout to ensure that tests have enough time:
cy.wait('@getBulbasaur', { timeout: 20000 }).its('response.statusCode').should('eq', 200);
Using intercepts in automated testing with Cypress can be a valuable tool. Not only does it allow us to verify that you are collaborating correctly with APIs, but also to simulate certain conditions of the production environment without risk, validating how our applications behave in response to unexpected changes or temporary failures.
Remember that improving the resilience of your tests is essential to minimize failures and reduce maintenance. Continue to explore the broad capabilities that Cypress offers, and continue to hone your skills with each test.
Contributions 4
Questions 1
Las URLs que usa el profesor en esta clase son:
https://pokeapi.co/api/v2/pokemon/ditto
https://pokeapi.co/api/v2/pokemon-species/1
Si la request dura mucho…
// Wait until a propertyPath answers a value...
cy.wait("@myApiResponse1").its("response.statusCode").should("eq", 200);
// Wait and use a timeout
cy.wait("@myApiResponse1", { timeout: 2000 });
Como no existen los archivos de la clase, hice este pequeno ejemplo que explica la clase de forma simple…
// Save my Interceptor into a alias
cy.intercept("GET", "https://my-api.com/1").as("myApiResponse1");
cy.visit("/my-page-list");
// Navigate into a detail Page
cy.get("#detailBtn-1").click();
// Use my alias
cy.wait("@myApiResponse1").then((interception) => {
cy.log(interception);
// Assert my Interceptor
expect(interception.body).to.have.property("property-name", "value");
});
Want to see more contributions, questions and answers from the community?