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: do not rely on localhost in tests (#36545)
Max Schmitt86bd3ebd9700
diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.tsindex 23beb0d186..07139c5484 100644--- a/tests/library/browsercontext-fetch.spec.ts+++ b/tests/library/browsercontext-fetch.spec.ts@@ -439,7 +439,7 @@ it('should handle cookies on redirects', async ({ context, server, browserName,'sameSite': (browserName === 'webkit' && isWindows) ? 'None' : 'Lax','name': 'r2','value': 'v2',- 'domain': 'localhost',+ 'domain': server.HOSTNAME,'path': '/a/b','expires': -1,'httpOnly': false,@@ -449,7 +449,7 @@ it('should handle cookies on redirects', async ({ context, server, browserName,'sameSite': (browserName === 'webkit' && isWindows) ? 'None' : 'Lax','name': 'r1','value': 'v1',- 'domain': 'localhost',+ 'domain': server.HOSTNAME,'path': '/','expires': -1,'httpOnly': false,diff --git a/tests/library/browsercontext-route.spec.ts b/tests/library/browsercontext-route.spec.tsindex 25d965c1b6..f3ff553888 100644--- a/tests/library/browsercontext-route.spec.ts+++ b/tests/library/browsercontext-route.spec.ts@@ -170,7 +170,7 @@ it('should use Set-Cookie header in future requests', async ({ contextFactory, ssameSite: defaultSameSiteCookieValue,name: 'name',value: 'value',- domain: 'localhost',+ domain: server.HOSTNAME,path: '/',expires: -1,httpOnly: false,diff --git a/tests/library/channels.spec.ts b/tests/library/channels.spec.tsindex cb51e36504..827f9fe0b9 100644--- a/tests/library/channels.spec.ts+++ b/tests/library/channels.spec.ts@@ -248,9 +248,9 @@ it('should work with the domain module', async ({ browserType, server, browserNalet callback;const result = new Promise(f => callback = f);page.on('websocket', ws => ws.on('socketerror', callback));- void page.evaluate(port => {- new WebSocket('ws://localhost:' + port + '/bogus-ws');- }, server.PORT);+ void page.evaluate(host => {+ new WebSocket('ws://' + host + '/bogus-ws');+ }, server.HOST);const message = await result;if (browserName === 'firefox')expect(message).toBe('CLOSE_ABNORMAL');diff --git a/tests/library/defaultbrowsercontext-1.spec.ts b/tests/library/defaultbrowsercontext-1.spec.tsindex 5db50f8e31..72d355ca92 100644--- a/tests/library/defaultbrowsercontext-1.spec.ts+++ b/tests/library/defaultbrowsercontext-1.spec.ts@@ -36,7 +36,7 @@ it('context.cookies() should work @smoke', async ({ server, launchPersistent, deexpect(maybeFilterCookies(channel, await page.context().cookies())).toEqual([{name: 'username',value: 'John Doe',- domain: 'localhost',+ domain: server.HOSTNAME,path: '/',expires: -1,httpOnly: false,@@ -58,7 +58,7 @@ it('context.addCookies() should work', async ({ server, launchPersistent, browseexpect(maybeFilterCookies(channel, await page.context().cookies())).toEqual([{name: 'username',value: 'John Doe',- domain: 'localhost',+ domain: server.HOSTNAME,path: '/',expires: -1,httpOnly: false,diff --git a/tests/library/modernizr.spec.ts b/tests/library/modernizr.spec.tsindex d4da802d89..0a42c39e8c 100644--- a/tests/library/modernizr.spec.ts+++ b/tests/library/modernizr.spec.ts@@ -14,12 +14,14 @@* limitations under the License.*/+import type { BrowserContext } from 'playwright-core';+import type { TestServer } from '../config/testserver';import { hostPlatform } from '../../packages/playwright-core/src/server/utils/hostPlatform';import { browserTest as it, expect } from '../config/browserTest';import fs from 'fs';import os from 'os';-async function checkFeatures(name: string, context: any, server: any) {+async function checkFeatures(name: string, context: BrowserContext, server: TestServer): Promise<any> {try {const page = await context.newPage();await page.goto(server.PREFIX + '/modernizr/index.html');@@ -31,14 +33,15 @@ async function checkFeatures(name: string, context: any, server: any) {}}-it('Safari Desktop', async ({ browser, browserName, platform, server, headless }) => {+it('Safari Desktop', async ({ browser, browserName, platform, httpsServer, headless }) => {it.skip(browserName !== 'webkit');it.skip(browserName === 'webkit' && platform === 'darwin' && os.arch() === 'x64', 'Modernizr uses WebGL which is not available on Intel macOS - https://bugs.webkit.org/show_bug.cgi?id=278277');it.skip(browserName === 'webkit' && hostPlatform.startsWith('ubuntu20.04'), 'Ubuntu 20.04 is frozen');const context = await browser.newContext({- deviceScaleFactor: 2+ deviceScaleFactor: 2,+ ignoreHTTPSErrors: true,});- const { actual, expected } = await checkFeatures('safari-18', context, server);+ const { actual, expected } = await checkFeatures('safari-18', context, httpsServer);expected.pushmanager = false;expected.devicemotion2 = false;@@ -88,13 +91,16 @@ it('Safari Desktop', async ({ browser, browserName, platform, server, headless }expect(actual).toEqual(expected);});-it('Mobile Safari', async ({ playwright, browser, browserName, platform, server, headless }) => {+it('Mobile Safari', async ({ playwright, browser, browserName, platform, httpsServer, headless }) => {it.skip(browserName !== 'webkit');it.skip(browserName === 'webkit' && platform === 'darwin' && os.arch() === 'x64', 'Modernizr uses WebGL which is not available on Intel macOS - https://bugs.webkit.org/show_bug.cgi?id=278277');it.skip(browserName === 'webkit' && hostPlatform.startsWith('ubuntu20.04'), 'Ubuntu 20.04 is frozen');const iPhone = playwright.devices['iPhone 12'];- const context = await browser.newContext(iPhone);- const { actual, expected } = await checkFeatures('mobile-safari-18', context, server);+ const context = await browser.newContext({+ ...iPhone,+ ignoreHTTPSErrors: true,+ });+ const { actual, expected } = await checkFeatures('mobile-safari-18', context, httpsServer);{// All platforms.diff --git a/tests/library/proxy.spec.ts b/tests/library/proxy.spec.tsindex 93313d2222..6eea7479f1 100644--- a/tests/library/proxy.spec.ts+++ b/tests/library/proxy.spec.ts@@ -33,7 +33,7 @@ it('should use proxy @smoke', async ({ browserType, server, mode }) => {res.end('<html><title>Served by the proxy</title></html>');});const browser = await browserType.launch({- proxy: { server: `localhost:${server.PORT}` }+ proxy: { server: server.HOST }});const page = await browser.newPage();await page.goto('http://non-existent.com/target.html');@@ -135,7 +135,7 @@ it('should authenticate', async ({ browserType, server }) => {}});const browser = await browserType.launch({- proxy: { server: `localhost:${server.PORT}`, username: 'user', password: 'secret' }+ proxy: { server: server.HOST, username: 'user', password: 'secret' }});const page = await browser.newPage();await page.goto('http://non-existent.com/target.html');@@ -167,7 +167,7 @@ it('should work with authenticate followed by redirect', async ({ browserName, bres.end('<html><title>Served by the proxy</title></html>');});const browser = await browserType.launch({- proxy: { server: `localhost:${server.PORT}`, username: 'user', password: 'secret' }+ proxy: { server: server.HOST, username: 'user', password: 'secret' }});const page = await browser.newPage();await page.goto('http://non-existent.com/page1.html');@@ -184,7 +184,7 @@ it('should exclude patterns', async ({ browserType, server, browserName, headles//// @see https://gist.github.com/CollinChaffin/24f6c9652efb3d6d5ef2f5502720ef00const browser = await browserType.launch({- proxy: { server: `localhost:${server.PORT}`, bypass: '1.non.existent.domain.for.the.test, 2.non.existent.domain.for.the.test, .another.test' }+ proxy: { server: server.HOST, bypass: '1.non.existent.domain.for.the.test, 2.non.existent.domain.for.the.test, .another.test' }});{diff --git a/tests/library/snapshotter.spec.ts b/tests/library/snapshotter.spec.tsindex 3e9cfce46f..9eb839b7e8 100644--- a/tests/library/snapshotter.spec.ts+++ b/tests/library/snapshotter.spec.ts@@ -30,7 +30,7 @@ it.describe('snapshots', () => {it('should collect snapshot', async ({ page, toImpl, snapshotter }) => {await page.setContent('<button>Hello</button>');const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot)).toBe('<BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot, page.url())).toBe('<BUTTON>Hello</BUTTON>');});it('should preserve BASE and other content on reset', async ({ page, toImpl, snapshotter, server }) => {@@ -51,7 +51,7 @@ it.describe('snapshots', () => {});await page.setContent('<link rel="stylesheet" href="style.css"><button>Hello</button>');const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- const resource = snapshot.resourceByUrl(`http://localhost:${server.PORT}/style.css`, 'GET');+ const resource = snapshot.resourceByUrl(`${server.PREFIX}/style.css`, 'GET');expect(resource).toBeTruthy();});@@ -65,11 +65,11 @@ it.describe('snapshots', () => {it('should respect inline CSSOM change', async ({ page, toImpl, snapshotter }) => {await page.setContent('<style>button { color: red; }</style><button>Hello</button>');const snapshot1 = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot1)).toBe('<STYLE>button { color: red; }</STYLE><BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot1, page.url())).toBe('<STYLE>button { color: red; }</STYLE><BUTTON>Hello</BUTTON>');await page.evaluate(() => { (document.styleSheets[0].cssRules[0] as any).style.color = 'blue'; });const snapshot2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');- expect(distillSnapshot(snapshot2)).toBe('<STYLE>button { color: blue; }</STYLE><BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot2, page.url())).toBe('<STYLE>button { color: blue; }</STYLE><BUTTON>Hello</BUTTON>');});it('should respect CSSOM change through CSSGroupingRule', async ({ page, toImpl, snapshotter }) => {@@ -79,33 +79,33 @@ it.describe('snapshots', () => {void 0;});const snapshot1 = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot1)).toBe('<STYLE>@media {\n button { color: red; }\n}</STYLE><BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot1, page.url())).toBe('<STYLE>@media {\n button { color: red; }\n}</STYLE><BUTTON>Hello</BUTTON>');await page.evaluate(() => { window['rule'].cssRules[0].style.color = 'blue'; });const snapshot2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');- expect(distillSnapshot(snapshot2)).toBe('<STYLE>@media {\n button { color: blue; }\n}</STYLE><BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot2, page.url())).toBe('<STYLE>@media {\n button { color: blue; }\n}</STYLE><BUTTON>Hello</BUTTON>');await page.evaluate(() => { window['rule'].insertRule('button { color: green; }', 1); });const snapshot3 = await snapshotter.captureSnapshot(toImpl(page), 'call@3', 'snapshot@call@3');- expect(distillSnapshot(snapshot3)).toBe('<STYLE>@media {\n button { color: blue; }\n button { color: green; }\n}</STYLE><BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot3, page.url())).toBe('<STYLE>@media {\n button { color: blue; }\n button { color: green; }\n}</STYLE><BUTTON>Hello</BUTTON>');});it('should respect node removal', async ({ page, toImpl, snapshotter }) => {await page.setContent('<div><button id="button1"></button><button id="button2"></button></div>');const snapshot1 = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot1)).toBe('<DIV><BUTTON id=\"button1\"></BUTTON><BUTTON id=\"button2\"></BUTTON></DIV>');+ expect(distillSnapshot(snapshot1, page.url())).toBe('<DIV><BUTTON id=\"button1\"></BUTTON><BUTTON id=\"button2\"></BUTTON></DIV>');await page.evaluate(() => document.getElementById('button2').remove());const snapshot2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');- expect(distillSnapshot(snapshot2)).toBe('<DIV><BUTTON id=\"button1\"></BUTTON></DIV>');+ expect(distillSnapshot(snapshot2, page.url())).toBe('<DIV><BUTTON id=\"button1\"></BUTTON></DIV>');});it('should respect attr removal', async ({ page, toImpl, snapshotter }) => {await page.setContent('<div id="div" attr1="1" attr2="2"></div>');const snapshot1 = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot1)).toBe('<DIV id=\"div\" attr1=\"1\" attr2=\"2\"></DIV>');+ expect(distillSnapshot(snapshot1, page.url())).toBe('<DIV id=\"div\" attr1=\"1\" attr2=\"2\"></DIV>');await page.evaluate(() => document.getElementById('div').removeAttribute('attr2'));const snapshot2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');- expect(distillSnapshot(snapshot2)).toBe('<DIV id=\"div\" attr1=\"1\"></DIV>');+ expect(distillSnapshot(snapshot2, page.url())).toBe('<DIV id=\"div\" attr1=\"1\"></DIV>');});it('should have a custom doctype', async ({ page, server, toImpl, snapshotter }) => {@@ -113,21 +113,21 @@ it.describe('snapshots', () => {await page.setContent('<!DOCTYPE foo><body>hi</body>');const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot)).toBe('<!DOCTYPE foo>hi');+ expect(distillSnapshot(snapshot, page.url())).toBe('<!DOCTYPE foo>hi');});it('should replace meta charset attr that specifies charset', async ({ page, server, toImpl, snapshotter }) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<meta charset="shift-jis" />');const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot)).toBe('<META charset="utf-8">');+ expect(distillSnapshot(snapshot, page.url())).toBe('<META charset="utf-8">');});it('should replace meta content attr that specifies charset', async ({ page, server, toImpl, snapshotter }) => {await page.goto(server.EMPTY_PAGE);await page.setContent('<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot)).toBe('<META http-equiv="Content-Type" content="text/html; charset=utf-8">');+ expect(distillSnapshot(snapshot, page.url())).toBe('<META http-equiv="Content-Type" content="text/html; charset=utf-8">');});it('should respect subresource CSSOM change', async ({ page, server, toImpl, snapshotter }) => {@@ -138,11 +138,11 @@ it.describe('snapshots', () => {await page.setContent('<link rel="stylesheet" href="style.css"><button>Hello</button>');const snapshot1 = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot1)).toBe('<LINK rel=\"stylesheet\" href=\"style.css\"><BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot1, page.url())).toBe('<LINK rel=\"stylesheet\" href=\"style.css\"><BUTTON>Hello</BUTTON>');await page.evaluate(() => { (document.styleSheets[0].cssRules[0] as any).style.color = 'blue'; });const snapshot2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');- const resource = snapshot2.resourceByUrl(`http://localhost:${server.PORT}/style.css`, 'GET');+ const resource = snapshot2.resourceByUrl(`${server.PREFIX}/style.css`, 'GET');expect((await snapshotter.resourceContentForTest(resource.response.content._sha1)).toString()).toBe('button { color: blue; }');});@@ -163,7 +163,7 @@ it.describe('snapshots', () => {for (let counter = 0; ; ++counter) {const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@' + counter, 'snapshot@call@' + counter);- const text = distillSnapshot(snapshot).replace(/frame@[^"]+["]/, '<id>"');+ const text = distillSnapshot(snapshot, page.url()).replace(/frame@[^"]+["]/, '<id>"');if (text === '<FRAMESET><FRAME __playwright_src__=\"/snapshot/<id>\"></FRAME></FRAMESET>')break;await page.waitForTimeout(250);@@ -188,7 +188,7 @@ it.describe('snapshots', () => {// Marking iframe hierarchy is racy, do not expect snapshot, wait for it.for (let counter = 0; ; ++counter) {const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@' + counter, 'snapshot@call@' + counter);- const text = distillSnapshot(snapshot).replace(/frame@[^"]+["]/, '<id>"');+ const text = distillSnapshot(snapshot, page.url()).replace(/frame@[^"]+["]/, '<id>"');if (text === '<IFRAME __playwright_src__=\"/snapshot/<id>\"></IFRAME>')break;await page.waitForTimeout(250);@@ -208,7 +208,7 @@ it.describe('snapshots', () => {// Marking iframe hierarchy is racy, do not expect snapshot, wait for it.for (let counter = 0; ; ++counter) {const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@' + counter, 'snapshot@call@' + counter);- const text = distillSnapshot(snapshot).replace(/frame@[^"]+["]/, '<id>"');+ const text = distillSnapshot(snapshot, page.url()).replace(/frame@[^"]+["]/, '<id>"');if (text === '<IFRAME __playwright_src__=\"/snapshot/<id>\"></IFRAME>')break;await page.waitForTimeout(250);@@ -219,22 +219,22 @@ it.describe('snapshots', () => {await page.setContent('<button>Hello</button>');{const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot)).toBe('<BUTTON>Hello</BUTTON>');+ expect(distillSnapshot(snapshot, page.url())).toBe('<BUTTON>Hello</BUTTON>');}const handle = await page.$('text=Hello')!;await handle.evaluate(element => element.setAttribute('data', 'one'));{const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');- expect(distillSnapshot(snapshot)).toBe('<BUTTON data="one">Hello</BUTTON>');+ expect(distillSnapshot(snapshot, page.url())).toBe('<BUTTON data="one">Hello</BUTTON>');}await handle.evaluate(element => element.setAttribute('data', 'two'));{const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@3', 'snapshot@call@3');- expect(distillSnapshot(snapshot)).toBe('<BUTTON data="two">Hello</BUTTON>');+ expect(distillSnapshot(snapshot, page.url())).toBe('<BUTTON data="two">Hello</BUTTON>');}});- it('empty adopted style sheets should not prevent node refs', async ({ page, toImpl, snapshotter, browserName }) => {+ it('empty adopted style sheets should not prevent node refs', async ({ page, toImpl, snapshotter }) => {await page.setContent('<button>Hello</button>');await page.evaluate(() => {const sheet = new CSSStyleSheet();@@ -253,7 +253,7 @@ it.describe('snapshots', () => {const renderer1 = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');// Expect some adopted style sheets.- expect(distillSnapshot(renderer1)).toContain('__playwright_style_sheet_');+ expect(distillSnapshot(renderer1, page.url())).toContain('__playwright_style_sheet_');const renderer2 = await snapshotter.captureSnapshot(toImpl(page), 'call@2', 'snapshot@call@2');const snapshot2 = renderer2.snapshot();@@ -264,11 +264,11 @@ it.describe('snapshots', () => {it('should not navigate on anchor clicks', async ({ page, toImpl, snapshotter }) => {await page.setContent('<a href="https://example.com">example.com</a>');const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'call@1', 'snapshot@call@1');- expect(distillSnapshot(snapshot)).toBe('<A href="link://https://example.com">example.com</A>');+ expect(distillSnapshot(snapshot, page.url())).toBe('<A href="link://https://example.com">example.com</A>');});});-function distillSnapshot(snapshot, options: { distillTarget: boolean, distillBoundingRect: boolean } = { distillTarget: true, distillBoundingRect: true }) {+function distillSnapshot(snapshot, url: string, options: { distillTarget: boolean, distillBoundingRect: boolean } = { distillTarget: true, distillBoundingRect: true }) {let { html } = snapshot.render();if (options.distillTarget)html = html.replace(/\s__playwright_target__="[^"]+"/g, '');@@ -279,7 +279,7 @@ function distillSnapshot(snapshot, options: { distillTarget: boolean, distillBou.replace(/<script>[.\s\S]+<\/script>/, '').replace(/<style>.*__playwright_target__.*?<\/style>/, '').replace(/<BASE href="about:blank">/, '')- .replace(/<BASE href="http:\/\/localhost:[\d]+\/empty.html">/, '')+ .replace(new RegExp(`<BASE href="${url}">`), '').replace(/<HTML>/, '').replace(/<\/HTML>/, '').replace(/<HEAD>/, '')diff --git a/tests/library/web-socket.spec.ts b/tests/library/web-socket.spec.tsindex 94b8ff1b2b..106682411e 100644--- a/tests/library/web-socket.spec.ts+++ b/tests/library/web-socket.spec.ts@@ -21,13 +21,13 @@ import { Server as WebSocketServer } from 'ws';it('should work @smoke', async ({ page, server }) => {server.sendOnWebSocketConnection('incoming');- const value = await page.evaluate(port => {+ const value = await page.evaluate(host => {let cb;const result = new Promise(f => cb = f);- const ws = new WebSocket('ws://localhost:' + port + '/ws');+ const ws = new WebSocket('ws://' + host + '/ws');ws.addEventListener('message', data => { ws.close(); cb(data.data); });return result;- }, server.PORT);+ }, server.HOST);expect(value).toBe('incoming');});@@ -41,12 +41,12 @@ it('should emit close events', async ({ page, server }) => {webSocket = ws;ws.on('close', () => { log.push('close'); socketClosed(); });});- await page.evaluate(port => {- const ws = new WebSocket('ws://localhost:' + port + '/ws');+ await page.evaluate(host => {+ const ws = new WebSocket('ws://' + host + '/ws');ws.addEventListener('open', () => ws.close());- }, server.PORT);+ }, server.HOST);await socketClosePromise;- expect(log.join(':')).toBe(`open<ws://localhost:${server.PORT}/ws>:close`);+ expect(log.join(':')).toBe(`open<ws://${server.HOST}/ws>:close`);expect(webSocket.isClosed()).toBeTruthy();});@@ -63,12 +63,12 @@ it('should emit frame events', async ({ page, server }) => {ws.on('framereceived', d => log.push('received<' + d.payload + '>'));ws.on('close', () => { log.push('close'); socketClosed(); });});- await page.evaluate(port => {- const ws = new WebSocket('ws://localhost:' + port + '/ws');+ await page.evaluate(host => {+ const ws = new WebSocket('ws://' + host + '/ws');ws.addEventListener('open', () => ws.send('outgoing'));ws.addEventListener('message', () => { ws.close(); });(window as any).ws = ws;- }, server.PORT);+ }, server.HOST);await socketClosePromise;expect(log).toEqual(['open', 'sent<outgoing>', 'received<incoming>', 'close']);});@@ -87,11 +87,11 @@ it('should filter out the close events when the server closes with a message', aws.on('framereceived', d => log.push('received<' + d.payload + '>'));ws.on('close', () => { log.push('close'); socketClosed(); });});- await page.evaluate(port => {- const ws = new WebSocket('ws://localhost:' + port + '/ws');+ await page.evaluate(host => {+ const ws = new WebSocket('ws://' + host + '/ws');ws.addEventListener('message', () => ws.send('outgoing'));(window as any).ws = ws;- }, server.PORT);+ }, server.HOST);await socketClosePromise;expect(log).toEqual(['open', 'received<incoming>', 'sent<outgoing>', 'close']);});@@ -104,10 +104,10 @@ it('should pass self as argument to close event', async ({ page, server }) => {webSocket = ws;ws.on('close', socketClosed);});- await page.evaluate(port => {- const ws = new WebSocket('ws://localhost:' + port + '/ws');+ await page.evaluate(host => {+ const ws = new WebSocket('ws://' + host + '/ws');ws.addEventListener('open', () => ws.close());- }, server.PORT);+ }, server.HOST);const eventArg = await socketClosePromise;expect(eventArg).toBe(webSocket);});@@ -120,8 +120,8 @@ it('should emit binary frame events', async ({ page, server }) => {ws.on('close', doneCallback);ws.on('framesent', d => sent.push(d.payload));});- await page.evaluate(port => {- const ws = new WebSocket('ws://localhost:' + port + '/ws');+ await page.evaluate(host => {+ const ws = new WebSocket('ws://' + host + '/ws');ws.addEventListener('open', () => {const binary = new Uint8Array(5);for (let i = 0; i < 5; ++i)@@ -130,7 +130,7 @@ it('should emit binary frame events', async ({ page, server }) => {ws.send(binary);ws.close();});- }, server.PORT);+ }, server.HOST);await donePromise;expect(sent[0]).toBe('text');for (let i = 0; i < 5; ++i)@@ -141,9 +141,9 @@ it('should emit error', async ({ page, server, browserName, channel }) => {let callback;const result = new Promise(f => callback = f);page.on('websocket', ws => ws.on('socketerror', callback));- await page.evaluate(port => {- new WebSocket('ws://localhost:' + port + '/bogus-ws');- }, server.PORT);+ await page.evaluate(host => {+ new WebSocket('ws://' + host + '/bogus-ws');+ }, server.HOST);const message = await result;if (browserName === 'firefox')expect(message).toBe('CLOSE_ABNORMAL');@@ -160,9 +160,9 @@ it('should not have stray error events', async ({ page, server }) => {await ws.waitForEvent('framereceived');return ws;}),- page.evaluate(port => {- (window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');- }, server.PORT)+ page.evaluate(host => {+ (window as any).ws = new WebSocket('ws://' + host + '/ws');+ }, server.HOST)]);await page.evaluate('window.ws.close()');expect(error).toBeFalsy();@@ -175,9 +175,9 @@ it('should reject waitForEvent on socket close', async ({ page, server }) => {await ws.waitForEvent('framereceived');return ws;}),- page.evaluate(port => {- (window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');- }, server.PORT)+ page.evaluate(host => {+ (window as any).ws = new WebSocket('ws://' + host + '/ws');+ }, server.HOST)]);const error = ws.waitForEvent('framesent').catch(e => e);await page.evaluate('window.ws.close()');@@ -191,9 +191,9 @@ it('should reject waitForEvent on page close', async ({ page, server }) => {await ws.waitForEvent('framereceived');return ws;}),- page.evaluate(port => {- (window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');- }, server.PORT)+ page.evaluate(host => {+ (window as any).ws = new WebSocket('ws://' + host + '/ws');+ }, server.HOST)]);const error = ws.waitForEvent('framesent').catch(e => e);await page.close();diff --git a/tests/page/frame-hierarchy.spec.ts b/tests/page/frame-hierarchy.spec.tsindex 3b8f0fb19b..46e9dace1a 100644--- a/tests/page/frame-hierarchy.spec.ts+++ b/tests/page/frame-hierarchy.spec.ts@@ -20,7 +20,7 @@ import { attachFrame, detachFrame } from '../config/utils';import type { Frame } from 'playwright-core';function dumpFrames(frame: Frame, indentation: string = ''): string[] {- let description = frame.url().replace(/:\d+\//, ':<PORT>/');+ let description = frame.url();if (frame.name())description += ' (' + frame.name() + ')';const result = [indentation + description];@@ -40,11 +40,11 @@ it('should handle nested frames @smoke', async ({ page, server, isAndroid }) =>await page.goto(server.PREFIX + '/frames/nested-frames.html');expect(dumpFrames(page.mainFrame())).toEqual([- 'http://localhost:<PORT>/frames/nested-frames.html',- ' http://localhost:<PORT>/frames/frame.html (aframe)',- ' http://localhost:<PORT>/frames/two-frames.html (2frames)',- ' http://localhost:<PORT>/frames/frame.html (dos)',- ' http://localhost:<PORT>/frames/frame.html (uno)',+ `${server.PREFIX}/frames/nested-frames.html`,+ ` ${server.PREFIX}/frames/frame.html (aframe)`,+ ` ${server.PREFIX}/frames/two-frames.html (2frames)`,+ ` ${server.PREFIX}/frames/frame.html (dos)`,+ ` ${server.PREFIX}/frames/frame.html (uno)`,]);});