Skip to content

Commit

Permalink
docs: how to use with Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
jfgreffier committed Oct 21, 2023
1 parent f222448 commit 79db726
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/guide/frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});

```

0 comments on commit 79db726

Please sign in to comment.