-
Notifications
You must be signed in to change notification settings - Fork 332
feat: [poc] e2e testing of frontend with playwright #4221
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
# Playwright | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: 'html', | ||
use: { | ||
baseURL: 'http://localhost:3000', | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
webServer: { | ||
command: 'pnpm run dev', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we want to use the Cloudflare deployment associated with the PR for CI, rather than a dev runner, since nuxt has a tendency to hot reload quite often during warmup which might affect tests. |
||
url: 'http://localhost:3000', | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { expect, test, type Page } from '@playwright/test' | ||
|
||
async function hasThemeOnElement(page: Page, element: string) { | ||
const htmlElement = page.locator('html') | ||
return await htmlElement.evaluate((el, theme) => el.classList.contains(theme), element) | ||
} | ||
|
||
test('test', async ({ page }, testInfo) => { | ||
await page.goto('http://localhost:3000/') | ||
await page.getByRole('link', { name: 'Settings' }).click() | ||
await page.locator('html').click() | ||
|
||
await page.getByRole('button', { name: 'Light' }).click() | ||
const lightMode = await page.screenshot() | ||
expect(await hasThemeOnElement(page, 'light-mode')).toBe(true) | ||
|
||
await page.waitForTimeout(1000) | ||
|
||
await page.getByRole('button', { name: 'Dark' }).click() | ||
const darkMode = await page.screenshot() | ||
expect(await hasThemeOnElement(page, 'dark-mode')).toBe(true) | ||
|
||
await page.waitForTimeout(1000) | ||
|
||
await page.getByRole('button', { name: 'OLED' }).click() | ||
const oledMode = await page.screenshot() | ||
expect(await hasThemeOnElement(page, 'oled-mode')).toBe(true) | ||
|
||
testInfo.attach('test-results/light-mode', { body: lightMode, contentType: 'image/png' }) | ||
testInfo.attach('test-results/dark-mode', { body: darkMode, contentType: 'image/png' }) | ||
testInfo.attach('test-results/oled-mode', { body: oledMode, contentType: 'image/png' }) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment.