I am trying to match part of a url http://www.mywebsite.com/get-stuff in cypress and haven't been able to figure out how to code a regex match.
I tried: cy.contains('http.*get-stuff') and don't find a match for do some things
Cypress can validate the text on an element with the help of jQuery text() method. This method shall help us to fetch the text content on the selected element. We can also put assertions on the text content of the element. cy.
contains() is chained off of a command that yielded the <button> , Cypress will look inside of the <button> for the new content. In other words, Cypress will look inside of the <button> containing "Delete User" for the content: "Yes, Delete!", which is not what we intended.
\d for single or multiple digit numbers To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.
If you are trying to see if some content on your website has the text http://www.mywebsite.com/get-stuff
using regex, you will need to pass in a valid Regular Expression. Your argument is attempting to match using a glob expression.
If you are trying to see if the url of your website is navigated to http://www.mywebsite.com/get-stuff
, you likely want to write an assertion off of the cy.url()
command like so:
cy.url().should('match', /myregexp/)
I know it's been quite a long, but for those who are still looking for a solution ( just like me ), you can make use of cy.url().should('contain', /regex/)
if the accepted solution didn't work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With