diff --git a/playwright/src/main/java/com/microsoft/playwright/Accessibility.java b/playwright/src/main/java/com/microsoft/playwright/Accessibility.java
deleted file mode 100644
index f24c476e..00000000
--- a/playwright/src/main/java/com/microsoft/playwright/Accessibility.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.microsoft.playwright;
-
-import java.util.*;
-
-/**
- * The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
- * assistive technology such as screen readers or switches.
- *
- *
Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might
- * have wildly different output.
- *
- *
Rendering engines of Chromium, Firefox and Webkit have a concept of "accessibility tree", which is then translated into
- * different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
- *
- *
Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific
- * AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing
- * only the "interesting" nodes of the tree.
- */
-public interface Accessibility {
- class SnapshotOptions {
- /**
- * Prune uninteresting nodes from the tree. Defaults to {@code true}.
- */
- public Boolean interestingOnly;
- /**
- * The root DOM element for the snapshot. Defaults to the whole page.
- */
- public ElementHandle root;
-
- public SnapshotOptions withInterestingOnly(boolean interestingOnly) {
- this.interestingOnly = interestingOnly;
- return this;
- }
- public SnapshotOptions withRoot(ElementHandle root) {
- this.root = root;
- return this;
- }
- }
- /**
- * Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
- * page.
- *
- *
NOTE: The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Playwright
- * will discard them as well for an easier to process tree, unless {@code interestingOnly} is set to {@code false}.
- *
- *
An example of dumping the entire accessibility tree:
- *
- */
- default String snapshot() {
- return snapshot(null);
- }
- /**
- * Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
- * page.
- *
- *
NOTE: The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Playwright
- * will discard them as well for an easier to process tree, unless {@code interestingOnly} is set to {@code false}.
- *
- *
An example of dumping the entire accessibility tree:
- *
- */
- String snapshot(SnapshotOptions options);
-}
-
diff --git a/playwright/src/main/java/com/microsoft/playwright/Page.java b/playwright/src/main/java/com/microsoft/playwright/Page.java
index 4208e290..7746244a 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Page.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Page.java
@@ -1601,7 +1601,6 @@ public interface Page extends AutoCloseable {
return this;
}
}
- Accessibility accessibility();
/**
* Adds a script which would be evaluated in one of the following scenarios:
*
NOTE: This does not contain ServiceWorkers
*/
List workers();
+ /**
+ * Adds one-off {@code Dialog} handler. The handler will be removed immediately after next {@code Dialog} is created.
+ *
{@code
+ * page.onceDialog(dialog -> {
+ * dialog.accept("foo");
+ * });
+ *
+ * // prints 'foo'
+ * System.out.println(page.evaluate("prompt('Enter string:')"));
+ *
+ * // prints 'null' as the dialog will be auto-dismissed because there are no handlers.
+ * System.out.println(page.evaluate("prompt('Enter string:')"));
+ * }
+ *
+ *
This code above is equivalent to:
+ *
{@code
+ * Consumer
+ *
+ * @param handler Receives the {@code Dialog} object, it **must** either {@link Dialog#accept Dialog.accept()} or {@link Dialog#dismiss
+ * Dialog.dismiss()} the dialog - otherwise the page will freeze waiting for the
+ * dialog, and actions like click will never finish.
+ */
+ void onceDialog(Consumer handler);
}
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/AccessibilityImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/AccessibilityImpl.java
deleted file mode 100644
index d412857d..00000000
--- a/playwright/src/main/java/com/microsoft/playwright/impl/AccessibilityImpl.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.microsoft.playwright.impl;
-
-import com.google.gson.JsonObject;
-import com.microsoft.playwright.Accessibility;
-
-import static com.microsoft.playwright.impl.Serialization.gson;
-
-class AccessibilityImpl implements Accessibility {
- private final PageImpl page;
-
- AccessibilityImpl(PageImpl page) {
- this.page = page;
- }
-
- @Override
- public String snapshot(SnapshotOptions options) {
- return page.withLogging("Accessibility.snapshot", () -> snapshotImpl(options));
- }
-
- private String snapshotImpl(SnapshotOptions options) {
- if (options == null) {
- options = new SnapshotOptions();
- }
- JsonObject params = gson().toJsonTree(options).getAsJsonObject();
- JsonObject json = page.sendMessage("accessibilitySnapshot", params).getAsJsonObject();
- if (!json.has("rootAXNode")) {
- return null;
- }
- return json.getAsJsonObject("rootAXNode").toString();
- }
-}
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java
index c2b1fed8..ef64f7b5 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java
@@ -43,7 +43,6 @@ public class PageImpl extends ChannelOwner implements Page {
private final FrameImpl mainFrame;
private final KeyboardImpl keyboard;
private final MouseImpl mouse;
- private final AccessibilityImpl accessibility;
private final TouchscreenImpl touchscreen;
private ViewportSize viewport;
private final Router routes = new Router();
@@ -106,7 +105,6 @@ public class PageImpl extends ChannelOwner implements Page {
keyboard = new KeyboardImpl(this);
mouse = new MouseImpl(this);
touchscreen = new TouchscreenImpl(this);
- accessibility = new AccessibilityImpl(this);
frames.add(mainFrame);
timeoutSettings = new TimeoutSettings(browserContext.timeoutSettings);
}
@@ -544,11 +542,6 @@ public class PageImpl extends ChannelOwner implements Page {
return withLogging("Page.evalOnSelectorAll", () -> mainFrame.evalOnSelectorAllImpl(selector, pageFunction, arg));
}
- @Override
- public Accessibility accessibility() {
- return accessibility;
- }
-
@Override
public void addInitScript(String script) {
withLogging("Page.addInitScript", () -> addInitScriptImpl(script));
@@ -1327,4 +1320,18 @@ public class PageImpl extends ChannelOwner implements Page {
public List workers() {
return new ArrayList<>(workers);
}
+
+ @Override
+ public void onceDialog(Consumer handler) {
+ onDialog(new Consumer() {
+ @Override
+ public void accept(Dialog dialog) {
+ try {
+ handler.accept(dialog);
+ } finally {
+ offDialog(this);
+ }
+ }
+ });
+ }
}
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestAccessibility.java b/playwright/src/test/java/com/microsoft/playwright/TestAccessibility.java
deleted file mode 100644
index 833b7f10..00000000
--- a/playwright/src/test/java/com/microsoft/playwright/TestAccessibility.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.microsoft.playwright;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledIf;
-import org.junit.jupiter.api.condition.EnabledIf;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-public class TestAccessibility extends TestBase {
- static void assertNodeEquals(String expected, String actual) {
- JsonElement actualJson = new Gson().fromJson(actual, JsonElement.class);
- assertNodeEquals(expected, actualJson);
- }
-
- static void assertNodeEquals(String expected, JsonElement actualJson) {
- assertEquals(JsonParser.parseString(expected), actualJson);
- }
-
- @Test
- void shouldWork() {
- page.setContent("\n" +
- " Accessibility Test\n" +
- "\n" +
- "\n" +
- "