-
Notifications
You must be signed in to change notification settings - Fork 19
chore(tests): visual regression testing POC #5214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
alionazherdetska
wants to merge
22
commits into
main
from
4923-using-playwright-for-visual-regression-testing
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a74328b
feat(setup): initial set for the playwright
alionazherdetska de5f31d
feat(testing): added the screenshot for the button
alionazherdetska 76605d8
feat(feat): implemented the initial setup for the playwright visual tβ¦
alionazherdetska c105222
feat(setup): added the scripts for the visual tests
alionazherdetska de14127
Merge branch 'visual-testing-playwright' into 4923-using-playwright-fβ¦
alionazherdetska 6e3b1da
chore(workflow): added missing permissions
alionazherdetska 7437476
chore(tests): added the screenshots for browsers
alionazherdetska 4f2fa22
removed screenshots
alionazherdetska 893cda6
remove redundant files
alionazherdetska d079f96
chore: added screenshots
alionazherdetska 8ed36d6
test
alionazherdetska 7e918fe
removed the screenshots
alionazherdetska ff92071
added creenshots
alionazherdetska 0154a92
remove screeshots
alionazherdetska 62292d7
added new screenshots
alionazherdetska 43648cf
chore(test): removed redundant code
alionazherdetska cb126d2
chore: removed redundant comments
alionazherdetska 39fa628
chore(workflow): refactore upload screenshot on failure job
alionazherdetska fc962f2
test
alionazherdetska 22c8d37
Merge branch 'main' into 4923-using-playwright-for-visual-regression-β¦
alionazherdetska a86f5ca
fixed broken lock.file
alionazherdetska 1a2b6de
fixed the button.html
alionazherdetska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Visual Regression Tests | ||
on: | ||
pull_request: | ||
paths: | ||
- 'packages/styles/**' | ||
workflow_dispatch: | ||
inputs: | ||
update-snapshots: | ||
description: 'Update visual snapshots' | ||
type: boolean | ||
default: false | ||
|
||
permissions: | ||
contents: read | ||
actions: read | ||
pull-requests: read | ||
|
||
jobs: | ||
visual-tests: | ||
name: Visual Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup | ||
uses: ./.github/actions/setup-pnpm | ||
|
||
- name: Install dependencies and build packages | ||
run: pnpm bootstrap | ||
|
||
- name: Install Playwright browsers | ||
working-directory: packages/styles | ||
run: npx playwright install --with-deps | ||
|
||
- name: Get snapshot cache | ||
id: snapshot-cache | ||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 | ||
with: | ||
path: packages/styles/tests/visual/__screenshots__ | ||
key: visual-snapshots-${{ github.ref }} | ||
restore-keys: | | ||
visual-snapshots-refs/heads/main | ||
|
||
- name: Update Snapshots | ||
if: github.event.inputs.update-snapshots == 'true' || steps.snapshot-cache.outputs.cache-hit != 'true' | ||
working-directory: packages/styles | ||
run: pnpm test:visual:update | ||
|
||
- name: Run visual tests | ||
working-directory: packages/styles | ||
run: pnpm test:visual | ||
|
||
- name: Upload test results | ||
if: always() | ||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 | ||
with: | ||
name: playwright-report | ||
path: packages/styles/test-results | ||
retention-days: 14 | ||
|
||
# Upload diff screenshots on failure | ||
- name: Upload diff screenshots | ||
if: failure() | ||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 | ||
with: | ||
name: playwright-screenshots | ||
path: | | ||
packages/styles/test-results/**/*-diff.png | ||
packages/styles/test-results/**/*-actual.png | ||
packages/styles/test-results/**/*-expected.png | ||
retention-days: 14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
testDir: './tests/visual', | ||
|
||
testMatch: '**/*.spec.ts', | ||
|
||
timeout: 30000, | ||
|
||
reporter: [ | ||
['html', { outputFolder: 'test-results/html-report' }], | ||
['list'] | ||
], | ||
|
||
snapshotPathTemplate: '{testDir}/__screenshots__/{projectName}/{testFilePath}/{arg}{ext}', | ||
|
||
outputDir: 'test-results/artifacts', | ||
|
||
use: { | ||
baseURL: 'http://localhost:9000', | ||
}, | ||
|
||
// Projects for different browsers | ||
projects: [ | ||
// Desktop Chrome | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
// Desktop Firefox | ||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
// Desktop Safari | ||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
} | ||
], | ||
|
||
// Start a web server for the tests | ||
webServer: { | ||
command: 'npx http-server . -p 9000', | ||
url: 'http://localhost:9000', | ||
reuseExistingServer: true, | ||
timeout: 60000, | ||
}, | ||
}); |
Binary file added
BIN
+2.91 KB
.../tests/visual/__screenshots__/chromium/button.spec.ts/button-primary-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.91 KB
...s/tests/visual/__screenshots__/chromium/button.spec.ts/button-primary-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.37 KB
...s/tests/visual/__screenshots__/chromium/button.spec.ts/button-primary-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.27 KB
.../styles/tests/visual/__screenshots__/chromium/button.spec.ts/button-primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.38 KB
...s/tests/visual/__screenshots__/firefox/button.spec.ts/button-primary-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.38 KB
...es/tests/visual/__screenshots__/firefox/button.spec.ts/button-primary-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.38 KB
...es/tests/visual/__screenshots__/firefox/button.spec.ts/button-primary-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.37 KB
...s/styles/tests/visual/__screenshots__/firefox/button.spec.ts/button-primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.37 KB
...es/tests/visual/__screenshots__/webkit/button.spec.ts/button-primary-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.89 KB
...les/tests/visual/__screenshots__/webkit/button.spec.ts/button-primary-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.37 KB
...les/tests/visual/__screenshots__/webkit/button.spec.ts/button-primary-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.22 KB
...es/styles/tests/visual/__screenshots__/webkit/button.spec.ts/button-primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.describe('Button Component Visual Test', () => { | ||
test('primary button appearance', async ({ page }) => { | ||
await page.goto('/tests/visual/components/button.html'); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
const button = page.locator('.btn-primary'); | ||
await expect(button).toHaveScreenshot('button-primary.png'); | ||
|
||
await button.hover(); | ||
await expect(button).toHaveScreenshot('button-primary-hover.png'); | ||
|
||
await button.focus(); | ||
await expect(button).toHaveScreenshot('button-primary-focus.png'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" id="styles" href="/dist/post-default.css" /> | ||
<title>Button Test</title> | ||
</head> | ||
<body> | ||
|
||
<button class="btn btn-primary">Button</button> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2019", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"sourceMap": true, | ||
"outDir": "./dist", | ||
"baseUrl": ".", | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"resolveJsonModule": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"types": ["node", "@playwright/test"] | ||
}, | ||
"include": ["tests/**/*.ts", "playwright.config.ts"], | ||
"exclude": ["node_modules"] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.