Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(locator handler): perform checkpoit during locator.waitFor #32683

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions packages/playwright-core/src/server/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,16 @@ export class Frame extends SdkObject {
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
return controller.run(async progress => {
progress.log(`waiting for ${this._asLocator(selector)}${state === 'attached' ? '' : ' to be ' + state}`);
return await this.waitForSelectorInternal(progress, selector, options, scope);
return await this.waitForSelectorInternal(progress, selector, true, options, scope);
}, this._page._timeoutSettings.timeout(options));
}

async waitForSelectorInternal(progress: Progress, selector: string, options: types.WaitForElementOptions, scope?: dom.ElementHandle): Promise<dom.ElementHandle<Element> | null> {
async waitForSelectorInternal(progress: Progress, selector: string, performLocatorHandlersCheckpoint: boolean, options: types.WaitForElementOptions, scope?: dom.ElementHandle): Promise<dom.ElementHandle<Element> | null> {
const { state = 'visible' } = options;
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
if (performLocatorHandlersCheckpoint)
await this._page.performLocatorHandlersCheckpoint(progress);

const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
progress.throwIfAborted();
if (!resolved) {
Expand Down
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 @@ -473,7 +473,7 @@ export class Page extends SdkObject {
progress.throwIfAborted();
if (!handler.noWaitAfter) {
progress.log(` locator handler has finished, waiting for ${asLocator(this.attribution.playwright.options.sdkLanguage, handler.selector)} to be hidden`);
await this.mainFrame().waitForSelectorInternal(progress, handler.selector, { state: 'hidden' });
await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, { state: 'hidden' });
} else {
progress.log(` locator handler has finished`);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/page/page-add-locator-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ test('should work with toBeVisible', async ({ page, server }) => {
expect(called).toBe(1);
});

test('should work with locator.waitFor', async ({ page, server }) => {
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 page.locator('#close').click();
});

await page.evaluate(() => {
(window as any).clicked = 0;
(window as any).setupAnnoyingInterstitial('remove', 1);
});
await page.locator('#target').waitFor();
await expect(page.locator('#interstitial')).not.toBeVisible();
expect(called).toBe(1);
});

test('should work with toHaveScreenshot', async ({ page, server, isAndroid }) => {
test.fixme(isAndroid, 'Screenshots are cut off on Android');
await page.setViewportSize({ width: 500, height: 500 });
Expand Down
Loading