name: rstudio-create-playwright-tests description: Patterns and gotchas for authoring RStudio Playwright tests in TypeScript. Use when writing, reviewing, or migrating tests under e2e/rstudio/.
Creating RStudio Playwright Tests
Most of what you need is in e2e/rstudio/README.md (basic structure,
conventions, selector hierarchy, Ace interactions, cross-platform shortcuts,
sandbox, tags, package deps) and in the existing tests under
e2e/rstudio/tests/. The fixture (@fixtures/rstudio.fixture) handles
RStudio launch/shutdown, save-dialog dismissal, and buffer cleanup -- author
tests as if the IDE starts clean.
This file covers RStudio-specific gotchas that aren't in the README.
Before writing
- Skim
e2e/rstudio/tests/for an existing similar test. - Skim
e2e/rstudio/pages/,actions/, andutils/for existing helpers.
Universal rules
pressSequentially()for GWT text inputs whose handlers fire per keystroke -- console, editor, and mostinput.gwt-TextBoxfields in dialogs/wizards (where typing a character enables OK, triggers autocomplete, etc.).fill()doesn't fire GWT key events in those cases. Inputs driven by a discrete trigger likepress('Enter')or a button click (e.g., the console Find bar) work fine withfill(), which has the bonus of replacing text instead of appending. Start withfill(); switch topressSequentially()only if the handler doesn't fire.Force-click Ace textareas:
await locator.click({ force: true }). Anace_contentdiv overlays the hidden textarea and intercepts normal clicks.focus()is also unreliable -- keystrokes can land in the wrong pane.Derive selectors from source, never use
gwt-uid-XXXX(those change every restart):src/gwt/.../commands/Commands.cmd.xml-- command IDs map to menu items at#rstudio_label_<sanitized_id>and toolbar buttons at#rstudio_tb_<sanitized_id>(seeElementIds.javafor the sanitizer).src/gwt/.../core/client/theme/DocTabLayoutPanel.java-- tab structure (.gwt-TabLayoutPanelTab,.gwt-TabLayoutPanelTab-selected, etc.).
Invoke RStudio commands and prefs via the
window.rstudiobridge -- import helpers from@utils/commands(executeCommand,setPref, etc.). Don't use.rs.api.executeCommand(...)(slow console roundtrip) orwindow.desktopHooks.invokeCommand(...)(Electron-only, crashes on Server).Decision order for triggering an action: GUI button/menu/shortcut, then
executeCommand(page, id), thenpage.evaluate()as a last resort. Clicking a button tests the real user path; the helper is for setup/teardown or when the UI path is slow/flaky/tangential to what's being tested.RStudio binds some shortcuts to plain Ctrl on every platform (including macOS) -- e.g.,
Ctrl+EnterRun Line,Ctrl+LClear Console,Ctrl+SpaceAutocomplete. Use Playwright's plainControlfor those, notControlOrMeta. If you're unsure, check what RStudio's keyboard-shortcut UI shows for the binding.Tests must work on Desktop and Server. Prefer stable IDs over wrapper selectors. Tag mode-specific tests
@desktop_onlyor@server_onlyrather than runtime-branching ontestInfo.project.name.
Feature-specific patterns
When working in these areas, also read the corresponding file:
- Code suggestions / Copilot / NES (
tests/panes/editor/code_suggestions.test.ts,edit_suggestions.test.ts): seecode-suggestions.md. - Chat pane / Posit Assistant / RPC interception
(
tests/panes/posit-assistant-chat/): seechat-pane.md.