refactor: locators, tests, new request design

This commit is contained in:
Siddharth Gelera
2025-10-01 13:28:58 +05:30
parent 0ed2ec1e20
commit e805beaf83
6 changed files with 74 additions and 69 deletions

View File

@@ -1,6 +1,6 @@
import { Page } from '../../../playwright';
export const buildCommonLocators = (page: Page) => ({
export const buildWebsocketCommonLocators = (page: Page) => ({
runner: () => page.getByTestId('run-button'),
saveButton: () => page
.locator('.infotip')

View File

@@ -1,5 +1,5 @@
import { expect, test } from '../../playwright';
import { buildCommonLocators } from './lib/locators';
import { buildWebsocketCommonLocators } from '../utils/page/locators';
const MAX_CONNECTION_TIME = 3000;
const BRU_FILE_NAME = /^ws-test-request$/;
@@ -12,7 +12,7 @@ test.describe.serial('websockets', () => {
});
test('websocket connects', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
await page.getByTitle(BRU_FILE_NAME).click();
await locators.connectionControls.connect().click();
@@ -23,14 +23,14 @@ test.describe.serial('websockets', () => {
});
test('websocket closes', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildCommonLocators(page);
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 = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
const messages = await locators.messages();
@@ -39,7 +39,7 @@ test.describe.serial('websockets', () => {
});
test('websocket messages sorting can be changed', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
await locators.toolbar.latestLast().click();
@@ -54,7 +54,7 @@ test.describe.serial('websockets', () => {
});
test('websocket request can send messages', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
await locators.toolbar.clearResponse().click();
await locators.runner().click();

View File

@@ -1,11 +1,11 @@
import { test, expect } from '../../playwright';
import { buildCommonLocators } from './lib/locators';
import { buildWebsocketCommonLocators } from '../utils/page/locators';
const BRU_FILE_NAME = /^ws-test-request-with-headers$/;
test.describe.serial('headers', () => {
test('headers are returned if passed', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
await page.locator('#sidebar-collection-name').click();
await page.getByTitle(BRU_FILE_NAME).click();

View File

@@ -1,5 +1,5 @@
import { expect, Locator, test } from '../../playwright';
import { buildCommonLocators } from './lib/locators';
import { buildWebsocketCommonLocators } from '../utils/page/locators';
import { readFile, writeFile } from 'fs/promises';
import { join } from 'path';
@@ -33,7 +33,7 @@ test.describe.serial('persistence', () => {
test('save new websocket url', async ({ pageWithUserData: page }) => {
const replacementUrl = 'ws://localhost:8082';
const locators = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
const unsavedColor = '#d97706';
const getSaveSvg = () => locators.saveButton().evaluate((d) => d.querySelector('svg'));

View File

@@ -1,11 +1,11 @@
import { test, expect } from '../../playwright';
import { buildCommonLocators } from './lib/locators';
import { buildWebsocketCommonLocators } from '../utils/page/locators';
const BRU_FILE_NAME = /^ws-test-request-with-subproto$/;
test.describe.serial('headers', () => {
test('headers are returned if passed', async ({ pageWithUserData: page, restartApp }) => {
const locators = buildCommonLocators(page);
const locators = buildWebsocketCommonLocators(page);
const clearText = async (text: string) => {
for (let i = text.length; i > 0; i--) {
await page.keyboard.press('Backspace');