-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathasync-events.ts
More file actions
79 lines (73 loc) · 2.74 KB
/
async-events.ts
File metadata and controls
79 lines (73 loc) · 2.74 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
/*
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
export function asyncEvents(page) {
return {
async clickButton(text, endpoint) {
if (!endpoint)
throw new Error('Must provide endpoint argument, type string, e.g. "/authenticate"');
await Promise.all([
page.waitForResponse((response) => response.url().includes(endpoint)),
page.getByRole('button', { name: text }).click(),
]);
},
async clickLink(text, endpoint) {
if (!endpoint)
throw new Error('Must provide endpoint argument, type string, e.g. "/authenticate"');
await Promise.all([
page.waitForResponse((response) => response.url().includes(endpoint)),
page.getByRole('link', { name: text }).click(),
]);
},
async getTokens(origin, clientId) {
const webStorage = await page.context().storageState();
const originStorage = webStorage.origins.find((item) => item.origin === origin);
// Storage may not have any items
if (!originStorage) {
return null;
}
const clientIdStorage = originStorage?.localStorage.find((item) => item.name === clientId);
if (clientIdStorage && typeof clientIdStorage.value !== 'string' && !clientIdStorage.value) {
return null;
}
try {
return JSON.parse(clientIdStorage.value);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return null;
}
},
async navigate(route) {
await page.goto(route, { waitUntil: 'networkidle' });
},
async pressEnter(endpoint) {
if (!endpoint)
throw new Error('Must provide endpoint argument, type string, e.g. "/authenticate"');
await Promise.all([
page.waitForResponse((response) => response.url().includes(endpoint)),
page.keyboard.press('Enter'),
]);
},
async pressSpacebar(endpoint) {
if (!endpoint)
throw new Error('Must provide endpoint argument, type string, e.g. "/authenticate"');
await Promise.all([
page.waitForResponse((response) => response.url().includes(endpoint)),
page.keyboard.press(' '),
]);
},
};
}
export async function verifyUserInfo(page, expect, type) {
const emailString = type === 'register' ? 'Email: test@auto.com' : 'Email: demo@user.com';
const nameString = 'Full name: Demo User';
const name = page.getByText(nameString);
const email = page.getByText(emailString);
// Just wait for one of them to be visible
await name.waitFor();
expect(await name.textContent()).toBe(nameString);
expect(await email.textContent()).toBe(emailString);
}