Back to All Questions
Question 18 of 100
Framework
Beginner
What testing frameworks does TypeScript support in Playwright?
The Answer
Playwright natively supports TypeScript with zero configuration. Write `.ts` test files and run them directly β `@playwright/test` handles transpilation automatically via esbuild.
Deep Dive Explanation
Playwright uses esbuild to transpile TypeScript on-the-fly (no `tsc` step required). This is significantly faster than traditional TypeScript compilation. You get full IntelliSense, type-checking in your IDE, and typed custom fixtures β all the benefits of TypeScript with none of the build overhead.
example.spec.ts
// TypeScript test - no tsconfig or setup needed!
import { test, expect, Page } from '@playwright/test';
// Full type safety on all Playwright APIs
async function login(page: Page, email: string, password: string) {
await page.getByLabel('Email').fill(email);
await page.getByLabel('Password').fill(password);
await page.getByRole('button', { name: 'Sign In' }).click();
}
test('typed test', async ({ page }) => {
await login(page, 'admin@test.com', 'secret');
await expect(page).toHaveURL('/dashboard');
});
// Custom typed fixture
import { test as base } from '@playwright/test';
type MyFixtures = { adminPage: Page };
const test2 = base.extend<MyFixtures>({
adminPage: async ({ page }, use) => {
await login(page, 'admin@test.com', 'secret');
await use(page);
}
});