0
votes

I have the following service calls on click of an element. I will need to intercept a request that does not have f0000000000 in the endpoint.

https://example.com/f0000000000/path1 - GET
https://example.com/f0000000000/path1 - GET
https://example.com/f0000000000/path1 - GET
https://example.com/f0000000000/path1 - GET
https://example.com/f0000000000/path1 - GET
https://example.com/f0000000000/path1 - GET
https://example.com/f2021090606/path1 - GET

How can we achieve this in cypress? Do we have any similar options?

 cy.intercept("GET", "**/NOT(f0000000000)/path1*").as('getForecast');
 cy.get('#some').click();
 cy.wait('@getForecast').its('response.statusCode').should('eq', 200)
});
1

1 Answers

1
votes

You can create a regex for this:

cy.intercept(/^(?!.*f0000000000\/path1).*$/gm).as('getForecast')

This will intercept the url which doesn't have f0000000000. This is a very basic regex, you can always enhance it as per your needs.

regex screenshot

You can also look into the Intercept Cypress Recipe.