-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexists.ts
More file actions
133 lines (96 loc) · 4.07 KB
/
exists.ts
File metadata and controls
133 lines (96 loc) · 4.07 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
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, step} from 'e2ed';
import {
assertPage,
navigateToPage,
pressKey,
scroll,
takeElementScreenshot,
waitForRequest,
waitForResponse,
waitForStartOfPageLoad,
} from 'e2ed/actions';
import {OK_STATUS_CODE} from 'e2ed/constants';
import {assertFunctionThrows, getDocumentUrl} from 'e2ed/utils';
import type {Url} from 'e2ed/types';
// eslint-disable-next-line max-statements
test('exists', {meta: {testId: '1'}, testIdleTimeout: 12_000, testTimeout: 20_000}, async () => {
const language = 'en';
const searchQuery = 'foo';
const testScrollValue = 200;
await scroll(0, testScrollValue);
assertFunctionThrows(() => {
void window.document;
}, 'assertFunctionThrows works');
const {customPackProperties} = getFullPackConfig();
await expect(customPackProperties.name, 'custom pack properties is correct').eql('allTests');
await expect(
customPackProperties.internalPackRunId,
'dynamic custom pack properties is correct',
).gt(0);
const urlObjectPromise = waitForStartOfPageLoad();
const mainPage = await navigateToPage(Main, {language});
await expect(mainPage.header, 'header is in viewport').toBeInViewport({ratio: 1});
await expect(mainPage.header.textContent, 'header text is ok').ok();
const urlObject = await urlObjectPromise;
await expect(getDocumentUrl(), 'waitForStartOfPageLoad returns correct url object').eql(
urlObject.href as Url,
);
await expect(mainPage.pageParams, 'pageParams is correct after navigateToPage').eql({
language,
});
await expect(mainPage.searchQuery, 'search query on page is empty').eql('');
await step('Some step', () => {
getPageCookies();
});
await mainPage.typeIntoSearchInput(searchQuery);
await expect(mainPage.searchQuery, 'search query on page has setted value').eql(searchQuery);
await expect(mainPage.body.find('input').exists, 'page contains some input element').ok();
await assertFunctionThrows(async () => {
await takeElementScreenshot(mainPage.body, {path: 'noScreenshot.png', timeout: 10});
}, 'takeElementScreenshot throws an error on timeout end');
await expect(mainPage.body.description, 'selector description is correct').eql('body');
await expect(
mainPage.body.find('input').description,
'description of selector method is correct',
).eql('body.find(input)');
await takeElementScreenshot(mainPage.searchInput.input, {path: 'screenshot.png'});
const searchUrlObjectPromise = waitForStartOfPageLoad();
const requestWithQueryPromise = waitForRequest(({url}) => url.includes(searchQuery));
const successfulResponsePromise = waitForResponse(
({statusCode}) => statusCode === OK_STATUS_CODE,
{includeNavigationRequest: true},
);
await pressKey('Enter');
const [requestWithQuery, successfulResponse] = await Promise.all([
requestWithQueryPromise,
successfulResponsePromise,
]);
await expect(requestWithQuery.url, 'request with query contains search query').contains(
searchQuery,
);
await expect(successfulResponse.statusCode, 'successful response has statusCode = 200').eql(
OK_STATUS_CODE,
);
const searchPage = await assertPage(Search, {searchQuery});
const searchUrlObject = await searchUrlObjectPromise;
/**
* Do not use the following pageParams and url (by getParamsFromUrlOrThrow) checks in your code.
* These are e2ed internal checks. Use `assertPage` instead.
*/
await expect(searchPage.pageParams, 'pageParams is correct after assertPage').eql({
searchQuery,
});
const url = await getDocumentUrl();
await expect(url, 'waitForStartOfPageLoad returns correct url object').eql(
searchUrlObject.href as Url,
);
await expect(SearchRoute.getParamsFromUrlOrThrow(url), 'page url has expected params').eql({
searchQuery,
});
await expect(searchPage.mobileDevice, 'search page has right device').eql('iphone');
});