Skip to content

[Feature] Expose page instance from locator #11269

Description

@tymfear

Let us know what functionality you'd like to see in Playwright and what your use case is.
Do you think others might benefit from this as well?
My use case are page fragments that receive root locator from the main page, and use it as a reference point for further element interactions. And sometimes I need an instance of the page used to define the root locator. So it would be a bit easier to get the instance from the locator, than passing it as additional constructor argument.

What I'm doing now

export class SomeFragment {
  constructor(private page: Page, private root: Locator) {}

  async someMethod() {
    await this.page.doSomeWork()
  }
}

What I would like to do

export class SomeFragment {
  constructor(private root: Locator) {}

  async someMethod() {
    this.root.page.doSomeWork()
  }
}

Activity

  1. mskelton commented on Jan 15, 2022

    @mskelton
    Contributor

    I built a page object framework built on top of locators that currently is using the _frame property since it is not publicly exposed, so I could benefit from this as well.

    https://github.com/Widen/lariat/blob/main/src/Collection.ts#L85-L87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions