Add visual regression tests (#994)
Co-authored-by: Roman Pronskiy <roman@pronskiy.com> Co-authored-by: Derick Rethans <derick@php.net>
63
tests/Visual/SmokeTest.spec.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import {expect, test} from '@playwright/test';
|
||||
|
||||
export type TestPageOptions = {
|
||||
path: string
|
||||
options?: object
|
||||
evaluate?: () => any
|
||||
}
|
||||
|
||||
const items: TestPageOptions[] = [
|
||||
{
|
||||
path: 'index.php',
|
||||
evaluate: () => {
|
||||
const selector = document.querySelector('.elephpants');
|
||||
selector.remove()
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'archive/1998.php',
|
||||
evaluate: () => {
|
||||
const selector = document.querySelector('.elephpants');
|
||||
selector.remove()
|
||||
}
|
||||
},
|
||||
{path: 'releases/8_3_6.php'},
|
||||
{path: 'releases/8.0/index.php'},
|
||||
{path: 'releases/8.1/index.php'},
|
||||
{path: 'releases/8.2/index.php'},
|
||||
{path: 'releases/8.3/index.php'},
|
||||
{path: 'manual/index.php'},
|
||||
{path: 'manual/php5.php'},
|
||||
{
|
||||
path: 'conferences/index.php',
|
||||
options: {
|
||||
fullPage: false,
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
for (const item of items) {
|
||||
test(`testing with ${item.path}`, async ({page}, testInfo) => {
|
||||
testInfo.snapshotSuffix = '';
|
||||
|
||||
const httpHost = process.env.HTTP_HOST
|
||||
|
||||
if (typeof httpHost !== 'string') {
|
||||
throw new Error('Environment variable "HTTP_HOST" is not set.')
|
||||
}
|
||||
|
||||
await page.goto(`${httpHost}/${item.path}`)
|
||||
|
||||
if (typeof item.evaluate === 'function') {
|
||||
await page.evaluate(item.evaluate)
|
||||
}
|
||||
|
||||
await expect(page).toHaveScreenshot(
|
||||
`tests/screenshots/${item.path}.png`,
|
||||
item.options ?? {
|
||||
fullPage: true,
|
||||
timeout: 10000,
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 168 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 382 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 604 KiB |
|
After Width: | Height: | Size: 730 KiB |
|
After Width: | Height: | Size: 565 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 818 KiB |