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 withoutPage
instance - All of interactions like
click
,hover
will delegate to instance of Page can be found viaStaticPage.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()