docs: Add Vitest example (#15356)

This commit is contained in:
jfgreffier 2022-07-05 20:12:02 +02:00 committed by GitHub
parent 8cdc4513f1
commit cfd00c0baf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -91,6 +91,35 @@ it('should work', async () => {
assert.equal(await page.title(), 'Example Domain');
});
```
## Vitest
Vitest looks very similar to the Jest/Jasmine setup, and functions in the same way.
```
import { chromium } from 'playwright';
import { afterAll, afterEach, beforeAll, beforeEach, expect, test } from 'vitest';
let browser;
let page;
beforeAll(async () => {
browser = await chromium.launch();
});
afterAll(async () => {
await browser.close();
});
beforeEach(async () => {
page = await browser.newPage();
});
afterEach(async () => {
await page.close();
});
test('should work', async () => {
await page.goto('https://www.example.com/');
expect(await page.title()).toBe('Example Domain');
});
```
## Multiple Browsers
These simple examples can be extended to support multiple browsers using an environment variable.