Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress intercept for dynamic pathParam in api and * functionality

I have few API's that i need to intercept.

'randomApi/import/entity'
'randomApi/import/entity/lead1/tabs'
'randomApi/import/entity/lead2/tabs'

lead1 and lead2 are values that are coming in the 1st api, so the values can be anything.

I was able to intercept the 1st one but not getting a proper solution for second and third one.

cy.intercept({
            pathname: '/randomApi/import/entity'
        }).as("entitiesData")

Also can anyone explain how does * and ** work in these

1. cy.intercept({ pathname: '/randomApi/import/entity*'}).as("entitiesData")
2. cy.intercept({ pathname: '/randomApi/import/entity**'}).as("entitiesData")
3. cy.intercept({ pathname: '/randomApi/import/entity/*'}).as("entitiesData")
4. cy.intercept({ pathname: '/randomApi/import/entity/**'}).as("entitiesData")
like image 483
Achal Utkarsh Avatar asked May 12 '26 10:05

Achal Utkarsh


1 Answers

The wildcards go between path separators. Try this:

cy.intercept('**/randomApi/import/entity/*/tabs', {}).as('leads')

cy.window().then(win => {
  win.fetch('https://my-host/randomApi/import/entity/lead1/tabs')
})

cy.wait('@leads')   // passes

Double stars asterisks are for multiple path sections, for example

cy.intercept('**/randomApi/import/entity/**/tabs', {}).as('leads')

cy.window().then(win => {
  win.fetch('https://my-host/randomApi/import/entity/leads/lead1/tabs')
})

cy.wait('@leads')   // passes

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!