Add `Get Viewport Intersection Ratio` keyword to assert element visibility in the viewport

未关闭
#5,124 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
testing

调研方向

从 protobuf/playwright.proto、node/playwright-wrapper 和 Browser/keywords/getters.py 开始,追踪现有的元素请求、浏览器求值、断言轮询和数值验证。然后检查相关文档、生成的存根以及 atest 模式。完成的标准是:新 keyword 返回 IntersectionObserver 比率,支持列出的断言和重试行为,并覆盖不可见、部分可见和完全可见的元素。

由索引模型根据 Issue 内容生成。

描述

enhancement

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

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 as toBeInViewport).
  • Browser/keywords/getters.py: new keyword with @with_assertion_polling and float_str_verify_assertion-style numeric assertion, tags Getter, Assertion, PageContent.
  • Docs + inv build stub 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MarketSquare/robotframework-browser 的其他 Issue

查看 MarketSquare/robotframework-browser 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。