fix(waitFor): when frameLocator does not match, resolve hidden/detached states (#22119)

Fixes #21879.
This commit is contained in:
Dmitry Gozman 2023-03-31 10:54:07 -07:00 committed by GitHub
parent 37d1659508
commit a95ced0fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -787,8 +787,11 @@ export class Frame extends SdkObject {
const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
progress.throwIfAborted();
if (!resolved)
if (!resolved) {
if (state === 'hidden' || state === 'detached')
return null;
return continuePolling;
}
const result = await resolved.injected.evaluateHandle((injected, { info, root }) => {
const elements = injected.querySelectorAll(info.parsed, root || document);
const element: Element | undefined = elements[0];

View File

@ -260,9 +260,11 @@ it('getBy coverage', async ({ page, server }) => {
it('wait for hidden should succeed when frame is not in dom', async ({ page }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21879' });
it.fixme();
await page.goto('about:blank');
const button = page.frameLocator('iframe1').locator('button');
expect(await button.isHidden()).toBeTruthy();
await button.waitFor({ state: 'hidden', timeout: 1000 });
await button.waitFor({ state: 'detached', timeout: 1000 });
const error = await button.waitFor({ state: 'attached', timeout: 1000 }).catch(e => e);
expect(error.message).toContain('Timeout 1000ms exceeded');
});