Skip to content

Commit 18f4acf

Browse files
authored
Merge pull request #118 from joomcode/feat/add-step-function
feat: add function `step` to public API
2 parents 1d0c550 + d95d503 commit 18f4acf

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

autotests/pageObjects/pages/Main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class Main extends Page<CustomPageParams> {
7070
url.startsWith('https://browser.events.data.msn.com/') ||
7171
url.startsWith('https://img-s-msn-com.akamaized.net/') ||
7272
url.startsWith('https://rewards.bing.com/widget/') ||
73+
url.startsWith('https://th.bing.com/th?id=') ||
7374
url.startsWith('https://www.bing.com/th?id=')
7475
) {
7576
return false;

autotests/tests/main/exists.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {test} from 'autotests';
2+
import {getPageCookies} from 'autotests/context';
23
import {Main, Search} from 'autotests/pageObjects/pages';
34
import {Search as SearchRoute} from 'autotests/routes/pageRoutes';
45
import {getFullPackConfig} from 'autotests/utils';
5-
import {expect} from 'e2ed';
6+
import {expect, step} from 'e2ed';
67
import {
78
assertPage,
89
navigateToPage,
@@ -39,6 +40,8 @@ test('exists', {meta: {testId: '1'}, testIdleTimeout: 10_000, testTimeout: 15_00
3940
'dynamic custom pack properties is correct',
4041
).gt(0);
4142

43+
await step('Some step');
44+
4245
const urlObjectPromise = waitForStartOfPageLoad();
4346

4447
const mainPage = await navigateToPage(Main, {language});
@@ -57,6 +60,10 @@ test('exists', {meta: {testId: '1'}, testIdleTimeout: 10_000, testTimeout: 15_00
5760

5861
await expect(mainPage.searchQuery, 'search query on page is empty').eql('');
5962

63+
await step('Another step', () => {
64+
getPageCookies();
65+
});
66+
6067
await mainPage.typeIntoSearchInput(searchQuery);
6168

6269
await expect(mainPage.searchQuery, 'search query on page has setted value').eql(searchQuery);

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export {WebSocketRoute} from './WebSocketRoute';
1515
export {createClientFunction} from './createClientFunction';
1616
export {createTestFunction} from './createTestFunction';
1717
export {expect} from './expect';
18+
export {step} from './step';

src/step.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {LogEventType} from './constants/internal';
2+
import {setCustomInspectOnFunction} from './utils/fn';
3+
import {log} from './utils/log';
4+
5+
import type {MaybePromise} from './types/internal';
6+
7+
import {test as playwrightTest} from '@playwright/test';
8+
9+
type Options = Readonly<{skipLogs?: boolean; timeout?: number}>;
10+
11+
const noop = (): void => {};
12+
13+
/**
14+
* Declares a test step (calls Playwright's `test.step` function inside).
15+
*/
16+
export const step = (
17+
name: string,
18+
body: () => MaybePromise<void> = noop,
19+
options?: Options,
20+
): Promise<void> => {
21+
if (options?.skipLogs !== true) {
22+
if (body !== noop) {
23+
setCustomInspectOnFunction(body);
24+
}
25+
26+
log(name, {body: body === noop ? undefined : body, options}, LogEventType.InternalCore);
27+
}
28+
29+
return playwrightTest.step(name, body, options);
30+
};

0 commit comments

Comments
 (0)