Home > Enterprise >  Cypress, not able to intercept a call
Cypress, not able to intercept a call

Time:12-15

I am trying to intercept following call, that gets executed after click on SAVE operation. Its a POST 201 call. Sample request URL is : https://www.test.com/abc/def/ghi/jkl/1234/mno/pqr/stu/9876

where 1234 and 9876 are dynamic changing parts of url.

But, it is not getting intercepted, and I am getting below error:

Timed out retrying after 2000ms: cy.wait() timed out waiting 2000ms for the 1st request to the route: submissionCall. No request ever occurred

My test code is as follow:

cy.intercept(‘**def/ghi/jkl/‘ ’*’ ’/mno/pqr/stu/*’).as('@submissionCall’)
cy.get("button[class='btn save’]”).click();


cy.wait('@submissionCall').then((result) => {
    cy.log(response)
})

I have tried cy.intercept(‘**/mno/pqr/stu*’).as('callToIntercept’) but this also didnt work. Can someone help me by pointing, what I am doing wrong and what are the other best possible ways of intercepting same? Thanks.

CodePudding user response:

In intercept method; you should change the url part like this:

cy.intercept("**/mno/pqr/stu/**").as('callToIntercept');

Also you should edit last part like this:

cy.wait("@callToIntercept").then(({ response }) => {
  cy.log(response.body);
});

I hope that works!

  • Related