Skip to content

docs: use locator-first examples in the API reference - #53

Open
luantaraschi wants to merge 1 commit into
lackeyjb:mainfrom
luantaraschi:docs/locator-first-api-reference
Open

docs: use locator-first examples in the API reference#53
luantaraschi wants to merge 1 commit into
lackeyjb:mainfrom
luantaraschi:docs/locator-first-api-reference

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

Closes #46.

I checked every candidate against Playwright's own doc source (microsoft/playwright, docs/src/api/*.md) rather than going from memory, since the issue asks to replace only where current guidance clearly prefers something better. Three groups came out of it.

Deprecated, replaced. locator.type carries a deprecation note verbatim:

* deprecated: In most cases, you should use [method: Locator.fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [method: Locator.pressSequentially].

The "clear and type" example now shows fill for the ordinary case and pressSequentially for the per-key one, labelled so a reader knows which situation each is for, rather than silently swapping one for the other.

Discouraged, replaced. Six page-level selector APIs in the reference carry a discouraged marker pointing at their locator equivalent:

API note in class-page.md
page.click Use locator-based Locator.click instead
page.fill Use locator-based Locator.fill instead
page.selectOption Use locator-based Locator.selectOption instead
page.setInputFiles Use locator-based Locator.setInputFiles instead
page.hover Use locator-based Locator.hover instead
page.dblclick Use locator-based Locator.dblclick instead

Those cover the form, mouse, network-wait, data-driven, popup and download examples. Where the element was described by role in prose I used getByRole rather than mechanically wrapping the CSS selector in page.locator(...), since the reference already teaches role-first locators a few sections earlier; where the example was pinned to a specific id or class I kept that selector and just moved it into a locator.

Not touched, on purpose. page.keyboard.type stays. It has no deprecation or discouraged note, and class-keyboard.md still calls it "the high level api" and uses it in its own example. Replacing it would have been the audit overreaching. I also found no waitForTimeout and no networkidle anywhere in the file, so nothing to do on the two patterns the issue names first.

What I ran, on Windows with Node 22.20.0:

  • npm test in skills/playwright-skill: 12 pass, 0 fail
  • npx skills-ref@0.1.5 validate . in the same directory, which is what CI runs: Valid skill: .
  • a grep afterwards for the whole discouraged set to confirm none survived in the file

Docs-only change, 22 lines added and 19 removed, no behaviour anywhere.

The reference showed six page-level selector APIs that Playwright marks discouraged (page.click, page.fill, page.selectOption, page.setInputFiles, page.hover, page.dblclick) and one that is outright deprecated (locator.type). A skill's reference is what an agent copies, so each example now uses the form the current docs prefer.

locator.type carries a deprecation note pointing at locator.fill, with locator.pressSequentially for pages that need per-key events; the example now shows both and says which is which.

page.keyboard.type is left alone: it carries no such note, and the Keyboard class docs still describe it as the high-level api and use it in their own example.

Closes lackeyjb#46
@luantaraschi
luantaraschi requested a review from lackeyjb as a code owner August 14, 2026 18:35
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.

Audit API reference for discouraged Playwright patterns

1 participant