Skip to content

playwright: simplify per-tab DOM locators by marking the active source-tab content #17793

Description

@kevinushey

Background

Several Playwright page-object locators in e2e/rstudio/pages/source_pane.page.ts need to target an element that exists inside every open source-editor tab (publishBtn, formatOptions, knitOptions, saveBtn, visualMdToggle, contentPane, aceTextInput, nesGutter, footerTable, previewBtn, ...). With more than one tab open -- which is now the steady state since tests start from a single Untitled placeholder rather than an empty source pane -- a plain page-wide locator strict-matches multiple elements and the assertion fails.

The workaround in tree today is a hand-rolled XPath that scopes to the visible tabpanel by sniffing inline style="display: none":

this.publishBtn = page.locator(
  "xpath=//div[@role='tabpanel' and not(contains(@style, 'display: none'))]" +
  "//*[starts-with(@id,'rstudio_publish_item_editor')]"
);

Six locators already share this prefix, and any new per-tab element added to a toolbar will need the same treatment.

Why this is brittle

  • Tied to GWT TabLayoutPanel's internal inline-style behavior. If that ever switches from display: none to visibility: hidden, hidden custom attribute, etc., every test-side locator silently starts matching the wrong thing.
  • Hard to read at a glance and easy to copy wrong (the not(contains(@style, 'display: none')) clause is exact-string sensitive -- e.g. display:none without the space wouldn't match).
  • Pushes test authors toward XPath when CSS would be more idiomatic for everything else in the page object.

Suggested DOM-side changes (pick one)

Option A -- mark the inactive tab content. Set aria-hidden="true" on the inactive [role='tabpanel'] containers inside the source pane (and clear it on the active one). Test locators collapse to:

this.publishBtn = page.locator(
  "[role='tabpanel']:not([aria-hidden='true']) [id^='rstudio_publish_item_editor']"
);

This is a one-line CSS selector and aria-hidden is also semantically correct for assistive tech.

Option B -- give the active source-tab content a stable id. Wrap the visible tabpanel with something like id="rstudio_active_source_panel" (updated when the active tab changes). Locators become:

this.publishBtn = page.locator(
  "#rstudio_active_source_panel [id^='rstudio_publish_item_editor']"
);

Either change would let us delete the XPath wrappers and stop chasing the same scope bug every time we add a new per-tab button to a toolbar.

Scope

  • Find where WorkbenchTabPanel / SourceColumn swap the active source tab and toggle the marker there.
  • Update the six existing scoped locators in e2e/rstudio/pages/source_pane.page.ts to the simpler CSS form.
  • No behavior change for end users; this is purely a test-infrastructure ergonomics improvement.

Context

Surfaced while working on Playwright flake removal -- see the test-infra refactor PR for the current XPath-based fix.

Activity

  1. added
    new
    on May 28, 2026
  2. github-actions commented on Nov 26, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

  3. added
    stale
    on Nov 26, 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

    enhancementnewstale

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions