Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export class Page extends SdkObject<PageEventMap> {

private async _performLocatorHandlersCheckpoint(progress: Progress) {
// Do not run locator handlers from inside locator handler callbacks to avoid deadlocks.
if (this._locatorHandlerRunningCounter)
if (this._locatorHandlerRunningCounter || [...this._locatorHandlers.values()].some(handler => !!handler.resolved))
return;
for (const [uid, handler] of this._locatorHandlers) {
if (!handler.resolved) {
Expand Down
30 changes: 30 additions & 0 deletions tests/library/multiclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,33 @@ test('MC-019 should not deliver an action buffered before the second recording s
expect(recorderA.selectors).toEqual(['internal:role=button[name="Before"i]']);
expect(recorderB.selectors).toEqual(['internal:role=button[name="After"i]']);
});

test('MC-020 should run locator handlers after reconnecting with a pending callback', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43607' },
}, async ({ connect, remoteServer, server }) => {
const browser = await connect(remoteServer.wsEndpoint());
const page = await browser.newPage();
await page.goto(server.PREFIX + '/input/handle-locator.html');

let called = 0;
await page.addLocatorHandler(page.getByText('This interstitial covers the button'), async () => {
++called;
await new Promise(() => {});
});
await page.evaluate(() => {
(window as any).setupAnnoyingInterstitial('none', 1);
});
const error = await page.locator('#target').click({ timeout: 1000 }).catch(e => e);
expect(error.message).toContain('Timeout 1000ms exceeded');
expect(called).toBe(1);

await disconnect(page);

const reconnectedBrowser = await connect(remoteServer.wsEndpoint());
const reconnectedPage = reconnectedBrowser.contexts()[0].pages()[0];
await reconnectedPage.addLocatorHandler(reconnectedPage.getByText('This interstitial covers the button'), async () => {
await reconnectedPage.locator('#close').click();
});
await reconnectedPage.locator('#target').click({ timeout: 3000 });
expect(await reconnectedPage.evaluate('window.clicked')).toBe(1);
});
15 changes: 13 additions & 2 deletions tests/page/page-add-locator-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* limitations under the License.
*/

import { iso } from '../../packages/playwright-core/lib/coreBundle';
import { test, expect } from './pageTest';

const { ManualPromise } = iso;

test('LH-001 should work', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/handle-locator.html');

Expand Down Expand Up @@ -120,14 +123,19 @@ test('LH-004 should not work with force:true', async ({ page, server }) => {
expect(await page.evaluate('window.clicked')).toBe(undefined);
});

test('LH-005 should throw when handler times out', async ({ page, server }) => {
test('LH-005 should throw when handler times out', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43607' },
}, async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/handle-locator.html');

let called = 0;
const releaseHandler = new ManualPromise();
const handlerFinished = new ManualPromise<Error | void>();
await page.addLocatorHandler(page.getByText('This interstitial covers the button'), async () => {
++called;
// Deliberately timeout.
await new Promise(() => {});
await releaseHandler;
handlerFinished.resolve(await page.locator('#close').click({ timeout: 3000 }).catch(e => e));
});

await page.locator('#aside').hover();
Expand All @@ -143,6 +151,9 @@ test('LH-005 should throw when handler times out', async ({ page, server }) => {

// Should not enter the same handler while it is still running.
expect(called).toBe(1);

releaseHandler.resolve();
expect(await handlerFinished).toBeUndefined();
});

test('LH-006 should work with toBeVisible', async ({ page, server }) => {
Expand Down
Loading