Skip to content

fix(playwright): adapter to support Page and FrameLocator#4

Merged
gpichot merged 1 commit intomainfrom
claude/fix-contact-form-typings-fTbPN
Mar 26, 2026
Merged

fix(playwright): adapter to support Page and FrameLocator#4
gpichot merged 1 commit intomainfrom
claude/fix-contact-form-typings-fTbPN

Conversation

@gpichot
Copy link
Copy Markdown
Owner

@gpichot gpichot commented Mar 25, 2026

Summary

This PR refactors the Playwright adapter to properly support both Playwright Page and FrameLocator objects, improving type safety and fixing issues with the selectOption method's return type.

Key Changes

  • Separated interface concerns: Created a new PwPage interface to represent the minimal surface needed from a Playwright Page or FrameLocator, distinct from PwLocatable which represents individual locators
  • Updated function signature: Changed playwright() to accept PwPage | PwLocatable instead of just PwLocatable, allowing it to work with both page-level and locator-level objects
  • Fixed selectOption return type: Updated the return type from Promise<void> to Promise<string[]> to match Playwright's actual API
  • Introduced locatable getter: Added a private getter that safely casts this.pw to PwLocatable for methods that require locator-specific operations
  • Updated method implementations: All action methods (click, fill, check, etc.) now use the locatable getter to ensure type safety
  • Fixed selectOption implementation: Made it properly async and discards the return value as expected by the adapter interface
  • Updated test file: Modified e2e tests to cast .get() results to PwLocator for Playwright's expect() assertions
  • Fixed TypeScript config: Changed rootDir from "./src" to "." in example-react to include e2e tests in compilation

Implementation Details

The refactoring maintains backward compatibility while improving the adapter's flexibility. The separation of PwPage and PwLocatable interfaces allows the adapter to handle both entry points (page/frame) and nested locators without type confusion. The locatable getter provides a clean way to access locator-specific methods while keeping the public API flexible.

https://claude.ai/code/session_01NLDZ5mExRobdxnCYZse77Z

- Fix PwLocatable to accept Playwright Page (split into PwPage and
  PwLocatable interfaces since Page lacks action methods like click/fill)
- Fix selectOption return type to match Playwright's Promise<string[]>
- Fix tsconfig rootDir to include e2e and tests directories
- Cast .get() results to Playwright Locator in spec for proper matchers

https://claude.ai/code/session_01NLDZ5mExRobdxnCYZse77Z
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 25, 2026

Deploy Preview for ui-testing-library ready!

Name Link
🔨 Latest commit 761535c
🔍 Latest deploy log https://app.netlify.com/projects/ui-testing-library/deploys/69c46eef463b4600081bd282
😎 Deploy Preview https://deploy-preview-4--ui-testing-library.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gpichot gpichot changed the title Refactor Playwright adapter to support Page and FrameLocator fix(playwright): adapter to support Page and FrameLocator Mar 25, 2026
@gpichot gpichot merged commit 4b84a01 into main Mar 26, 2026
4 of 6 checks passed
@gpichot gpichot deleted the claude/fix-contact-form-typings-fTbPN branch March 26, 2026 07:01
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.

2 participants