-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhelper.ts
More file actions
56 lines (48 loc) · 2.01 KB
/
helper.ts
File metadata and controls
56 lines (48 loc) · 2.01 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
import type { Locator, Page } from '@playwright/test';
import { expect, test as baseTest } from '@playwright/test';
export const examplesURL = 'https://surveyjstest.azurewebsites.net';
export const siteUrl = 'https://surveyjsio-test.azurewebsites.net';
// export const examplesURL = 'http://localhost:62946';
// export const siteUrl = 'http://localhost:62946';
export const screens = {
'Large-Desktop': { width: 1920, height: 1080 },
'Desktop': { width: 1366, height: 768 },
'Tablet': { width: 1024, height: 744 },
'Vertical-Tablet': { width: 744, height: 1024 },
'Mobile': { width: 375, height: 667 }
};
export async function compareScreenshot(page: Page, elementSelector: string | Locator | undefined, screenshotName: string, elementIndex = 0, maxDiffPixels?:number, mask?: Array<Locator>) {
let currentElement = elementSelector;
if (!!currentElement && typeof currentElement == 'string') {
currentElement = page.locator(currentElement);
}
const options: {timeout: number, maxDiffPixels?: number, mask?: Array<Locator>} = {
timeout: 10000
};
if (maxDiffPixels) options.maxDiffPixels = maxDiffPixels;
if (mask) options.mask = mask;
if (!!currentElement) {
const element = (<any>currentElement).filter({ visible: true });
await expect.soft(element.nth(elementIndex)).toBeVisible();
await expect.soft(element.nth(elementIndex)).toHaveScreenshot(screenshotName, options);
} else {
await expect.soft(page).toHaveScreenshot(screenshotName, options);
}
}
export async function acceptCookieBanner(page: Page):Promise<void> {
await page.locator('a').filter({ hasText: 'Accept All' }).click();
}
export const test = baseTest.extend<{page: void, skipJSErrors: boolean}>({
skipJSErrors: [false, { option: false }],
page: async ({ page, skipJSErrors }, use) => {
const errors: Array<Error> = [];
page.addListener('pageerror', (error) => {
errors.push(error);
});
await use(page);
if (!skipJSErrors) {
expect(errors).toHaveLength(0);
}
}
});
export { expect };