Skip to content

Navigation Menu

Sign in
Sign up

[Feature]: Numerical Comparison Assertions for hasCount #1875

Open

Description

🚀 Feature Request

Currently, assertThat(locator).hasCount(n) only supports strict equality. In many real-world testing scenarios, the exact number of elements is dynamic, and we only need to verify if the count meets a certain threshold (e.g., "at least one item is present" or "no more than 10 items").

Example

Proposed Methods: hasCountGreaterThan(int n), hasCountLessThan(int n), hasCountAtLeast(int n), hasCountAtMost(int n).

Motivation

Improved Readability: Replaces less intuitive workarounds like assertThat(locator).not().hasCount(0).
Native Polling: These checks would leverage Playwright’s built-in auto-waiting mechanism, making tests much more stable than manual polling loops.
Implementation: The implementation is straightforward as Playwright already has the infrastructure to retrieve element counts and poll for conditions. It simply requires adding comparison operators to the assertion logic.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      AltStyle によって変換されたページ (->オリジナル) /