Skip to content

chore: Playwright e2e testing enhancements#777

Merged
danielroe merged 2 commits intonuxt:feat/playwright-runnerfrom
mxschmitt:feat/playwright-runner-follow-up
Mar 14, 2024
Merged

chore: Playwright e2e testing enhancements#777
danielroe merged 2 commits intonuxt:feat/playwright-runnerfrom
mxschmitt:feat/playwright-runner-follow-up

Conversation

@mxschmitt
Copy link
Copy Markdown
Collaborator

No description provided.

@@ -0,0 +1,28 @@
import { test as base } from '@playwright/test';
Copy link
Copy Markdown
Collaborator Author

@mxschmitt mxschmitt Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we ship this whole file inside the test-utils package, so that the user does not have to think about it. If the user wants to customise it, he can extend from it.

Edit: Addressed

"playwright": "^1.42.1",
"@nuxt/test-utils": "latest"
"@nuxt/test-utils": "latest",
"@playwright/test": "1.43.0-alpha-2024-03-14"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: thats the alpha version with the fix: microsoft/playwright#29865

rootDir: fileURLToPath(new URL('.', import.meta.url)),
}

export default defineConfig<ConfigOptions>({
Copy link
Copy Markdown
Collaborator Author

@mxschmitt mxschmitt Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: Ideally we mirror here a similar default config like we have here: https://github.com/microsoft/create-playwright/blob/main/assets/playwright.config.ts

Edit: Addressed

test('test', async ({ page }) => {
await page.goto(url('/'))
test.expect(await page.getByRole('heading').innerText()).toBe('Welcome to Playwright!')
await page.goto('/')
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of relying on the url() function from the test-utils package, we use Playwright's baseURL.

await page.goto(url('/'))
test.expect(await page.getByRole('heading').innerText()).toBe('Welcome to Playwright!')
await page.goto('/')
await expect(page.getByRole('heading')).toHaveText('Welcome to Playwright!')
Copy link
Copy Markdown
Collaborator Author

@mxschmitt mxschmitt Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions, which we call "web-first assertions" will automatically retry over and over again until the condition is met or the timeout has been reached (they are non-flaky).

@mxschmitt mxschmitt force-pushed the feat/playwright-runner-follow-up branch from 65da6af to 486bf86 Compare March 14, 2024 20:53
@danielroe danielroe merged commit 70cf73e into nuxt:feat/playwright-runner Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants