Files
bruno/tests/websockets/connection.spec.ts
2025-10-01 13:28:58 +05:30

69 lines
2.6 KiB
TypeScript

import { expect, test } from '../../playwright';
import { buildWebsocketCommonLocators } from '../utils/page/locators';
const MAX_CONNECTION_TIME = 3000;
const BRU_FILE_NAME = /^ws-test-request$/;
test.describe.serial('websockets', () => {
test('websocket requests are visible', async ({ pageWithUserData: page, restartApp }) => {
await page.locator('#sidebar-collection-name').click();
expect(page.locator('span.item-name').filter({ hasText: BRU_FILE_NAME })).toBeVisible();
});
test('websocket connects', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildWebsocketCommonLocators(page);
await page.getByTitle(BRU_FILE_NAME).click();
await locators.connectionControls.connect().click();
await expect(locators.connectionControls.disconnect()).toBeAttached({
timeout: MAX_CONNECTION_TIME
});
});
test('websocket closes', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildWebsocketCommonLocators(page);
await locators.connectionControls.disconnect().click();
await expect(locators.connectionControls.connect()).toBeVisible();
});
test('websocket messages were recorded', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildWebsocketCommonLocators(page);
const messages = await locators.messages();
expect(messages[0].getByText('Connected to ws://')).toBeAttached();
expect(messages[1].getByText('Closed')).toBeAttached();
});
test('websocket messages sorting can be changed', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildWebsocketCommonLocators(page);
await locators.toolbar.latestLast().click();
const messages = await locators.messages();
expect(messages[0].getByText('Closed')).toBeAttached();
expect(messages[1].getByText('Connected to ws://')).toBeAttached();
await locators.toolbar.latestFirst().click();
const messagesReset = await locators.messages();
expect(messagesReset[0].getByText('Connected to ws://')).toBeAttached();
expect(messagesReset[1].getByText('Closed')).toBeAttached();
});
test('websocket request can send messages', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildWebsocketCommonLocators(page);
await locators.toolbar.clearResponse().click();
await locators.runner().click();
const messages = await locators.messages();
expect(await messages[1].locator('.text-ellipsis').innerText()).toMatch('{ "foo": "bar" }');
expect(await messages[2].locator('.text-ellipsis').innerText()).toMatch('{ "data": { "foo": "bar" } }');
});
});