From 0ad88a6e07894620d6241fba17082f11496cbe2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Greffier?= Date: Sat, 4 Nov 2023 00:34:58 +0100 Subject: [PATCH] docs: how to use with Playwright (#2489) --- docs/guide/frameworks.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/guide/frameworks.md b/docs/guide/frameworks.md index 4dec853f717..3b0cd6f39c1 100644 --- a/docs/guide/frameworks.md +++ b/docs/guide/frameworks.md @@ -98,3 +98,39 @@ describe('Testing the application', () => { }); }); ``` + +## Playwright + +Integration with [Playwright](https://playwright.dev/) is also easy: + +```ts +import { faker } from '@faker-js/faker/locale/en'; +import { expect, test } from '@playwright/test'; + +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('password').fill(password); + await page.getByRole('button', { name: 'Login' }).click(); + + // We should have logged in successfully to the dashboard page. + await expect(page).toHaveURL(/.*dashboard/); + }); +}); +```