fix: throw when element handle is detached while waiting for selector (#32961)
This commit is contained in:
parent
eaeaa0b158
commit
9f842da8b3
|
|
@ -805,6 +805,8 @@ export class Frame extends SdkObject {
|
||||||
return continuePolling;
|
return continuePolling;
|
||||||
}
|
}
|
||||||
const result = await resolved.injected.evaluateHandle((injected, { info, root }) => {
|
const result = await resolved.injected.evaluateHandle((injected, { info, root }) => {
|
||||||
|
if (root && !root.isConnected)
|
||||||
|
throw injected.createStacklessError('Element is not attached to the DOM');
|
||||||
const elements = injected.querySelectorAll(info.parsed, root || document);
|
const elements = injected.querySelectorAll(info.parsed, root || document);
|
||||||
const element: Element | undefined = elements[0];
|
const element: Element | undefined = elements[0];
|
||||||
const visible = element ? injected.utils.isElementVisible(element) : false;
|
const visible = element ? injected.utils.isElementVisible(element) : false;
|
||||||
|
|
|
||||||
|
|
@ -328,3 +328,31 @@ it('should fail when navigating while on handle', async ({ page, mode, server })
|
||||||
const error = await body.waitForSelector('div', { __testHookBeforeAdoptNode } as any).catch(e => e);
|
const error = await body.waitForSelector('div', { __testHookBeforeAdoptNode } as any).catch(e => e);
|
||||||
expect(error.message).toContain(`waiting for locator('div') to be visible`);
|
expect(error.message).toContain(`waiting for locator('div') to be visible`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail if element handle was detached while waiting', async ({ page, server }) => {
|
||||||
|
await page.setContent(`<button>hello</button>`);
|
||||||
|
const button = await page.$('button');
|
||||||
|
const promise = button.waitForSelector('something').catch(e => e);
|
||||||
|
await page.waitForTimeout(100);
|
||||||
|
await page.evaluate(() => document.body.innerText = '');
|
||||||
|
const error = await promise;
|
||||||
|
expect(error.message).toContain('Element is not attached to the DOM');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should succeed if element handle was detached while waiting for hidden', async ({ page, server }) => {
|
||||||
|
await page.setContent(`<button>hello</button>`);
|
||||||
|
const button = await page.$('button');
|
||||||
|
const promise = button.waitForSelector('something', { state: 'hidden' });
|
||||||
|
await page.waitForTimeout(100);
|
||||||
|
await page.evaluate(() => document.body.innerText = '');
|
||||||
|
await promise;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should succeed if element handle was detached while waiting for detached', async ({ page, server }) => {
|
||||||
|
await page.setContent(`<button>hello</button>`);
|
||||||
|
const button = await page.$('button');
|
||||||
|
const promise = button.waitForSelector('something', { state: 'detached' });
|
||||||
|
await page.waitForTimeout(100);
|
||||||
|
await page.evaluate(() => document.body.innerText = '');
|
||||||
|
await promise;
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -308,17 +308,6 @@ it('click should survive navigation', async ({ page, server }) => {
|
||||||
await promise;
|
await promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if element removed while waiting on element handle', async ({ page, server }) => {
|
|
||||||
it.fixme();
|
|
||||||
await routeIframe(page);
|
|
||||||
await page.goto(server.PREFIX + '/iframe.html');
|
|
||||||
const button = await page.$('button');
|
|
||||||
const promise = button.waitForSelector('something');
|
|
||||||
await page.waitForTimeout(100);
|
|
||||||
await page.evaluate(() => document.body.innerText = '');
|
|
||||||
await promise;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should non work for non-frame', async ({ page, server }) => {
|
it('should non work for non-frame', async ({ page, server }) => {
|
||||||
await routeIframe(page);
|
await routeIframe(page);
|
||||||
await page.setContent('<div></div>');
|
await page.setContent('<div></div>');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue