feat(locator): introduce locator.page() getter (#11630)

This commit is contained in:
Dmitry Gozman 2022-01-26 07:58:58 -08:00 committed by GitHub
parent 19820de7a9
commit 687a16b848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View file

@ -551,6 +551,11 @@ Returns locator to the n-th matching element.
### param: Locator.nth.index
- `index` <[int]>
## method: Locator.page
- returns: <[Page]>
A page this locator belongs to.
## async method: Locator.press
Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].

View file

@ -59,6 +59,10 @@ export class Locator implements api.Locator {
});
}
page() {
return this._frame.page();
}
async boundingBox(options?: TimeoutOptions): Promise<Rect | null> {
return this._withElement(h => h.boundingBox(), options?.timeout);
}

View file

@ -9279,6 +9279,11 @@ export interface Locator {
*/
nth(index: number): Locator;
/**
* A page this locator belongs to.
*/
page(): Page;
/**
* Focuses the element, and then uses [keyboard.down(key)](https://playwright.dev/docs/api/class-keyboard#keyboard-down)
* and [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboard-up).

View file

@ -191,3 +191,15 @@ it('isVisible and isHidden should work with details', async ({ page }) => {
await expect(page.locator('ul')).toBeHidden();
});
it('should return page', async ({ page, server }) => {
await page.goto(server.PREFIX + '/frames/two-frames.html');
const outer = page.locator('#outer');
expect(outer.page()).toBe(page);
const inner = outer.locator('#inner');
expect(inner.page()).toBe(page);
const inFrame = page.frames()[1].locator('div');
expect(inFrame.page()).toBe(page);
});