I am fetching data with a network call:
/third-party-service/pragma?perPage=15&page=1
Request Method: GET
Trying to intercept it with code:
// Overriden not to clear localStorage authentication tokens
const clear = Cypress.LocalStorage.clear;
Cypress.LocalStorage.clear = function(keys) {
if (keys) {
return;
}
};
context('Navigation', () => {
before(() => {
cy.login();
cy.visit('/');
});
beforeEach(() => {
cy.get('[data-test=test-burger]').click();
});
it('Tests table', () => {
cy.get('[data-test=invoices]').click();
cy.intercept('**/pragma**').as('getPragmaDocuments');
cy.wait('@getPragmaDocuments');
//....assertions here after API call is waited
});
});
However, it does not intercept the network request.
Error I get:
Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: getPragmaDocuments. No request ever occurred.Learn more
I am fetching data with a network call:
https://mydomain.xxx/third-party-service/pragma?perPage=15&page=1
Request Method: GET
Trying to intercept it with code:
// Overriden not to clear localStorage authentication tokens
const clear = Cypress.LocalStorage.clear;
Cypress.LocalStorage.clear = function(keys) {
if (keys) {
return;
}
};
context('Navigation', () => {
before(() => {
cy.login();
cy.visit('/');
});
beforeEach(() => {
cy.get('[data-test=test-burger]').click();
});
it('Tests table', () => {
cy.get('[data-test=invoices]').click();
cy.intercept('**/pragma**').as('getPragmaDocuments');
cy.wait('@getPragmaDocuments');
//....assertions here after API call is waited
});
});
However, it does not intercept the network request.
Error I get:
Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: getPragmaDocuments. No request ever occurred.Learn more
Share Improve this question edited Jan 14, 2021 at 15:03 Mindaugas Nakrošis asked Jan 14, 2021 at 14:22 Mindaugas NakrošisMindaugas Nakrošis 1052 silver badges6 bronze badges 2-
Testing with
Cypress.minimatch
as the docs suggest show that URL is matched, can you give a minimal reproducible example? – jonrsharpe Commented Jan 14, 2021 at 14:35 -
I tried testing with
Cypress.minimatch
. It returnstrue
. Edited my question including all code. – Mindaugas Nakrošis Commented Jan 14, 2021 at 15:01
1 Answer
Reset to default 7I see your problem, and I'm not sure why your "fix" worked, haha.
You need to start the cy.intercept()
before the click, like this:
cy.intercept('**/pragma**').as('getPragmaDocuments');
cy.get('[data-test=invoices]').click();
cy.wait('@getPragmaDocuments');