Skip to content

[Feature]: Numerical Comparison Assertions for hasCount #1875

@gamestheory

Description

@gamestheory

🚀 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions