Playwright
End-to-End Testing Framework
Microsoft's cross-browser E2E testing framework. Supports Chromium, Firefox, and WebKit. Write stable tests with Auto-wait and Trace Viewer.
End-to-End Testing Framework
Microsoft's cross-browser E2E testing framework. Supports Chromium, Firefox, and WebKit. Write stable tests with Auto-wait and Trace Viewer.
Playwright is an open-source E2E (End-to-End) test automation framework developed by Microsoft. It automates browser-based tests by simulating real user scenarios of web applications. Going beyond a simple browser automation tool, it provides all the features needed for testing modern web applications, and supports various languages such as TypeScript, JavaScript, Python, .NET, and Java.
Playwright was created in 2020 by engineers from Google's Puppeteer development team after they moved to Microsoft. It was designed to carry on the strengths of Puppeteer while resolving the limitations of existing tools, such as the lack of cross-browser support and test stability issues. Unlike Puppeteer, which was limited to Chrome/Chromium, Playwright was developed from the start to target all major browsers.
Playwright's core strength is cross-browser support. With a single API, the same tests can be run on three browser engines: Chromium (Chrome, Edge), Firefox, and WebKit (Safari). It also supports mobile emulation, making it possible to test in iPhone and Android device environments. This makes it possible to catch cross-browser compatibility problems, such as "it works on my machine," early in the CI/CD pipeline.
In practice, Playwright is loved thanks to features such as Auto-wait and Trace Viewer. Auto-wait automatically waits until an element becomes clickable, greatly reducing flaky tests (intermittent failures). Trace Viewer visually shows the test execution process together with a timeline, screenshots, and network requests, making it easy to debug the cause of failures. In addition, complex scenarios such as intercepting network requests, controlling multiple tabs/windows, and handling iframes can be implemented simply.
// Playwright κΈ°λ³Έ ν
μ€νΈ μμ± μμ
import { test, expect } from '@playwright/test';
// ν
μ€νΈ μ€μνΈ: λ‘κ·ΈμΈ κΈ°λ₯
test.describe('λ‘κ·ΈμΈ κΈ°λ₯', () => {
// κΈ°λ³Έ λ‘κ·ΈμΈ ν
μ€νΈ
test('μ ν¨ν μ격μ¦λͺ
μΌλ‘ λ‘κ·ΈμΈ μ±κ³΅', async ({ page }) => {
// 1. λ‘κ·ΈμΈ νμ΄μ§λ‘ μ΄λ
await page.goto('https://example.com/login');
// 2. μ΄λ©μΌ μ
λ ₯ (Auto-wait: μμκ° μ€λΉλ λκΉμ§ μλ λκΈ°)
await page.fill('[data-testid="email"]', 'user@example.com');
// 3. λΉλ°λ²νΈ μ
λ ₯
await page.fill('[data-testid="password"]', 'securePassword123');
// 4. λ‘κ·ΈμΈ λ²νΌ ν΄λ¦
await page.click('button[type="submit"]');
// 5. λμ보λλ‘ λ¦¬λ€μ΄λ νΈ νμΈ
await expect(page).toHaveURL('/dashboard');
// 6. νμ λ©μμ§ νμΈ
await expect(
page.locator('[data-testid="welcome-message"]')
).toContainText('νμν©λλ€');
});
// μ€ν¨ μΌμ΄μ€ ν
μ€νΈ
test('μλͺ»λ λΉλ°λ²νΈλ‘ μλ¬ λ©μμ§ νμ', async ({ page }) => {
await page.goto('https://example.com/login');
await page.fill('[data-testid="email"]', 'user@example.com');
await page.fill('[data-testid="password"]', 'wrongPassword');
await page.click('button[type="submit"]');
// μλ¬ λ©μμ§κ° νμλλμ§ νμΈ
await expect(
page.locator('.error-message')
).toBeVisible();
});
});
// νμ΄μ§ κ°μ²΄ ν¨ν΄ (Page Object Model)
// ν
μ€νΈ μ½λμ μ¬μ¬μ©μ±κ³Ό μ μ§λ³΄μμ±μ λμ΄λ μ€κ³ ν¨ν΄
import { Page, Locator, expect } from '@playwright/test';
export class LoginPage {
readonly page: Page;
readonly emailInput: Locator;
readonly passwordInput: Locator;
readonly submitButton: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
// μ νμλ₯Ό ν κ³³μμ κ΄λ¦¬
this.emailInput = page.getByTestId('email');
this.passwordInput = page.getByTestId('password');
this.submitButton = page.getByRole('button', { name: 'λ‘κ·ΈμΈ' });
this.errorMessage = page.locator('.error-message');
}
// νμ΄μ§ μ΄λ λ©μλ
async goto() {
await this.page.goto('/login');
}
// λ‘κ·ΈμΈ μ‘μ
λ©μλ
async login(email: string, password: string) {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.submitButton.click();
}
// κ²μ¦ λ©μλ
async expectError(message: string) {
await expect(this.errorMessage).toContainText(message);
}
}
// ===== ν
μ€νΈμμ μ¬μ© =====
// login.spec.ts
import { test } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
test('νμ΄μ§ κ°μ²΄ ν¨ν΄ μ¬μ© μμ', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('test@example.com', 'password123');
// UIκ° λ³κ²½λμ΄λ LoginPage ν΄λμ€λ§ μμ νλ©΄ λ¨
});
QA Lead Kim:
"After the frontend renewal, manual regression testing is taking too much time. We're looking to adopt an E2E automation tool. Which is better, Cypress or Playwright?"
Frontend Developer Lee:
"I recommend Playwright. Many of our service's users are on Safari, and Playwright supports WebKit natively. Cypress offers only experimental support. Also, Playwright's Auto-wait feature greatly reduces flaky tests."
Senior Developer Park:
"I agree on Playwright. I've used both at my previous company, and Playwright's Trace Viewer is really useful for debugging test failures. You can check each step's screenshots and network requests right in the timeline, so identifying the cause of a problem is fast."
QA Lead Kim:
"How difficult is it to write tests? The QA team needs to write tests too."
Frontend Developer Lee:
"Playwright has a feature called Codegen. When you interact directly in the browser, it generates code automatically. If the QA team starts with that, the learning curve should be low. And structuring with the Page Object pattern makes maintenance easier too."
Interviewer:
"You said you have experience writing E2E tests with Playwright. What was the most difficult part?"
Candidate:
"At first, I struggled with flaky tests. There were timing issues when loading dynamic content. Using Playwright's Auto-wait and the automatic retry feature of expect assertions instead of waitForSelector greatly improved stability."
Interviewer:
"Have you used the Page Object pattern? What advantages did it have?"
Candidate:
"Yes, I structured every page with POM. Even when the UI changed, I only had to modify the Page class and the test code kept working, which made maintenance easier, and being able to reuse common actions like login and search sped up test writing as well."
DevOps Engineer Choi:
"I'm planning to integrate Playwright tests into GitHub Actions, but isn't the setup complicated? Browsers need to be installed too..."
Backend Developer Jung:
"It's simpler than you'd think. Playwright provides an official GitHub Action, so just adding playwright-action handles even browser caching automatically. Docker images are also officially provided."
DevOps Engineer Choi:
"If test execution takes a long time, PR merges will be delayed. Is parallel execution possible?"
Backend Developer Jung:
"Yes, you can run tests in parallel with the --workers option, and by combining GitHub Actions' matrix strategy with the --shard option, you can distribute tests across multiple runners. We run the Chromium, Firefox, and WebKit tests simultaneously on separate runners, which cut the total time to one-third."
DevOps Engineer Choi:
"How do we check the report when a test fails?"
Backend Developer Jung:
"Playwright provides an HTML reporter by default. If you upload the Trace file as an artifact when tests fail in CI, you can download it and analyze it right away in Trace Viewer. You can see everything, including the screenshot and DOM snapshot at the point of failure."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Each test must run independently. Sharing state between tests (login sessions, DB data) causes unexpected failures. Reset state in beforeEach, and manage authentication state with the storageState option. Design tests so they do not depend on test order.
Selectors that depend on CSS classes or DOM structure break easily when the UI changes. We recommend user-facing selectors such as the data-testid attribute, getByRole(), and getByText(). Playwright's Locator has built-in retry logic and is therefore stable, but avoid complex path selectors such as XPath.
The default timeout (30 seconds) is not suitable for every situation. For slow API responses or animations, set an appropriate timeout for each test. However, solving the actual performance problem takes priority over blindly increasing the timeout. Use expect's automatic retry instead of waitForSelector.