2

How can I use regular expression with variable and substring in cypress.should to verify url by typescript? something like?

const string = /key_to_be_include\w+key1__`${v1}`,key2__`${v2}`/
//url: example.com/subdomain1/subdomainb/?key_xxxx=xxxxx&key_to_be_include=~alltextneed%25needtoBypass,key1__value1,key2__value2&...

const v1 = 'value1'
const v2 = 'value2'
const string = /key_to_be_include\w+key1__`${v1}`,key2__`${v2}`/
cy.url().should('contains', string);
zwessels
  • 617
  • 1
  • 10
  • 25
jacobcan118
  • 7,797
  • 12
  • 50
  • 95

1 Answers1

3

You can use contains() !

const string = /key_to_be_include\w+key1__`${v1}`,key2__`${v2}`/
cy.url().contains(string);

See here

Or try this or something like that :

const string = /key_to_be_include\w+key1__`${v1}`,key2__`${v2}`/
cy.url().should((url) => {
   expect(url).to.match(string)
}

See here

Jboucly
  • 720
  • 6
  • 17