From 1b44b911d3633df89bd6106aaf7accb49230934d Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:11:44 +0200 Subject: [PATCH] fix: use handle frame instead of page (#10676) --- .../src/api/locators/Locator.ts | 2 +- test/TestExpectations.json | 6 +++++ test/src/locator.spec.ts | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/puppeteer-core/src/api/locators/Locator.ts b/packages/puppeteer-core/src/api/locators/Locator.ts index 8ff4c734..19a769c7 100644 --- a/packages/puppeteer-core/src/api/locators/Locator.ts +++ b/packages/puppeteer-core/src/api/locators/Locator.ts @@ -322,7 +322,7 @@ export abstract class Locator extends EventEmitter { return EMPTY; } return from( - handle.frame.page().waitForFunction( + handle.frame.waitForFunction( element => { if (!(element instanceof HTMLElement)) { return true; diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 87a73c02..161e1a69 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -965,6 +965,12 @@ "parameters": ["webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[locator.spec] Locator Locator.click should work with a OOPIF", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[mouse.spec] Mouse should click the document", "platforms": ["darwin", "linux", "win32"], diff --git a/test/src/locator.spec.ts b/test/src/locator.spec.ts index d0288a43..1cd518e7 100644 --- a/test/src/locator.spec.ts +++ b/test/src/locator.spec.ts @@ -287,6 +287,31 @@ describe('Locator', function () { clock.restore(); } }); + + it('should work with a OOPIF', async () => { + const {page} = await getTestState(); + + await page.setViewport({width: 500, height: 500}); + await page.setContent(` + + `); + const frame = await page.waitForFrame(frame => { + return frame.url().startsWith('data'); + }); + let willClick = false; + await frame + .locator('button') + .on(LocatorEmittedEvents.Action, () => { + willClick = true; + }) + .click(); + const button = await frame.$('button'); + const text = await button?.evaluate(el => { + return el.innerText; + }); + expect(text).toBe('clicked'); + expect(willClick).toBe(true); + }); }); describe('Locator.hover', function () {