Playwright Recipes
1. Launch Browser and Open a Page
import { chromium } from '@playwright/test';
(async () => {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
// ...your actions here...
await browser.close();
})();
2. Basic Test with Playwright Test Runner
import { test, expect } from '@playwright/test';
test('homepage has correct title', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle('Example Domain');
});