Skip to content

A failure names getByRole("heading") for getByRole('heading', { level: 2 }), so the message points at the wrong element #2490

Backlog

Description

@gagarinyury

What happened

A locator's description drops level, the state options (checked, disabled, selected, expanded, pressed) and exact: false. The description is what a failure prints, and what step labels and reports show. So a locator that misses because of one of those options reads as one that should match:

locator: getByRole("heading")
expected: visible
observed: no node (match count 0)

The page has an <h1>; the test asked for level: 2. getByRole('checkbox', { name: 'Agree', checked: true }) on an unchecked box prints getByRole("checkbox", name: "Agree") the same way.

describeExpression in packages/core/src/locator/expression.ts prints a query's value, name and visible only.

Reproduction

https://github.com/gagarinyury/e2e-repros/tree/main/locator-description

Steps to reproduce

  1. npm install in the repo root, then cd locator-description
  2. npx e2e run
  3. Both tests fail, as they should. The messages print getByRole("checkbox", name: "Agree") and getByRole("heading").

Expected: getByRole("checkbox", name: "Agree", checked: true) and getByRole("heading", level: 2).

Versions

e2e 0.25.0, @e2e-dev/web 0.17.0, Node 25.2.1, macOS. Also on main at 7c1b2b2.

Engine

not engine specific

Anything else

I have a fix with a unit test and can send the PR.

Activity

  1. okwasniewski commented on Nov 29, 2026

    @okwasniewski
    Member

    Automated triage (AI pass), not yet read by a maintainer.

    Confirmed on main at 7c1b2b2. describeExpression prints only a query's value, name and visible (expression.ts:185-191). roleQuery also stores level and the state options (L22-L35), and a loose exact lives on the pattern. So locators that differ only by those options print the same string in failures, step labels and reports. The bug is real: the message points at a locator that looks like it should match.

    #2494 fixes this at the source. Thanks for the repro and the PR.

  2. added
    bug
    reporting
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreporting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions