-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassertPage.ts
More file actions
51 lines (38 loc) · 1.63 KB
/
assertPage.ts
File metadata and controls
51 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {ADDITIONAL_STEP_TIMEOUT, LogEventStatus, LogEventType} from '../../constants/internal';
import {step} from '../../step';
import {assertValueIsDefined} from '../../utils/asserts';
import {getDocumentUrl} from '../../utils/document';
import {createPageInstance} from '../../utils/pageObjects';
import type {AnyPageClassType, NavigateToOrAssertPageArgs} from '../../types/internal';
/**
* Asserts that we are on the expected page by page parameters.
*/
export const assertPage = async <SomePageClass extends AnyPageClassType>(
...args: NavigateToOrAssertPageArgs<SomePageClass>
): Promise<InstanceType<SomePageClass>> => {
const [PageClass, pageParams] = args;
let page: InstanceType<SomePageClass> | undefined;
await step(
`Asserts that the document url matches the page "${PageClass.name}"`,
async () => {
page = await createPageInstance(PageClass, pageParams);
const route = page.getRoute();
await page.beforeAssertPage?.();
await page.waitForPageLoaded();
const documentUrl = await getDocumentUrl();
const isMatch = route.isMatchUrl(documentUrl);
const logEventStatus = isMatch ? LogEventStatus.Passed : LogEventStatus.Failed;
const {routeParams} = route;
await page.assertPage(isMatch, documentUrl);
await page.afterAssertPage?.();
return {documentUrl, isMatch, logEventStatus, routeParams};
},
{
payload: {pageParams},
timeout: PageClass.navigationTimeout + ADDITIONAL_STEP_TIMEOUT,
type: LogEventType.InternalAction,
},
);
assertValueIsDefined(page, 'page is defined', {name: PageClass.name, pageParams});
return page;
};