|
| 1 | +package com.microsoft.playwright; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import java.util.regex.Pattern; |
| 6 | + |
| 7 | +import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; |
| 8 | +import static java.util.Arrays.asList; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | + |
| 11 | +public class TestSelectorsText extends TestBase { |
| 12 | + @Test |
| 13 | + void hasTextAndInternalTextShouldMatchFullNodeTextInStrictMode() { |
| 14 | + page.setContent("<div id=div1>hello<span>world</span></div>\n" + |
| 15 | + " <div id=div2>hello</div>"); |
| 16 | + assertThat(page.getByText("helloworld", new Page.GetByTextOptions().setExact(true))).hasId("div1"); |
| 17 | + assertThat(page.getByText("hello", new Page.GetByTextOptions().setExact(true))).hasId("div2"); |
| 18 | + assertThat(page.locator("div", new Page.LocatorOptions().setHasText(Pattern.compile("^helloworld$")))).hasId("div1"); |
| 19 | + assertThat(page.locator("div", new Page.LocatorOptions().setHasText(Pattern.compile("^hello$")))).hasId("div2"); |
| 20 | + |
| 21 | + page.setContent("<div id=div1><span id=span1>hello</span>world</div>\n" + |
| 22 | + " <div id=div2><span id=span2>hello</span></div>"); |
| 23 | + assertThat(page.getByText("helloworld", new Page.GetByTextOptions().setExact(true))).hasId("div1"); |
| 24 | + assertEquals(asList("span1", "span2"), page.getByText("hello", new Page.GetByTextOptions().setExact(true)).evaluateAll("els => els.map(e => e.id)")); |
| 25 | + assertThat(page.locator("div", new Page.LocatorOptions().setHasText(Pattern.compile("^helloworld$")))).hasId("div1"); |
| 26 | + assertThat(page.locator("div", new Page.LocatorOptions().setHasText(Pattern.compile("^hello$")))).hasId("div2"); |
| 27 | + } |
| 28 | +} |
0 commit comments