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
test: keepalive and workers fetch when offline (#35927)
Dmitry Gozmanec3e13b9604f
diff --git a/tests/library/browsercontext-basic.spec.ts b/tests/library/browsercontext-basic.spec.tsindex 6988d3ba4a..352b1bca03 100644--- a/tests/library/browsercontext-basic.spec.ts+++ b/tests/library/browsercontext-basic.spec.ts@@ -291,6 +291,34 @@ it('should work with offline option', async ({ browser, server, browserName }) =await context.close();});+it('fetch with keepalive should throw when offline', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/35701' },+}, async ({ contextFactory, server }) => {+ const context = await contextFactory();+ const page = await context.newPage();+ await page.goto(server.EMPTY_PAGE);++ const url = server.PREFIX + '/fetch';+ server.setRoute('/fetch', (req, res) => {+ res.setHeader('Content-Type', 'application/json');+ res.end(JSON.stringify('hello'));+ });++ const okResponse = await page.evaluate(url => fetch(url, { cache: 'no-store', keepalive: true }).then(response => response.json()), url);+ expect(okResponse).toEqual('hello');++ await context.setOffline(true);+ const offlineResponse = await page.evaluate(async url => {+ try {+ const response = await fetch(url, { cache: 'no-store', keepalive: true });+ return await response.json();+ } catch {+ return 'error';+ }+ }, url);+ expect(offlineResponse).toEqual('error');+});+it('should emulate navigator.onLine', async ({ browser, server }) => {const context = await browser.newContext();const page = await context.newPage();diff --git a/tests/page/workers.spec.ts b/tests/page/workers.spec.tsindex a4e5b99afc..7db80de3b4 100644--- a/tests/page/workers.spec.ts+++ b/tests/page/workers.spec.ts@@ -286,15 +286,17 @@ it('should support extra http headers', {});it('should support offline', async ({ page, server, browserName }) => {- it.fixme(browserName === 'firefox');it.fixme(browserName === 'webkit', 'flaky on all platforms');const [worker] = await Promise.all([page.waitForEvent('worker'),+ page.waitForEvent('console', msg => msg.text().includes('hello from the worker')),page.goto(server.PREFIX + '/worker/worker.html'),]);await page.context().setOffline(true);- await expect.poll(() => worker.evaluate(() => navigator.onLine)).toBe(false);+ // TODO: Firefox does not plumb setOffline into WorkerNavigator::OnLine.+ const expectedOnline = browserName === 'firefox' ? true : false;+ await expect.poll(() => worker.evaluate(() => navigator.onLine)).toBe(expectedOnline);expect(await worker.evaluate(() => fetch('/one-style.css').catch(e => 'error'))).toBe('error');await page.context().setOffline(false);await expect.poll(() => worker.evaluate(() => navigator.onLine)).toBe(true);