Home > Software engineering >  cy.wrap().its()... doesn't work when the value in .its() contains a period
cy.wrap().its()... doesn't work when the value in .its() contains a period

Time:11-23

I am looking to extract a URL parameter from the current URL I'm testing with Cypress. I was able to basically get the answer from Cypress error message

I saw there was a similar error with Cypress's .get() function back in 2018.

I am new to both javascript and Cypress, so I hope it's just a weird easy thing I'm overlooking. Any advice or educated guesses are greatly welcome at this point!

Thank you.

CodePudding user response:

.its() is just a shorthand for property extraction. Since it fails with the period, you could instead use bracket notation in a .then().

cy.wrap(paramObj)
  .then(paramObj => paramObj['timeline.ws'])

or just

cy.wrap(paramObj['timeline.ws'])

Playing around with the URL constructor

const urlString = 'http://example.com?timeline.ws=3600000&timeline.to&timeline.fm&timeline.ar=false'
const url = new URL(urlString)

cy.wrap(url.searchParams.get('timeline.ws'))
  .should('eq', '3600000')

cy.wrap(url.searchParams.get('timeline.to'))
  .should('be.empty')

cy.wrap(url.searchParams.get('timeline.ar'))
  .should('eq', 'false')
  • Related