I'm trying to test an ad network call by using cypress, how can I filter the network call and get the response.
specifically for query string parameters
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.
console.log(interception)
as well as console.log(interception.response)
and take a look in DevTools what information those objects contain. You'll see that response has url
property, so to get it you just need interception.response.url
. You'll need additional few lines of code to parse out the query string parameters, but that's easily googleable. Regarding multiple response, sorry, don't know unless you specify as many waits as there are requests (you need only one intercept)