@silenteer/pw-proxy
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

Playwright proxy

Plawyright proxy is a proxy for creating a "static" Playwright Locator.

Plawyright Locator normally cannot be constructed without having an instance of Page (or another Locator). But if the Locator on its own doesn't have the intention to interact with the Page (like click, hover etc), Locator would not need to have the Page instance

How the proxy comes into play

So, pw-proxy lets you create an instance of Locator in a static way

  • All of methods to manipulate Locator can be constructed without Page instance
  • All of interactions like click, hover will delegate to instance of Page can be found via StaticPage.set

The result of those letting you create Page Object in a more static way

Compares traditional Page Object

class Home {
  constructor(public page: Page) {}
  dialog = this.page.locator('.dialog').fitler({ hasText: 'form' })

  async openDialog() { await this.dialog.click() }
}

const home = new Home(page)
await home.openDialog()

to something way simpler

const home = new class {
  dialog = $.locator('.dialog').fitler({ hasText: 'form' })
  async openDialog() { await this.dialog.click() }
}

// you'll need to set page
StaticPage.set(page)
await home.openDialog()

Readme

Keywords

none

Package Sidebar

Install

npm i @silenteer/pw-proxy

Weekly Downloads

1

Version

1.3.3

License

none

Unpacked Size

223 kB

Total Files

11

Last publish

Collaborators

  • lagz0ne
  • minh-van