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: url bar navigation vs js redirect (#21640)
Yury Semikhatsky6b3e7faad534
diff --git a/tests/page/page-goto.spec.ts b/tests/page/page-goto.spec.tsindex 1683c08bcd..00a7b0a7ac 100644--- a/tests/page/page-goto.spec.ts+++ b/tests/page/page-goto.spec.ts@@ -419,6 +419,95 @@ it('should fail when replaced by another navigation', async ({ page, server, bro}});+it('js redirect overrides url bar navigation ', async ({ page, server, browserName }) => {+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' });+ server.setRoute('/a', (req, res) => {+ res.writeHead(200, { 'content-type': 'text/html' });+ res.end(`+ <body>+ <script>+ setTimeout(() => {+ window.location.pathname = '/c';+ }, 1000);+ </script>+ </body>+ `);+ });+ const events = [];+ server.setRoute('/b', async (req, res) => {+ events.push('started b');+ await new Promise(f => setTimeout(f, 2000));+ res.writeHead(200, { 'content-type': 'text/html' });+ res.end(`BBB`);+ events.push('finished b');+ });+ server.setRoute('/c', async (req, res) => {+ events.push('started c');+ await new Promise(f => setTimeout(f, 2000));+ res.writeHead(200, { 'content-type': 'text/html' });+ res.end(`CCC`);+ events.push('finished c');+ });+ await page.goto(server.PREFIX + '/a');+ const error = await page.goto(server.PREFIX + '/b').then(r => null, e => e);+ const expectEvents = (browserName === 'chromium') ?+ ['started b', 'finished b'] :+ ['started b', 'started c', 'finished b', 'finished c'];+ await expect(() => expect(events).toEqual(expectEvents)).toPass();+ expect(events).toEqual(expectEvents);+ if (browserName === 'chromium') {+ // Chromium prioritizes the url bar navigation over the js redirect.+ expect(error).toBeFalsy();+ expect(page.url()).toBe(server.PREFIX + '/b');+ } else if (browserName === 'webkit') {+ expect(error.message).toContain('Navigation interrupted by another one');+ expect(page.url()).toBe(server.PREFIX + '/c');+ } else if (browserName === 'firefox') {+ expect(error.message).toContain('NS_BINDING_ABORTED');+ expect(page.url()).toBe(server.PREFIX + '/c');+ }+});++it('should succeed on url bar navigation when there is pending navigation', async ({ page, server, browserName }) => {+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21574' });+ server.setRoute('/a', (req, res) => {+ res.writeHead(200, { 'content-type': 'text/html' });+ res.end(`+ <body>+ <script>+ setTimeout(() => {+ window.location.pathname = '/c';+ }, 10);+ </script>+ </body>+ `);+ });+ const events = [];+ server.setRoute('/b', async (req, res) => {+ events.push('started b');+ await new Promise(f => setTimeout(f, 2000));+ res.writeHead(200, { 'content-type': 'text/html' });+ res.end(`BBB`);+ events.push('finished b');+ });+ server.setRoute('/c', async (req, res) => {+ events.push('started c');+ await new Promise(f => setTimeout(f, 2000));+ res.writeHead(200, { 'content-type': 'text/html' });+ res.end(`CCC`);+ events.push('finished c');+ });+ await page.goto(server.PREFIX + '/a');+ await new Promise(f => setTimeout(f, 1000));+ const error = await page.goto(server.PREFIX + '/b').then(r => null, e => e);+ const expectEvents = ['started c', 'started b', 'finished c', 'finished b'];+ await expect(() => expect(events).toEqual(expectEvents)).toPass({ timeout: 5000 });+ expect(events).toEqual(expectEvents);+ expect(error).toBeFalsy();+ expect(page.url()).toBe(server.PREFIX + '/b');+});++it('should work when navigating to valid url', async ({ page, server }) => {const response = await page.goto(server.EMPTY_PAGE);expect(response.ok()).toBe(true);