During the internet growth course of, generally values in HTML have inconsistent capitalization, which is able to result in flaky exams. Sometimes, the exams will search for lowercase textual content, however the precise textual content worth can be in uppercase. One of the widespread practices to enhance such a flaky take a look at is to make the textual content in case-insensitive means. In this put up, I’ll present you 4 other ways to make the textual content case insensitive.
The first method is to make use of Cypress built-in function to disregard case sensitivity. In this method, the take a look at will go even when the textual content worth in HTML is anticipated textual content
as an alternative of Expected Text
. Cypress will ignore the uppercase and solely verify the precise textual content content material. You can activate and off this function by altering the worth of matchCase
from false
to true
.
The second method is to make use of Regex to disregard case sensitivity. In this method, the i flag signifies that case ought to be ignored whereas making an attempt a match in a string.
The third method is to vary the string to lowercase first earlier than making an attempt a match. In this method, the .toLowerCase();
operate will convert all the alphabetic characters in a string to a lowercase string.
The fourth method is changing the characters in a string to lowercase by utilizing an ASCII desk. In the desk beneath, you will notice that #65 to #90 signify uppercase A to Z , whereas #97 to #122 current lowercase a to z. As such, if a personality has a price between #65 to #90, we all know this character is in higher case. By including 32 to that character’s quantity, we are able to convert that character to lowercase.