Issue 1:
System info

Playwright Version: [v1.36.1]

Operating System: [Windows 10]

Browser: [Chromium, Firefox, WebKit]

Other info:

Source code

I provided exact source code that allows reproducing the issue locally.

Config file

import { defineConfig, devices } from '@playwright/test';
import dotenv from 'dotenv';
dotenv.config();

export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
trace: 'on-first-retry',
},

projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},
],
});

Test file (self-contained)

import {test, expect} from '@playwright/test';

const check = async(page) => {
await expect(page.getByText(String(null))).toHaveCount(0);
await expect(page.getByText(String(undefined))).toHaveCount(0);
await expect(page.getByText(String(0), {exact: true})).toHaveCount(0);
}

test('function', async ({ page }) => {
await page.goto('https://example.com');
await expect(page.locator("body > div > h1")).toHaveText("Example Domain");
check(page);
});

test('direct call', async ({ page }) => {
await page.goto('https://example.com');
await expect(page.locator("body > div > h1")).toHaveText("Example Domain");

await expect(page.getByText(String(null))).toHaveCount(0);
await expect(page.getByText(String(undefined))).toHaveCount(0);
await expect(page.getByText(String(0), {exact: true})).toHaveCount(0);
});

Steps

Run playwright test --ui

Run playwright test

Expected

The test results are consistent between UI and CI

Actual

the function test fails in CI test.

Issue 2:
System info

Playwright Version: v1.31.2

Operating System: Ubuntu 22.04 LTS

Browser: All

Other info:

This may simply need to be clarified in the docs but it would also be good to know if this is possible.

Source code

I provided exact source code that allows reproducing the issue locally.

Test file (self-contained)

import { Page, test } from '@playwright/test';

test('test intercept request ws', async ({ page }) => {
// doesn't work, no wss traffic is ever intercepted
await page.route('wss://**', async (route, request) => {
console.log('Routing all wss traffic via page: ' + request.url());
const response = await route.fetch();
route.fulfill({ response });
});

// also doesn't work, no ws traffic is ever intercepted
await page.context().route('ws://**', async (route, request) => {
console.log('Routing all ws traffic via context: ' + request.url());
const response = await route.fetch();
route.fulfill({ response });
});

// await request.get('ws://127.0.0.1:3030/ws');
// await request.get('ws://127.0.0.1:3030');
// await request.get('wss://127.0.0.1:3030');
await request.get('wss://127.0.0.1:3030/ws');
});

Steps

Run the test

Expected

The router should pickup requests made to the web socket server URL.

Actual

The router never picks up the requests. I would like to route requests away from a remote web socket serve to a locally hosted one.

I believe this bug is sort of related to #21816 as well as the full WebSocket routing open feature request #4488 -- I was hoping for a way to simply redirect the GET request to the WebSocket server URL with route() -- low hanging fruit compared to the full message mocking and intercepting I think is required to delivery the feature request.