Skip to content

Commit abf245c

Browse files
authored
feat: implement Locator.filter (#925)
1 parent 10592ce commit abf245c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void fill(String value, FillOptions options) {
204204

205205
@Override
206206
public Locator filter(FilterOptions options) {
207-
return null;
207+
return new LocatorImpl(frame, selector, convertType(options,LocatorOptions.class));
208208
}
209209

210210
@Override

playwright/src/test/java/com/microsoft/playwright/TestPageLocatorQuery.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,19 @@ void shouldSupportHasLocator() {
134134
assertThat(page.locator("div", new Page.LocatorOptions()
135135
.setHas(page.locator("span")).setHasText("wor"))).hasCount(1);
136136
}
137+
138+
@Test
139+
void shouldSupportLocatorFilter() {
140+
page.setContent("<section><div><span>hello</span></div><div><span>world</span></div></section>");
141+
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHasText("hello"))).hasCount(1);
142+
assertThat(page.locator("div", new Page.LocatorOptions().setHasText("hello")).filter(new Locator.FilterOptions().setHasText("hello"))).hasCount(1);
143+
assertThat(page.locator("div", new Page.LocatorOptions().setHasText("hello")).filter(new Locator.FilterOptions().setHasText("world"))).hasCount(0);
144+
assertThat(page.locator("section", new Page.LocatorOptions().setHasText("hello")).filter(new Locator.FilterOptions().setHasText("world"))).hasCount(1);
145+
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHasText("hello")).locator("span")).hasCount(1);
146+
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHas(page.locator("span", new Page.LocatorOptions().setHasText("world"))))).hasCount(1);
147+
assertThat(page.locator("div").filter(new Locator.FilterOptions().setHas(page.locator("span")))).hasCount(2);
148+
assertThat(page.locator("div").filter(new Locator.FilterOptions()
149+
.setHas(page.locator("span"))
150+
.setHasText("world"))).hasCount(1);
151+
}
137152
}

0 commit comments

Comments
 (0)