[java] Implement accessibility snapshots (ADR 18205)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java
調査の方向性
Start by reading ADR 18205 and the tracker issue #18345, then compare the Python issue #18307 and JavaScript issue #18308 for reference behavior. The plan identifies Java APIs, remote internals, the accessibility snapshot atom, and tests under java/test/org/openqa/selenium; implementation spans these areas and requires both BiDi and Classic browser paths. Done means the proposed API and behavior are implemented and the listed corpus and browser cases pass.
索引モデルが issue の本文から書いたものです。
説明
Part of #18345, the ADR 18205 tracker. This is the Java plan we will implement if people are happy with it. Please comment here before the PR goes up.
Python (#18307) and JavaScript (#18308) set the reference behaviour, listed in the tracker. This issue only covers how Java does it.
Public API (org.openqa.selenium)
This is a role interface, like TakesScreenshot. It is implemented by RemoteWebDriver and RemoteWebElement, so ChromeDriver, FirefoxDriver and the others get it without the Augmenter. Nothing is added to WebDriver or WebElement, so other implementations do not break.
public interface TakesAccessibilitySnapshot {
/** Snapshot with the default options (pruned). */
default AccessibilityNode getAccessibilitySnapshot() {
return getAccessibilitySnapshot(AccessibilitySnapshotOptions.defaults());
}
/**
* @throws StaleElementReferenceException if called on an element that is no longer attached
*/
AccessibilityNode getAccessibilitySnapshot(AccessibilitySnapshotOptions options);
}
Options are an immutable value with withers, following ClientConfig. There is no setter-style builder, so a shared default instance can never be changed:
AccessibilitySnapshotOptions.defaults() // interestingOnly = true
.withInterestingOnly(false);
The node is a final class rather than a record, because we compile with --release 11. It is immutable, its collections are unmodifiable, and it has getters in the usual Selenium Java style:
public final class AccessibilityNode {
public String getRole(); // "text" for text leaves, "iframe" for frames
public String getName(); // "" when none
public String getDescription(); // "" when none
public Optional<String> getValue(); // textbox, searchbox, combobox, range
public Optional<String> getUrl(); // links with an href
public Map<String, Object> getStates(); // Boolean, Integer, or the String "mixed"; unmodifiable, ordered
public Optional<WebElement> getElement(); // empty for text leaves and generated content
public List<AccessibilityNode> getChildren(); // unmodifiable, [] for leaves
public Stream<AccessibilityNode> stream(); // this node and its descendants, depth-first
public String toText(); // ADR §1 text form
@Override public String toString(); // same as toText()
}
The optional fields use Optional instead of @Nullable because users read them in chains such as node.getElement().ifPresent(WebElement::click). stream() is an extra for Java. It is additive under the record's compatibility rule, and it covers the most common thing people will do with the tree:
TakesAccessibilitySnapshot snapshots = (TakesAccessibilitySnapshot) driver;
AccessibilityNode tree = snapshots.getAccessibilitySnapshot();
System.out.println(tree.toText());
tree.stream()
.filter(n -> n.getRole().equals("button") && n.getName().equals("Submit"))
.findFirst()
.flatMap(AccessibilityNode::getElement)
.ifPresent(WebElement::click);
AccessibilityNode form =
((TakesAccessibilitySnapshot) driver.findElement(By.id("login")))
.getAccessibilitySnapshot(AccessibilitySnapshotOptions.defaults().withInterestingOnly(false));
Internals (org.openqa.selenium.remote, package-private)
AccessibilitySnapshotteris created lazily, one perRemoteWebDriver.RemoteWebElementdelegates to its parent's instance.- BiDi path. Used when the
webSocketUrlcapability is present. Rawscript.callFunctionandbrowsingContext.getTreego through the driver'sHasBiDi.getHandle(), wrapped in a small internalorg.openqa.selenium.bidi.Modulesubclass. It does not use the deprecatedgetBiDi()/maybeGetBiDi()(ADR 17670) or the publicbidi.module.Script, so taking a snapshot never warns about calls the user did not make. - Classic path. Uses
executeScriptwith the atom source. Frames are reached withswitchTo().frame(WebElement)andswitchTo().parentFrame()in atry/finally, so the current context is restored even if a frame throws. AccessibilityNode.fromWire(...)(package-private) builds the tree from the atom's JSON withorg.openqa.selenium.json.Json. It maps element indexes toRemoteWebElementthrough the driver's element factory.- Frames that cannot be reached are logged at
Level.FINEand become childlessiframenodes. Stale roots throwStaleElementReferenceException. - Atom: a
copy_fileof//javascript/atoms/fragments:accessibility-snapshot-wire-typescript.jsinto//java/src/org/openqa/selenium/remoteresources. It is read once withRead.resourceAsString.
Decorators and wrappers
WebDriverDecorator/EventFiringDecoratorproxy every interface the decorated object implements, so the new interface passes through. A test will check this, including thatgetElement()on a decorated driver returns a decorated element.RemoteWebDriveron Grid needs nothing extra. It works with the Classic path whatever the node is, and with BiDi when the Grid gives awebSocketUrl.
Tests
java/test/org/openqa/selenium/AccessibilityNodeTest(small, no browser): checkstoText()against every corpus.json/.txtpair, plus escaping and state order.java/test/org/openqa/selenium/AccessibilitySnapshotTest(JupiterTestBase,@ParameterizedTestoverindex.json): for each page, pruned and unpruned, compares against the corpus, preferring.webkitfiles on Safari. It also ports the other cases from the Python suite: rooted at the switched frame, context unchanged, frames stitched, subtree inside a frame, stale and detached roots, usable element references, a snapshot is a copy.- Both paths need covering.
testing/drivers/Browser.javaalways callsenableBiDi(), so the suite needs a Classic variant that leaves BiDi off (JavaScript did the equivalent in #18308 by honouringwebSocketUrl: false). This follows the repo's preference for real browsers over mocks.
Not changing
Nothing is deprecated, because this replaces no existing call. There is no CDP path.
Generated by Claude Code
- 主要言語
- Java
- スター
- 34.6k
- フォーク
- 8.7k
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 107
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SeleniumHQ/selenium のほかの issue
-
C-py I-defect
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
SeleniumHQ/selenium#18438 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
SeleniumHQ/selenium#18323 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
B-build C-py I-enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
SeleniumHQ/selenium#18435 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[🐛 Bug]: Bindings change the user's options when Selenium Manager supplies a browser対応中かも @Liz-Lian が 2 日前に担当しました。 オープンC-dotnet C-java C-nodejs C-py C-rb I-defect
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
SeleniumHQ/selenium#18428 ·
メンテナーはふだん 1 日以内に返信
-
[🐛 Bug]: [rust] Selenium Manager can return a browser from the cache before it finishes copying対応中かも @Liz-Lian が 2 日前に担当しました。 オープンC-rust I-defect
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
SeleniumHQ/selenium#18427 ·
メンテナーはふだん 1 日以内に返信
SeleniumHQ/selenium の issue をすべて見る
似ている issue
-
area-integrations
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
? - Needs Triage bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NVIDIA/cudf-spark-jni#5598 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
oracle/graalvm-reachability-metadata#12264 ·
メンテナーはふだん 1 日以内に返信
-
[source-facebook-pages] post stream never returns attachments.media_type対応中かも @v-k-data が今日担当しました。 オープンarea/connectors needs-triage type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
[BUG] AppSync: GetIntrospectionSchema wraps the schema in JSON instead of returning the raw SDL bodyオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
floci-io/floci#10107 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信