cy.wait('@alias') timeouts when I use it with cy.intercept()

Viewed 29

I have registered cy.intercept() way before the API call. When I wait using cy.wait() on that API, It never gets stubbed and then I get timeout error. Api calls

In the above image we can see, log intercept, then waiting for the API, even after the api is called after some time, wait gets failed.

Cypress Version - 10.6.0

1 Answers

Try adding wildcard characters before the url, same as you have for the @records intercept.

cy.intercept('**/com.bmc.dsm.item-applications:Default Calendar*').as('designConfig')

If you have trouble finding the correct minimatch expression, try using javascript to assign the alias.

cy.intercept('*', (req) => {   // "*" catches everything
  
  // Now can use javascript to check if the URL has the string you want
  // and assign the alias dynamically

  // Don't use any wildcards here, just look for characters in the URL
  // that uniquely identify the `xhr` you want

  if (req.url.includes('com.bmc.dsm.item-applications:Default Calendar')) {
    req.alias = 'designConfig';  
  }
})
Related