Given the pseudo-POM below and the case where you would need to wait for an element for any reason, you'd have to repeat the selector in two places. It hurts reusability.
export class PageObject {
private readonly page: Page
private readonly someButton: Locator
constructor(page: Page) {
this.page = page
this.someButton = this.page.locator('#someButtton')
}
async clickSomeButton() {
await this.page.waitForSelector('#someButton')
await this.someButton.click()
}
}
While using the old method, you could set selector value once and then simply reuse the variable as much as you want:
POM with page actions
export class PageObject {
private readonly page: Page
private readonly someButton: string
constructor(page: Page) {
this.page = page
this.someButton = ('#someButtton')
}
async clickSomeButton() {
await this.page.waitForSelector(this.someButton)
await this.page.click(this.someButton)
}
}
It'd be nice if locator API would have an option to use functions like waitForSelector(). My use case involves only this function but there might be others.
Given the pseudo-POM below and the case where you would need to wait for an element for any reason, you'd have to repeat the selector in two places. It hurts reusability.
While using the old method, you could set selector value once and then simply reuse the variable as much as you want:
POM with page actions
It'd be nice if locator API would have an option to use functions like waitForSelector(). My use case involves only this function but there might be others.