-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitchingPagesForRequests.ts
More file actions
73 lines (56 loc) · 1.93 KB
/
switchingPagesForRequests.ts
File metadata and controls
73 lines (56 loc) · 1.93 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
/* eslint-disable @typescript-eslint/no-magic-numbers */
import {test} from 'autotests';
import {getUsers} from 'autotests/entities';
import {E2edReportExample} from 'autotests/pageObjects/pages';
import {GetUsers} from 'autotests/routes/apiRoutes';
import {expect} from 'e2ed';
import {
navigateToPage,
switchToTab,
waitForNewTab,
waitForRequestToRoute,
waitForTimeout,
} from 'e2ed/actions';
import {log} from 'e2ed/utils';
const maxNumberOfRequests = 15;
const timeout = (maxNumberOfRequests + 10) * 1_000;
test(
'support switching of tabs for waitForRequest',
{enableCsp: false, meta: {testId: '21'}, testTimeout: timeout + 1_000},
async () => {
let numberOfCaughtRequests = 0;
let numberOfSentRequests = 0;
setInterval(() => {
if (numberOfSentRequests < maxNumberOfRequests) {
numberOfSentRequests += 1;
log(`Sent request number ${numberOfSentRequests}`);
void getUsers({retries: 1});
}
}, 1_000);
void waitForRequestToRoute(GetUsers, {
predicate: (routeParams, request) => {
numberOfCaughtRequests += 1;
log(`Caught request number ${numberOfCaughtRequests}`, {request, routeParams});
return false;
},
timeout,
});
await waitForTimeout(maxNumberOfRequests * 333);
const reportPage = await navigateToPage(E2edReportExample);
await waitForTimeout(maxNumberOfRequests * 333);
const npmPageTab = await waitForNewTab(
async () => {
await reportPage.clickLogo();
},
{timeout: 10_000},
);
await switchToTab(npmPageTab);
await waitForTimeout(maxNumberOfRequests * 333 + 1_000);
await expect(
numberOfSentRequests === numberOfCaughtRequests ||
numberOfSentRequests === numberOfCaughtRequests + 1 ||
numberOfSentRequests === numberOfCaughtRequests - 1,
`almost all responses were caught (${numberOfCaughtRequests} of ${numberOfSentRequests})`,
).ok();
},
);