Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(actions): wait between action retries outside of the page (#43012)
Dmitry Gozman8b552173e8d7
diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.tsindex b0f370d99a..551e9eb368 100644--- a/packages/playwright-core/src/server/dom.ts+++ b/packages/playwright-core/src/server/dom.ts@@ -336,9 +336,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {const timeout = waitTime[Math.min(retry - 1, waitTime.length - 1)];if (timeout) {progress.log(` waiting ${timeout}ms`);- const result = await progress.race(this.evaluateInUtility(([injected, node, timeout]) => new Promise<void>(f => setTimeout(f, timeout)), timeout));- if (result === 'error:notconnected')- return result;+ await progress.wait(timeout);}} else {progress.log(`attempting ${actionName} action${options.trial ? ' (trial run)' : ''}`);diff --git a/tests/library/browsercontext-basic.spec.ts b/tests/library/browsercontext-basic.spec.tsindex b6413a3d02..d09e3f656b 100644--- a/tests/library/browsercontext-basic.spec.ts+++ b/tests/library/browsercontext-basic.spec.ts@@ -305,6 +305,24 @@ it('setContent should work after disabling javascript', async ({ contextFactoryawait expect(page.locator('h1')).toHaveText('Hello');});+it('should retry click after disabling javascript', async ({ contextFactory }) => {+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42977' });+ const context = await contextFactory({ javaScriptEnabled: false });+ const page = await context.newPage();+ await page.setContent(`+ <details><summary>Continue</summary>Details</details>+ <div id="cover" style="position: fixed; inset: 0;"></div>+ `);+ let clicked = false;+ const clickPromise = page.locator('summary').click().then(() => clicked = true);+ // Give it enough time to go through a few retries while the button is covered.+ await page.waitForTimeout(2000);+ expect(clicked).toBe(false);+ await page.locator('#cover').evaluate(e => e.remove());+ await clickPromise;+ await expect(page.locator('details')).toHaveAttribute('open', '');+});+it('should work with offline option', async ({ browser, server, browserName }) => {const context = await browser.newContext({ offline: true });const page = await context.newPage();