Skip to content

Give Python assertion rows the element their value was read from - #475

Merged
vishnuv688 merged 3 commits into
mainfrom
fix/462-python-assert-target
Oct 28, 2026
Merged

vishnuv688 merged 3 commits into
mainfrom
fix/462-python-assert-target

Conversation

@vishnuv688

Copy link
Copy Markdown
Member

What & why

Closes #462.

An assertion row from pytest's plain assert named no element, so the dashboard could not box what the assertion was about. The JS adapters get this from value provenance (core/read-value-locators.ts); the Python adapter had no counterpart, and the conformance suite carried it as a known gap (lacksTargets: ['Assert.equal']).

The Python adapter now keeps the same registry in selenium_devtools/read_value_locators.py, since it cannot import core:

  • Every captured command records its result against the row's selector from the patched execute: same bounds as core (200 values, strings of at most 256 chars, primitives only, newest producer wins), keyed by type as well so True and 1 stay apart.
  • A driver-level read (driver.title, current_url) records None, so a title assertion never borrows the box of an element whose text reads the same.
  • get_attribute and is_displayed reach the wire as w3cExecuteScript atoms, so their element comes from the script's arguments (element_locators.selector_for_script_element).
  • The assertion row (pytest pass and failure hooks, and the plain-script tracer and unwinding paths) looks up the observed operand before the expected one (assertions.comparison_target), and an operand recorded as no element's ends the search, so a literal some element once read cannot hand a title assertion that element's box.

The conformance allowlist entry, its KNOWN_DEBT.pythonAssertTarget reason and the CLAUDE.md debt bullet are removed; the value-provenance bullet in CLAUDE.md now describes the Python side. No features.ts cell names this, so the capability tables are unchanged (pnpm docs:capabilities --check passes).

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

Packages touched

  • shared (types and contracts)
  • core (framework-agnostic capture/reporting)
  • elements (published element/snapshot API — @wdio/elements)
  • service (WebdriverIO adapter)
  • nightwatch-devtools (Nightwatch adapter)
  • selenium-devtools (Selenium adapter)
  • selenium-devtools-py (Selenium Python adapter)
  • backend (server)
  • app (UI)
  • script (page-injected runtime)
  • trace (Trace mode)

Also packages/conformance (allowlist and one agreement test fixture).

Capability matrix

  • packages/conformance/src/features.ts updated, and tables regenerated with pnpm docs:capabilities, if this adds or changes user-facing behaviour

No cell covers assertion targets; pnpm docs:capabilities --check passes unchanged.

Notes for reviewers

Evidence:

  • New tests/test_read_value_locators.py (14 tests). With the wiring reverted, the 5 end-to-end row tests fail. With the None sentinel removed (driver-level reads not recorded), the title-vs-element collision test fails with the title assertion carrying selector: 'h1'.
  • Conformance (npx vitest run packages/conformance/tests/conformance.test.ts) passes 3 of 3 runs with the gap removed. With assertion_target forced to return nothing, it fails in all three BiDi modes on devtools-service shows [Assert.equal #flash], selenium-devtools-py shows [Assert.equal] (and the same for h2), so the Python adapter really runs there.
  • agreement.test.ts used the removed gap to exercise target dropping; its fixture's Python assertion now carries #flash, since that is what the adapter shows. The lacksTargets mechanism itself is kept, with no gap using it today.

Checks: Python suite 777 passed, 2 failed (test_an_abandoned_driver_is_not_retained, test_the_recorder_does_not_retain_its_driver, both failing identically on origin/main in this environment); pnpm build, pnpm test (3017 passed), pnpm lint (0 errors), pnpm typecheck, pnpm docs:capabilities --check, scripts/changes.py check all green.

Known residuals, as in the JS registry: a boolean read is weakly discriminating, and a value collision with no intervening producer can still mis-attribute. A user execute_script that takes an element argument now attributes its returned value to that element too.

Not verified in a real browser here beyond the conformance harness's fake WebDriver. To check the box in the dashboard:

export PYTHONPATH=$PWD/packages/selenium-devtools-py/src
pnpm demo:python:pytest

then select the "You logged into a secure area" in flash row: the overlay should box the flash message, while the "/secure" in current_url row (a driver-level read) should box nothing.

Screenshots / recordings

Not a UI change.

🤖 Generated with Claude Code

A pytest assert compares values, so its row named no element and the
dashboard could not box what the assertion was about, while the JS
adapters' rows carried the locator through value provenance. The Python
adapter cannot import core's registry, so it keeps its own: every captured
command records its result against its selector (None for a driver-level
read, so a title assertion never borrows an element that reads the same
text), script atoms such as get_attribute and is_displayed resolve the
element passed to them, and the assertion row looks up the observed
operand first.

With the gap closed, the conformance allowlist entry, its Known debt
reason and the CLAUDE.md bullet describing it go too.

Closes #462
@vishnuv688 vishnuv688 self-assigned this Oct 27, 2026
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no new actionable defects were found.

Summary

Python assertion rows now use remembered command results to find the element they describe.

  • Python assertion rows can point to the element that produced their value.

Reviews (3) · Last reviewed commit: "Merge origin/main into fix/462-python-as..." · Reviewed by Greptile

…nown

A plain script's assertion on an attribute such as driver.title cannot
see the value that was read, so the target fell back to the expected
literal and could box an element that once read the same text. With the
observed side unknown, the row now carries no target.
#474 and this branch both edited the Python adapter's command capture:
the row now carries both this branch's selector and #474's wait fold
(replaces=). #474 closed the Python wait debt and this branch closes the
assertion-target debt, so neither entry stays in KNOWN_DEBT or CLAUDE.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: assertion rows carry no element target

1 participant