0

In case, if 'Panasonic' is entered directly in cy.intercept property, it works ok

cy.intercept('GET', '**/part-number/search?q=Panasonic**').as('getPNList')

but in case if this value added via variable into cy.intercept property, it doesn't work and cy.wait falls with timeout. What could be the reason?

let pnName = 'Panasonic'
    cy.intercept('GET', '**/part-number/search?q={@pnName}**').as('getPNList')
    cy.get('.select2-search__field').click().type(pnName)
    cy.wait('@getPNList').then((interception) => {
        expect(interception.response.statusCode).eq(200)
    })
TesterDick
  • 3,830
  • 5
  • 18
Michael
  • 35
  • 2

2 Answers2

1

Consider using the alternate format for query parameters

Ref: Matching with RouteMatcher

const pnName = 'Panasonic'

cy.intercept({
  pathname: '**/part-number/search',
  query: {
    q: pnName,
  },
}).as('getPNList')
0

I'm fairly certain your string interpolation is incorrect, and as such, your intercept is just looking for '**/part-number/search?q={@pnName}**' instead of replacing {@pnName} with the variable.

Try this instead:

cy.intercept('GET', `**/part-number/search?q=${pnName}**`).as('getPNList')

Check out more about string templates/string interpolation at MDN.

agoff
  • 5,818
  • 1
  • 7
  • 20