Skip to Content
FrontendTechPlaywright

Playwright

Description

what is it ? : Playwright is an open-source end-to-end testing framework developed by Microsoft. It enables reliable cross-browser web automation for testing modern web applications.
URL : official website 
version : 1.40.0
Why ? :

  • Cross-browser testing (Chromium, Firefox, WebKit)
  • Auto-waiting for elements and network requests
  • Built-in test runner with parallel execution
  • Powerful debugging tools (Playwright Inspector, trace viewer)
  • Multi-language support (TypeScript, JavaScript, Python, .NET, Java)
  • Mobile emulation and geolocation support
  • Network interception and mocking capabilities
  • Screenshot and video recording for test failures
  • Reliable selectors with auto-waiting
  • Fast and parallel test execution

Application

Basic Test Example

import { test, expect } from '@playwright/test'; test('homepage has title', async ({ page }) => { await page.goto('https://playwright.dev/'); // Expect a title "to contain" a substring. await expect(page).toHaveTitle(/Playwright/); }); test('get started link', async ({ page }) => { await page.goto('https://playwright.dev/'); // Click the get started link. await page.getByRole('link', { name: 'Get started' }).click(); // Expects the URL to contain intro. await expect(page).toHaveURL(/.*intro/); });

Running Tests

# Run all tests npx playwright test # Run tests in headed mode npx playwright test --headed # Run a specific test file npx playwright test example.spec.ts # Run tests in debug mode npx playwright test --debug # Run tests in UI mode npx playwright test --ui

Best Practices

  • Prefer test.describe() blocks to organize related tests
  • Use test.beforeEach() for test setup and authentication
  • Use expect() assertions with auto-waiting
  • Take screenshots on failures for debugging
  • Use test.step() to break down complex test scenarios
  • Mock external APIs for faster and more reliable tests
Last updated on