Cypress Intercept Glob Pattern Matching URLs

Profile picture for user arilio666

The problem in matching a URL is that when we provide an exact URL, this becomes too restrictive. What if we want to match with different hosts? This article will show how we can match URLs using the glob pattern.?

cy.intercept('https://programsbuzz.com/user/login')
  • It only matches with the URL provided and cannot be matched with any other hosts with this specified URL.
  • This is the restrictive problem when we face a restricted URL.

When it comes to GLOB pattern matching, it provides certain flexibility.

cy.intercept('/cypress')

Providing a URL like this will match any URL we intercept matching with '/cypress' globally.

cy.intercept('/users?_limit=+(3|5)')

This means limiting the user's endpoint to fetch limit to 3 or 5.