xref: /web-php/tests/Visual/SmokeTest.spec.ts (revision cb385e3e)
1import {expect, test} from '@playwright/test';
2
3export type TestPageOptions = {
4    path: string
5    options?: object
6    evaluate?: () => any
7    mask?: string[]
8}
9
10const items: TestPageOptions[] = [
11    {
12        path: 'index.php',
13        evaluate: () => {
14            const selector = document.querySelector('.elephpants');
15            selector.remove()
16        },
17        options: {
18            fullPage: true,
19            timeout: 10000,
20        },
21        mask: ['.hero__versions'],
22    },
23    {
24        path: 'archive/1998.php',
25        evaluate: () => {
26            const selector = document.querySelector('.elephpants');
27            selector.remove()
28        }
29    },
30    {path: 'releases/8_3_6.php'},
31    {path: 'releases/8.0/index.php'},
32    {path: 'releases/8.1/index.php'},
33    {path: 'releases/8.2/index.php'},
34    {path: 'releases/8.3/index.php'},
35    {path: 'manual/index.php'},
36    {path: 'manual/php5.php'},
37    {
38        path: 'conferences/index.php',
39        options: {
40            fullPage: false,
41        }
42    },
43]
44
45for (const item of items) {
46    test(`testing with ${item.path}`, async ({page}, testInfo) => {
47        testInfo.snapshotSuffix = '';
48
49        const httpHost = process.env.HTTP_HOST
50
51        if (typeof httpHost !== 'string') {
52            throw new Error('Environment variable "HTTP_HOST" is not set.')
53        }
54
55        await page.goto(`${httpHost}/${item.path}`)
56
57        if (typeof item.evaluate === 'function') {
58            await page.evaluate(item.evaluate)
59        }
60
61        if (typeof item.mask === 'object') {
62            item.options = {
63                ...item.options,
64                mask: item.mask.map((selector) => page.locator(selector))
65            }
66        }
67
68        await expect(page).toHaveScreenshot(
69            `tests/screenshots/${item.path}.png`,
70            item.options ?? {
71                fullPage: true,
72                timeout: 10000,
73            }
74        )
75    })
76}
77