Repository navigation
Conversation
Port Playwright's implicit role rule for `th` (microsoft/playwright#38160), which matches Chromium: an explicit `scope` of col/colgroup or row/rowgroup wins; otherwise the role comes from the neighbouring cells, and a lone `th` in a single-row table gets no role. Previously a `th` without `scope` was treated as a `cell`, so `getByRole('columnheader')` missed header cells that the browser's accessibility tree and Playwright both expose as headers. Refs vitest-dev/vitest#8054 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 of 8 tasks
columnheader/rowheader for th without scopecolumnheader/rowheader for th without scope
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs vitest-dev/vitest#8054
Problem
getByRole('columnheader')andgetByRole('rowheader')in Vitest browser mode don't find a<th>that has noscopeattribute. ivya treats such athas acell, which is how Playwright behaved when #8054 was closed. Playwright has since changed the rule in microsoft/playwright#38160 (released in 1.57), so for the same markup Playwright'spage.getByRole('columnheader')now finds the header cells and Vitest's doesn't.Change
This ports Playwright's current
THrule frompackages/injected/src/roleUtils.tsintosrc/roleUtils.ts, including the two helpersisHeaderCellandisNonEmptyDataCell:scopestill wins:col/colgroupgivescolumnheader, androw/rowgroupgivesrowheader.colgroupandrowgroupweren't recognised before.ax_node_object.cc). Athwith a non-emptytdnext to it is arowheader. Any otherthis acolumnheader. The one exception is a lonethin a single-row table, which gets no role.Tests
test/role.test.tsruns on chromium, firefox and webkit. It covers these cases, taken from the ones Playwright added in #38160:this acolumnheader, with or withouttheadthfirst in a body row is arowheaderthnext to an emptytdis acolumnheaderthin a single-row table has no role, and in a multi-row table it's acolumnheaderscopevalues beat the position-based rulequeryAllByRoleandgetByRoleSelectorNine of these fail without the change. The
table structure rolesaria snapshot now showscolumnheader "H"where it used to showcell "H", which is what Playwright's snapshot shows.I also checked every fixture outside the test suite with Playwright 1.60 on Chromium. For each one I compared ivya's new result with Playwright's
page.getByRoleand with Chromium's accessibility tree from CDPAccessibility.getPartialAXTree. They matched in all eight cases, including the loneth(Playwright gives no role, and Chromium reports a layout-onlyLayoutTableCell).Once this is released, Vitest needs its
ivyadependency bumped to pick it up.🤖 Generated with Claude Code