Build `Get Aria Snapshot return_type=parsed` on Playwright's `ariaSnapshotJSON`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- grpc, playwright, python, typescript
Hướng nghiên cứu
Read Browser/keywords/getters.py and node/playwright-wrapper/getters.ts first, then review the AriaSnapShot RPC in protobuf/playwright.proto and its registration in grpc-service.ts. Implement the JSON RPC and map its nodes into the documented DotDict shape; update the parser unit tests and add a backslash case to the acceptance tests. Done means the parsed shape and options remain compatible, with the documented text value difference covered in release notes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Use case
Get Aria Snapshot return_type=parsed (added in #5101, released in v20.4.0) returns the snapshot as a tree of nodes with role, name, text, props and children, so tests can assert on single nodes:
${nodes} = Get Aria Snapshot h1 parsed
Should Be Equal ${nodes}[0][props][level] ${1}
The library builds that tree itself: it loads Playwright's YAML and splits each line label with regular expressions (Browser/utils/aria_snapshot.py). The YAML is made for humans and for toMatchAriaSnapshot, not for parsing, and the parser has to guess at Playwright's quoting rules. One case it gets wrong today, checked with Playwright 1.65.0 and Chromium:
- An accessible name with a backslash. Playwright writes
heading "A\\B"and the parser unescapes only\", sonamecomes back asA\\Binstead ofA\B.
Playwright 1.63 added locator.ariaSnapshotJSON(), which returns the same tree as a JSON value. Using it removes the parsing, and with it this class of bug.
Proposed keyword / arguments
No new keyword and no new argument. return_type=parsed keeps its documented shape (role, name, text, props, children on every node, DotDict access), but gets the tree from ariaSnapshotJSON instead of parsing YAML. yaml and dict stay on ariaSnapshot() as today. mode, depth and boxes apply to parsed as they do now; ariaSnapshotJSON takes the same three options.
*** Test Cases ***
Check Login Form Through Aria Tree
${nodes} = Get Aria Snapshot id=login parsed
Should Be Equal ${nodes}[0][role] textbox
Should Be Equal ${nodes}[0][props][placeholder] User name
Get Aria Snapshot css=select parsed validate value[0].children[0].props.selected == True
The mapping from a JSON node to a parsed node:
| JSON node | parsed node |
|---|---|
role |
role |
name |
name, None when absent |
text |
text, None when absent |
children |
children, each mapped the same way, [] when absent |
every other key (level, checked, selected, url, placeholder, ref, cursor, box, ...) |
a key in props |
Keeping the fixed keys, instead of returning the JSON as is, matters for assertions: ${node.name} and ${node}[children] work on every node without a missing-key error, and existing tests keep passing.
A separate return_type=json with Playwright's raw shape was considered. It would give users two tree formats with almost the same content and different keys, so it is not proposed.
Playwright API
locator.ariaSnapshotJSON({ mode, depth, boxes, timeout }), since 1.63 (absent from types.d.ts of 1.62.0, present in 1.63.0). page.ariaSnapshotJSON() exists too, but the keyword always works on a locator. The docs list the node properties: role ("text" for a text fragment), name, text ("Text content of the element when it is the only child, or the content of a static text fragment"), children, state flags checked, disabled, expanded, active, invalid, level, pressed, selected, other properties such as url and placeholder, and ref, cursor (AI mode) and box (boxes: true, with x, y, width, height).
Observed with Playwright 1.65.0 and Chromium:
{"role":"heading","name":"Login Page","level":1}; keys that have no value are left out, notnull.{"role":"link","name":"Text bold","url":"/a"}; the link target is a property, where the YAML has a/urlchild that our parser hoists intoprops.boxes: truegives"box":{"x":8,"y":8,"width":1264,"height":37}, integers, the same keys and values as the YAML[box=...].mode: "ai"adds"ref":"e1".
Implementation notes
All references are to upstream main (5e350998).
- Proto:
ariaSnapshot()andariaSnapshotJSON()are two Playwright calls, so add a second rpc next torpc AriaSnapShot(Request.AriaSnapShot) returns (Response.String)(protobuf/playwright.proto:561):rpc AriaSnapshotJson(Request.AriaSnapShot) returns (Response.Json).Request.AriaSnapShot(:20-26) already carrieslocator,strict,mode,depthandboxes. - Node:
node/playwright-wrapper/getters.ts:41-52getAriaSnapshotresolves the locator withfindLocatorand builds options withariaSnapshotOptions(:27-39). The new handler does the same and callslocator.ariaSnapshotJSON(options), returning the value withjsonResponse. Register it ingrpc-service.tsnext toariaSnapShot = this.wrappingStatePage(getters.getAriaSnapshot)(:294). - Python:
Browser/keywords/getters.py:67-153get_aria_snapshotcalls the new rpc whenreturn_type is AriaSnapshotReturnType.parsed(:143-144today callsparse_aria_snapshot), and maps the result toDotDictnodes as in the table above.Browser/utils/aria_snapshot.py(the YAML label parser) is then no longer needed and can be replaced by the JSON-to-node mapping. AriaSnapshotReturnTypedocs (Browser/utils/data_types.py:185-405): theparsedsection explains that/url"is an annotation in Playwright ... and therefore becomes theurlproperty". That stays true; the wording about splitting YAML annotations changes.- Tests: the
parsedacceptance tests inatest/test/02_Content_Keywords/aria_snapshot.robot:101-162describe the shape and should pass unchanged; add a name with a backslash.utest/test_aria_snapshot_parser.pytests the YAML parser; it becomes a test of the JSON-to-node mapping. - To check during implementation: the docstring says
mode=ai"does not wait for a matching element, but fails immediately" (getters.py:103-106). ConfirmariaSnapshotJSONbehaves the same, or document the difference.
Backwards compatibility
yaml and dict do not change. parsed keeps its keys and access style, with these differences in values:
- Names and texts with backslashes are correct, where today they keep the YAML escaping.
- An element with both a name and its own text content: the YAML parser turns a
- text:line under a node into a child node, while the JSON may put it in the node'stext. With Playwright 1.65.0,<input aria-label="N" placeholder="ph" value="v">gives{"role":"textbox","name":"N","placeholder":"ph","text":"v"}in JSON, and today'sparsedgives a textbox with atextchild nodev. Tests that read such a value throughchildrenneed to readtextinstead. This should be called out in the release notes.
- Ngôn ngữ chính
- Python
- Star
- 662
- Fork
- 149
- Merge trung bình
- 6 giờ 13 phút
- Pull request đã merge (30 ngày)
- 121
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MarketSquare/robotframework-browser
-
priority: high
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
MarketSquare/robotframework-browser#5306 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MarketSquare/robotframework-browser#5153 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 78/100
MarketSquare/robotframework-browser#5502 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
MarketSquare/robotframework-browser#5501 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Accept a list of credentials in `httpCredentials` of `New Context` and `New Persistent Context`Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
MarketSquare/robotframework-browser#5500 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MarketSquare/robotframework-browser
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
igormcsouza/tether#278 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
aws-samples/sample-per-model-bedrock#803 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
huggingface/accelerate#4511 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày