1919import com .microsoft .playwright .Locator ;
2020import com .microsoft .playwright .assertions .LocatorAssertions ;
2121
22+ import java .lang .reflect .Field ;
2223import java .util .ArrayList ;
2324import java .util .List ;
2425import java .util .regex .Pattern ;
@@ -39,6 +40,7 @@ private LocatorAssertionsImpl(Locator locator, boolean isNot) {
3940 public void containsText (String text , ContainsTextOptions options ) {
4041 ExpectedTextValue expected = new ExpectedTextValue ();
4142 expected .string = text ;
43+ expected .ignoreCase = shouldIgnoreCase (options );
4244 expected .matchSubstring = true ;
4345 expected .normalizeWhiteSpace = true ;
4446 expectImpl ("to.have.text" , expected , text , "Locator expected to contain text" , convertType (options , FrameExpectOptions .class ));
@@ -47,6 +49,7 @@ public void containsText(String text, ContainsTextOptions options) {
4749 @ Override
4850 public void containsText (Pattern pattern , ContainsTextOptions options ) {
4951 ExpectedTextValue expected = expectedRegex (pattern );
52+ expected .ignoreCase = shouldIgnoreCase (options );
5053 expected .matchSubstring = true ;
5154 expected .normalizeWhiteSpace = true ;
5255 expectImpl ("to.have.text" , expected , pattern , "Locator expected to contain regex" , convertType (options , FrameExpectOptions .class ));
@@ -58,6 +61,7 @@ public void containsText(String[] strings, ContainsTextOptions options) {
5861 for (String text : strings ) {
5962 ExpectedTextValue expected = new ExpectedTextValue ();
6063 expected .string = text ;
64+ expected .ignoreCase = shouldIgnoreCase (options );
6165 expected .matchSubstring = true ;
6266 expected .normalizeWhiteSpace = true ;
6367 list .add (expected );
@@ -70,6 +74,7 @@ public void containsText(Pattern[] patterns, ContainsTextOptions options) {
7074 List <ExpectedTextValue > list = new ArrayList <>();
7175 for (Pattern pattern : patterns ) {
7276 ExpectedTextValue expected = expectedRegex (pattern );
77+ expected .ignoreCase = shouldIgnoreCase (options );
7378 expected .matchSubstring = true ;
7479 expected .normalizeWhiteSpace = true ;
7580 list .add (expected );
@@ -203,6 +208,7 @@ public void hasJSProperty(String name, Object value, HasJSPropertyOptions option
203208 public void hasText (String text , HasTextOptions options ) {
204209 ExpectedTextValue expected = new ExpectedTextValue ();
205210 expected .string = text ;
211+ expected .ignoreCase = shouldIgnoreCase (options );
206212 expected .matchSubstring = false ;
207213 expected .normalizeWhiteSpace = true ;
208214 expectImpl ("to.have.text" , expected , text , "Locator expected to have text" , convertType (options , FrameExpectOptions .class ));
@@ -211,6 +217,7 @@ public void hasText(String text, HasTextOptions options) {
211217 @ Override
212218 public void hasText (Pattern pattern , HasTextOptions options ) {
213219 ExpectedTextValue expected = expectedRegex (pattern );
220+ expected .ignoreCase = shouldIgnoreCase (options );
214221 // Just match substring, same as containsText.
215222 expected .matchSubstring = true ;
216223 expected .normalizeWhiteSpace = true ;
@@ -223,6 +230,7 @@ public void hasText(String[] strings, HasTextOptions options) {
223230 for (String text : strings ) {
224231 ExpectedTextValue expected = new ExpectedTextValue ();
225232 expected .string = text ;
233+ expected .ignoreCase = shouldIgnoreCase (options );
226234 expected .matchSubstring = false ;
227235 expected .normalizeWhiteSpace = true ;
228236 list .add (expected );
@@ -235,6 +243,7 @@ public void hasText(Pattern[] patterns, HasTextOptions options) {
235243 List <ExpectedTextValue > list = new ArrayList <>();
236244 for (Pattern pattern : patterns ) {
237245 ExpectedTextValue expected = expectedRegex (pattern );
246+ expected .ignoreCase = shouldIgnoreCase (options );
238247 expected .matchSubstring = true ;
239248 expected .normalizeWhiteSpace = true ;
240249 list .add (expected );
@@ -327,5 +336,17 @@ private void expectTrue(String expression, String message, FrameExpectOptions op
327336 public LocatorAssertions not () {
328337 return new LocatorAssertionsImpl (actualLocator , !isNot );
329338 }
330- }
331339
340+ private static Boolean shouldIgnoreCase (Object options ) {
341+ if (options == null ) {
342+ return null ;
343+ }
344+ try {
345+ Field fromField = options .getClass ().getDeclaredField ("ignoreCase" );
346+ Object value = fromField .get (options );
347+ return (Boolean ) value ;
348+ } catch (NoSuchFieldException | IllegalAccessException e ) {
349+ return null ;
350+ }
351+ }
352+ }
0 commit comments