How to use cypress to get network call after page load

Viewed 587

I'm trying to test an ad network call by using cypress, how can I filter the network call and get the response. enter image description here

specifically for query string parameters

enter image description here

1 Answers

Like this for example:

it('Some test', () => {
    cy.intercept('/').as('myRequest');
    cy.visit('www.example.com');
    cy.wait('@myRequest').then((interception) => {
        cy.log(interception.response.body);
    });
});

To listen for only ads requests use cy.intercept('/ads'). Remember to put intercept before you open the page.

Reference: https://docs.cypress.io/api/commands/intercept

Related