-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce non case sensitive matching for cy.contains() #2785
Comments
It would be the same problem in regards to things like If you know of any DOM methods that return the text with this kind of CSS styling factored in, let us know. |
Yeah it's a tough one. A possible algorithm for case-sensitivity using
But it's less efficient because it requires multiple traversals of the DOM so it could potentially be opt-in? |
Introducing this into the default cy.contains() would also make it impossible to then test actually capitalization within an application. If my team wanted our content to move from Capitalized to Sentence Case, for example, there wouldn't be a way to test that those changes were put in correctly. If this were even implemented, I would recommend it as a separate argument to be passed like in 'search' in your IDE - to |
I actually might prefer to have |
I'd also need case insensitive contains method, maybe add some options to it? |
I solved it using a regex with |
please add an argument to make cy.contains optionally work in a non case-sensitive way using the regex works but when combined with variables requires you to add a lot of extra code.. it would be much better to have it built-in |
my solution is to create a helpers class and then import it inside my tests like this: helpers.js export default class Helpers {
static caseInsensitive(str) {
// escape special characters
this.input = str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
return new RegExp(`${this.input}`, 'i');
}
} spec.js import helpers from '../support/helpers';
...
cy.get('[data-cy="form-errors"]').contains(helpers.caseInsensitive(variables.strings.en.general.oops)); |
The code for this is done in cypress-io/cypress#5653, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
cy.contains('Capital Sentence')
does not match<span class="capitalize"> capital sentence </span>
where:
Is this expected?
Desired behavior:
I assumed it would match because that's what the user sees. However the underlying text in the DOM is indeed
capital sentence
.Steps to reproduce:
Versions
Cypress: 3.0.1
Chrome, Mac OS Mojave
The text was updated successfully, but these errors were encountered: