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: add regression test for bug 33561 (#35006)
Andrey Lushnikovf396bf2236c0
diff --git a/tests/assets/serviceworkers/bug-33561/index.html b/tests/assets/serviceworkers/bug-33561/index.htmlnew file mode 100644index 0000000000..b29d3f2e34--- /dev/null+++ b/tests/assets/serviceworkers/bug-33561/index.html@@ -0,0 +1,4 @@+<script>+ window.registrationPromise = navigator.serviceWorker.register('sw.js');+ window.activationPromise = new Promise(resolve => navigator.serviceWorker.oncontrollerchange = resolve);+</script>diff --git a/tests/assets/serviceworkers/bug-33561/sw.js b/tests/assets/serviceworkers/bug-33561/sw.jsnew file mode 100644index 0000000000..83a661dc45--- /dev/null+++ b/tests/assets/serviceworkers/bug-33561/sw.js@@ -0,0 +1,14 @@+// sw.js+self.addEventListener('install', (event) => {+ self.skipWaiting();+});++self.addEventListener('activate', (event) => {+ event.waitUntil(self.clients.claim());+});++self.addEventListener('fetch', (event) => {+ // IMPORTANT: we have to have a "fetch" listener+ // to trigger the issue.+ console.log('Fetching:', event.request.url);+});diff --git a/tests/page/page-route.spec.ts b/tests/page/page-route.spec.tsindex f8ae508532..00a5fc94a3 100644--- a/tests/page/page-route.spec.ts+++ b/tests/page/page-route.spec.ts@@ -1028,3 +1028,21 @@ it('should intercept when postData is more than 1MB', async ({ page, server }) =}).catch(e => {}), POST_BODY);expect(await interceptionPromise).toBe(POST_BODY);});++it('should be able to intercept every navigation to a page controlled by service worker', async ({ page, server, isElectron, browserName }) => {+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33561' });+ it.fixme(browserName === 'firefox');+ it.skip(isElectron);++ let interceptions = 0;+ const URL = server.PREFIX + '/serviceworkers/bug-33561/index.html';+ await page.route(URL, async route => {+ ++interceptions;+ await route.continue();+ });++ await page.goto(URL);+ await page.evaluate(() => window['activationPromise']);+ await page.goto(URL);+ expect(interceptions).toBe(2);+});