Add `Get Viewport Intersection Ratio` keyword to assert element visibility in the viewport
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 protobuf/playwright.proto、node/playwright-wrapper 和 Browser/keywords/getters.py 开始,追踪现有的元素请求、浏览器求值、断言轮询和数值验证。然后检查相关文档、生成的存根以及 atest 模式。完成的标准是:新 keyword 返回 IntersectionObserver 比率,支持列出的断言和重试行为,并覆盖不可见、部分可见和完全可见的元素。
由索引模型根据 Issue 内容生成。
描述
Use case
"Is this element actually visible in the viewport right now?" is a common check for lazy-loading images, sticky headers, infinite scrolling, cookie banners and scroll-into-view behavior. The library's element state keywords answer attached/visible in the CSS sense, but not whether the element is inside the current viewport, and certainly not how much of it is.
Playwright covers this with toBeInViewport({ ratio }), backed by IntersectionObserver. Browser library has no equivalent: users today must hand-roll an Evaluate JavaScript snippet with an IntersectionObserver, a Promise and manual polling — boilerplate that is easy to get wrong and gets copy-pasted between suites.
A float getter fits the assertion-engine model perfectly and is strictly more expressive than a boolean keyword: > 0 reproduces toBeInViewport, == 0 reproduces not.toBeInViewport, and >= 0.5 covers the ratio option that a boolean never could.
Proposed keyword / arguments
Get Viewport Intersection Ratio selector assertion_operator=None assertion_expected=None message=None
| Argument | Description |
|---|---|
selector |
Element selector, strict mode applies. |
assertion_operator / assertion_expected / message |
Standard assertion-engine arguments with auto-retry; numeric operators (==, >, >=, <, <=) apply. |
Returns a float between 0.0 (fully outside the viewport) and 1.0 (fully inside), the IntersectionObserver intersection ratio of the element versus the viewport.
*** Test Cases ***
Hero Is Visible After Load
New Page ${URL}
Get Viewport Intersection Ratio id=hero > 0
Call To Action Is At Least Half Visible
Scroll To Element id=cta
Get Viewport Intersection Ratio id=cta >= 0.5
Footer Is Not In Viewport Initially
Get Viewport Intersection Ratio css=footer == 0
${ratio} = Get Viewport Intersection Ratio id=banner
With Set Retry Assertions For, the assertion auto-retries — e.g. waiting until a lazily loaded element scrolls into view.
Playwright API
- expect(locator).toBeInViewport (including its
ratiooption)
The wrapper computes the same IntersectionObserver-based ratio Playwright's assertion uses.
Implementation notes
protobuf/playwright.proto: new selector-in / float-out RPC (or reuse an existing generic element-request shape).node/playwright-wrapper: resolve the locator and evaluate the intersection ratio via Playwright's injected utilities (same mechanism astoBeInViewport).Browser/keywords/getters.py: new keyword with@with_assertion_pollingandfloat_str_verify_assertion-style numeric assertion, tagsGetter, Assertion, PageContent.- Docs +
inv buildstub regen, atest with a long scrollable page (element out of view, partially in view, fully in view).
Backwards compatibility
Purely additive: a new keyword, no changes to any existing keyword.
- 主要语言
- Python
- 星标
- 662
- 派生
- 149
- 平均合并
- 6 小时 9 分钟
- 30 天内合并 PR
- 119
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MarketSquare/robotframework-browser 的其他 Issue
-
priority: high
难度 2/5 1-3 小时 新手友好度 75/100
MarketSquare/robotframework-browser#5306 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
MarketSquare/robotframework-browser#5153 ·
维护者通常 1 天内回复
-
Record Keyword: allow calling the recorded keyword in the current test case可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
MarketSquare/robotframework-browser#5513 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
MarketSquare/robotframework-browser#5503 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 78/100
MarketSquare/robotframework-browser#5502 ·
维护者通常 1 天内回复
查看 MarketSquare/robotframework-browser 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
Significant-Gravitas/AutoGPT#16733 ·
维护者通常 1 天内回复
-
changelog investigate
难度 1/5 1 小时以内 新手友好度 74/100
ramnes/notion-sdk-py#444 ·
-
documentation
难度 2/5 1-3 小时 新手友好度 69/100
Judgment-Pack/judgment-pack-spec#299 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
QuantConnect/Documentation#2858 ·
维护者通常 1 天内回复
-
good first issue
难度 2/5 1-3 小时 新手友好度 90/100
btclib-org/btclib#3047 ·
维护者通常 1 天内回复