-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE2edReportExample.ts
More file actions
140 lines (113 loc) · 3.72 KB
/
E2edReportExample.ts
File metadata and controls
140 lines (113 loc) · 3.72 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
setPageCookiesAndNavigateToUrl,
setPageRequestHeadersAndNavigateToUrl,
} from 'autotests/actions';
import {setPageCookies, setPageRequestHeaders} from 'autotests/context';
import {E2edReportExample as E2edReportExampleRoute} from 'autotests/routes/pageRoutes';
import {locator} from 'autotests/selectors';
import {Page} from 'e2ed';
import {click} from 'e2ed/actions';
import {setReadonlyProperty} from 'e2ed/utils';
import {TestRunButton} from './TestRunButton';
import type {Cookie, NavigationReturn, Selector, StringHeaders, Url} from 'e2ed/types';
type CustomPageParams =
| {pageCookies?: readonly Cookie[]; pageRequestHeaders?: StringHeaders}
| undefined;
/**
* The e2ed report example page.
*/
export class E2edReportExample extends Page<CustomPageParams> {
/**
* Page navigation timeout.
*/
static override readonly navigationTimeout = 5_000;
/**
* Page header.
*/
readonly header: Selector = locator('header');
/**
* Logo of `e2ed` in page header.
*/
readonly logo: Selector = locator('logo');
/**
* Navigation bar with test retries.
*/
readonly navigationRetries: Selector = locator('RetriesButtons');
/**
* Button tabs in navigation bar with test retries.
*/
readonly navigationRetriesButton: Selector = this.navigationRetries.findByTestId('RetryButton');
/**
* Selected button tab in navigation bar with test retries.
*/
readonly navigationRetriesButtonSelected: Selector =
this.navigationRetriesButton.filterByLocatorParameter('selected', 'true');
/**
* Cookies that we set (additionally) on a page before navigating to it.
*/
readonly pageCookies!: readonly Cookie[];
/**
* Request headers that we add to page request.
*/
readonly pageRequestHeaders: StringHeaders | undefined;
/**
* Test run button.
*/
readonly testRunButton: Selector = this.testRunsList.findByTestId('TestRunButton');
/**
* List of test runs of retry.
*/
get testRunsList(): Selector {
return locator('column-2');
}
/**
* Set page cookies and page request headers to context before navigate.
*/
override beforeNavigateToPage(): void {
if (this.pageCookies.length !== 0) {
setPageCookies(this.pageCookies);
}
if (this.pageRequestHeaders !== undefined) {
setPageRequestHeaders(this.pageRequestHeaders);
}
}
async clickLogo(): Promise<void> {
await click(this.logo);
}
getRoute(): E2edReportExampleRoute {
return new E2edReportExampleRoute();
}
/**
* Get `TestRunButton` hash (hashed by test `mainParams`).
*/
async getTestRunButtons(): Promise<readonly TestRunButton[]> {
const multiSelector = locator('TestRunButton');
const numberOfPageObjects = await multiSelector.count;
const buttons: TestRunButton[] = [];
for (let index = 0; index < numberOfPageObjects; index += 1) {
const selector = multiSelector.nth(index);
buttons.push(new TestRunButton(selector));
}
return buttons;
}
override init(this: E2edReportExample): void {
const {pageCookies = [], pageRequestHeaders} = this.pageParams ?? {};
setReadonlyProperty(this, 'pageCookies', pageCookies);
setReadonlyProperty(this, 'pageRequestHeaders', pageRequestHeaders);
}
override navigateToPage(url: Url): Promise<NavigationReturn> {
if (this.pageRequestHeaders) {
return setPageRequestHeadersAndNavigateToUrl(url, {
pageRequestHeaders: this.pageRequestHeaders,
timeout: E2edReportExample.navigationTimeout,
});
}
return setPageCookiesAndNavigateToUrl(url, {
pageCookies: this.pageCookies,
timeout: E2edReportExample.navigationTimeout,
});
}
override async waitForPageLoaded(): Promise<void> {
await this.waitForDomContentLoaded();
}
}