From d95d5030134df14a16b9723093fa71d9652d81f0 Mon Sep 17 00:00:00 2001 From: uid11 Date: Tue, 20 May 2025 16:56:45 +0300 Subject: [PATCH] PRO-10777 feat: add function `step` to public API --- autotests/pageObjects/pages/Main.ts | 1 + autotests/tests/main/exists.ts | 9 ++++++++- src/index.ts | 1 + src/step.ts | 30 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/step.ts diff --git a/autotests/pageObjects/pages/Main.ts b/autotests/pageObjects/pages/Main.ts index 0ae1f1e5..baec21e1 100644 --- a/autotests/pageObjects/pages/Main.ts +++ b/autotests/pageObjects/pages/Main.ts @@ -70,6 +70,7 @@ export class Main extends Page { url.startsWith('https://browser.events.data.msn.com/') || url.startsWith('https://img-s-msn-com.akamaized.net/') || url.startsWith('https://rewards.bing.com/widget/') || + url.startsWith('https://th.bing.com/th?id=') || url.startsWith('https://www.bing.com/th?id=') ) { return false; diff --git a/autotests/tests/main/exists.ts b/autotests/tests/main/exists.ts index cec7f0d5..dedcc880 100644 --- a/autotests/tests/main/exists.ts +++ b/autotests/tests/main/exists.ts @@ -1,8 +1,9 @@ import {test} from 'autotests'; +import {getPageCookies} from 'autotests/context'; import {Main, Search} from 'autotests/pageObjects/pages'; import {Search as SearchRoute} from 'autotests/routes/pageRoutes'; import {getFullPackConfig} from 'autotests/utils'; -import {expect} from 'e2ed'; +import {expect, step} from 'e2ed'; import { assertPage, navigateToPage, @@ -39,6 +40,8 @@ test('exists', {meta: {testId: '1'}, testIdleTimeout: 10_000, testTimeout: 15_00 'dynamic custom pack properties is correct', ).gt(0); + await step('Some step'); + const urlObjectPromise = waitForStartOfPageLoad(); const mainPage = await navigateToPage(Main, {language}); @@ -57,6 +60,10 @@ test('exists', {meta: {testId: '1'}, testIdleTimeout: 10_000, testTimeout: 15_00 await expect(mainPage.searchQuery, 'search query on page is empty').eql(''); + await step('Another step', () => { + getPageCookies(); + }); + await mainPage.typeIntoSearchInput(searchQuery); await expect(mainPage.searchQuery, 'search query on page has setted value').eql(searchQuery); diff --git a/src/index.ts b/src/index.ts index 3d7b8204..43c50413 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,3 +15,4 @@ export {WebSocketRoute} from './WebSocketRoute'; export {createClientFunction} from './createClientFunction'; export {createTestFunction} from './createTestFunction'; export {expect} from './expect'; +export {step} from './step'; diff --git a/src/step.ts b/src/step.ts new file mode 100644 index 00000000..9a455e97 --- /dev/null +++ b/src/step.ts @@ -0,0 +1,30 @@ +import {LogEventType} from './constants/internal'; +import {setCustomInspectOnFunction} from './utils/fn'; +import {log} from './utils/log'; + +import type {MaybePromise} from './types/internal'; + +import {test as playwrightTest} from '@playwright/test'; + +type Options = Readonly<{skipLogs?: boolean; timeout?: number}>; + +const noop = (): void => {}; + +/** + * Declares a test step (calls Playwright's `test.step` function inside). + */ +export const step = ( + name: string, + body: () => MaybePromise = noop, + options?: Options, +): Promise => { + if (options?.skipLogs !== true) { + if (body !== noop) { + setCustomInspectOnFunction(body); + } + + log(name, {body: body === noop ? undefined : body, options}, LogEventType.InternalCore); + } + + return playwrightTest.step(name, body, options); +};