feat(locator): introduce locator.page() getter (#11630)
This commit is contained in:
parent
19820de7a9
commit
687a16b848
|
|
@ -551,6 +551,11 @@ Returns locator to the n-th matching element.
|
||||||
### param: Locator.nth.index
|
### param: Locator.nth.index
|
||||||
- `index` <[int]>
|
- `index` <[int]>
|
||||||
|
|
||||||
|
## method: Locator.page
|
||||||
|
- returns: <[Page]>
|
||||||
|
|
||||||
|
A page this locator belongs to.
|
||||||
|
|
||||||
## async method: Locator.press
|
## async method: Locator.press
|
||||||
|
|
||||||
Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,10 @@ export class Locator implements api.Locator {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page() {
|
||||||
|
return this._frame.page();
|
||||||
|
}
|
||||||
|
|
||||||
async boundingBox(options?: TimeoutOptions): Promise<Rect | null> {
|
async boundingBox(options?: TimeoutOptions): Promise<Rect | null> {
|
||||||
return this._withElement(h => h.boundingBox(), options?.timeout);
|
return this._withElement(h => h.boundingBox(), options?.timeout);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
packages/playwright-core/types/types.d.ts
vendored
5
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -9279,6 +9279,11 @@ export interface Locator {
|
||||||
*/
|
*/
|
||||||
nth(index: number): 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)
|
* 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).
|
* and [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboard-up).
|
||||||
|
|
|
||||||
|
|
@ -191,3 +191,15 @@ it('isVisible and isHidden should work with details', async ({ page }) => {
|
||||||
|
|
||||||
await expect(page.locator('ul')).toBeHidden();
|
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);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue