From 04158db747d09f46a0d4dadcbeac2ea0cf50f657 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 28 Nov 2022 15:13:25 -0800 Subject: [PATCH] cherry-pick(#1131): fix: implement LocatorImpl.getByRole (#1132) Fixes https://github.com/microsoft/playwright-java/issues/1130 --- .../java/com/microsoft/playwright/impl/LocatorImpl.java | 2 +- .../java/com/microsoft/playwright/TestSelectorsGetBy.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java index c1d23c8b..2063436e 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java @@ -245,7 +245,7 @@ class LocatorImpl implements Locator { @Override public Locator getByRole(AriaRole role, GetByRoleOptions options) { - return null; + return locator(getByRoleSelector(role, options)); } @Override diff --git a/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java b/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java index eb2706ac..d086c2a5 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java @@ -171,4 +171,12 @@ public class TestSelectorsGetBy extends TestBase { asList("he llo 56"), page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName(" he \n llo 56 ").setExact(true)).evaluateAll("els => els.map(e => e.outerHTML)")); } + + @Test + void locatorGetByRole() { + page.setContent("
"); + assertEquals( + asList(""), + page.locator("div").getByRole(AriaRole.BUTTON).evaluateAll("els => els.map(e => e.outerHTML)")); + } }