diff --git a/docs/guide/frameworks.md b/docs/guide/frameworks.md index 4dec853f717..065b456225d 100644 --- a/docs/guide/frameworks.md +++ b/docs/guide/frameworks.md @@ -98,3 +98,46 @@ describe('Testing the application', () => { }); }); ``` + +## Playwright + +Integration with [Playwright](https://playwright.dev/) is also easy: + +```ts +import { faker } from '@faker-js/faker/locale/en'; +import { test, expect } from '@playwright/test'; + +// This will re-seed our faker instance after each test. +test.afterEach(() => { + faker.seed(); +}); + +test.describe('Testing the application', () => { + test('should create an account with username and password', async ({ + page, + }) => { + const username = faker.internet.userName(); + const password = faker.internet.password(); + const email = faker.internet.exampleEmail(); + + // Visit the webpage and create an account. + await page.goto('https://www.example.com/register'); + await page.getByLabel('email').fill(email); + await page.getByLabel('username').fill(username); + await page.getByLabel('password', { exact: true }).fill(password); + await page.getByLabel('confirm password').fill(password); + await page.getByRole('button', { name: 'Register' }).click(); + + // Now, we try to login with these credentials. + await page.goto('https://www.example.com/login'); + await page.getByLabel('email').fill(email); + await page.getByLabel('username').fill(username); + await page.getByLabel('password').fill(password); + await page.getByRole('button', { name: 'Register' }).click(); + + // We should have logged in successfully to the dashboard page. + await expect(page).toHaveURL(/.*dashboard/); + }); +}); + +```