-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.page.ts
More file actions
112 lines (85 loc) · 3.38 KB
/
Copy pathexample.page.ts
File metadata and controls
112 lines (85 loc) · 3.38 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
import {expect} from '@playwright/test';
import {AppPage} from './app.page';
export abstract class ExamplePage extends AppPage {
async assertSignedIn(): Promise<void> {
const button = this.page.locator('button', {hasText: this.callToActions.logout});
await expect(button).toBeVisible();
}
async assertSignedOut(): Promise<void> {
const button = this.page.locator('button', {
hasText: this.callToActions.internet_identity.continue
});
await expect(button).toBeVisible();
}
async goto(): Promise<void> {
await this.page.goto('/');
}
async addEntry(text: string): Promise<void> {
const addEntryButton = this.page.locator('button', {hasText: this.callToActions.add_an_entry});
await expect(addEntryButton).toBeVisible();
await addEntryButton.click();
const textarea = this.page.locator('textarea');
await textarea.fill(text);
const button = this.page.locator('button', {hasText: this.callToActions.submit});
await button.click();
const row = this.page.locator('[role="row"]', {hasText: text});
await expect(row).toBeVisible();
}
async assertEntries(count: number): Promise<void> {
const rows = this.page.locator('[role="rowgroup"] [role="row"]');
await expect(rows).toHaveCount(count, {timeout: 2000});
}
async addEntryWithFile({text, filePath}: {text: string; filePath: string}): Promise<void> {
const addEntryButton = this.page.locator('button', {hasText: this.callToActions.add_an_entry});
await expect(addEntryButton).toBeVisible();
await addEntryButton.click();
const textarea = this.page.locator('textarea');
await textarea.fill(text);
const fileInput = this.page.locator('input[type="file"]');
await fileInput.setInputFiles(filePath);
const button = this.page.locator('button', {hasText: this.callToActions.submit});
await button.click();
const row = this.page.locator('[role="row"]', {hasText: text});
await expect(row).toBeVisible({timeout: 60_000});
}
async assertUploadedImage(): Promise<void> {
const [imgPage] = await Promise.all([
this.page.context().waitForEvent('page'),
this.page.locator(this.locators.open_data).click()
]);
await imgPage.waitForLoadState('load');
await expect(imgPage).toHaveScreenshot('uploaded-image.png', {
maxDiffPixelRatio: 0.1
});
await imgPage.close();
}
async deleteLastEntry(): Promise<void> {
const buttons = this.page.locator(this.locators.delete_entry);
await buttons.last().click();
await expect(this.page.locator('[role="row"]', {hasText: 'text'})).toHaveCount(0);
}
async assertScreenshot({
mode,
name
}: {
mode: 'light' | 'dark' | 'current';
name: string;
}): Promise<void> {
await expect(this.page).toHaveScreenshot(`${name}-${mode}-mode.png`, {
fullPage: true,
maxDiffPixelRatio: 0.03
});
}
async openAddEntry(): Promise<void> {
const addEntryButton = this.page.locator('button', {hasText: this.callToActions.add_an_entry});
await expect(addEntryButton).toBeVisible();
await addEntryButton.click();
const textarea = this.page.locator('textarea');
await expect(textarea).toBeVisible();
}
async closeAddEntryModal(): Promise<void> {
const closeAddEntryButton = this.page.locator('button', {hasText: 'Close'});
await expect(closeAddEntryButton).toBeVisible();
await closeAddEntryButton.click();
}
}