Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS MATH

Playwright Introduction


Share

What is Playwright?

Playwright is a tool for testing websites in real browsers.

It is made by Microsoft, and it is free and open source.

Playwright can control the three main browser engines:

  • Chromium, used by Google Chrome and Microsoft Edge
  • Firefox
  • WebKit, used by Safari

You write a script that tells the browser what to do, and Playwright does it, much faster than a person could.


What is End-to-End Testing?

An end-to-end test checks a whole feature the way a user uses it.

It opens the page, clicks buttons, fills in forms, and checks what the page shows.

For example, an end-to-end test for a login page could:

  1. Open the login page
  2. Type a username and a password
  3. Click the "Log in" button
  4. Check that the page says "Welcome, student!"

A unit test checks one small function on its own.

An end-to-end test checks that all the parts work together: the HTML, the CSS, the JavaScript and the server.



What Can You Do with Playwright?

  • Test websites: check that pages and features work after every change
  • Take screenshots and videos of pages and test runs
  • Compare screenshots to find visual changes
  • Test APIs: send HTTP requests and check the responses
  • Automate tasks: fill in forms, download files, or collect data from web pages (web scraping)

This tutorial is about testing.

It uses Playwright Test, the test runner that comes with Playwright.


Playwright, Selenium and Cypress

Selenium and Cypress are two other popular tools for end-to-end testing.

All three can test a website in a real browser.

Playwright Selenium Cypress
Languages JavaScript, TypeScript, Python, Java, C# Java, Python, C#, JavaScript, Ruby JavaScript, TypeScript
Browsers Chromium, Firefox, WebKit Chrome, Edge, Firefox, Safari Chrome, Edge, Firefox (WebKit is experimental)
Waits for elements Yes, built in You add waits yourself Yes, built in
Test runner included Yes No, you use one from your language Yes

Selenium is the oldest, and supports the most languages.

Cypress runs inside the browser, and is popular with front-end developers.

Playwright runs outside the browser, can use several tabs and browsers in one test, and comes with its own tools.


Languages

Playwright works with several programming languages:

  • JavaScript and TypeScript, with the Playwright Test runner
  • Python
  • Java
  • .NET (C#)

JavaScript and TypeScript get new features first, and have the most tools.

This tutorial uses JavaScript.

The last chapters show how to use Playwright with Python.


How a Test Runs

When you run your tests, three things work together:

  • The test runner finds your test files, runs the tests and reports the results
  • The browser is started by Playwright, usually without a visible window
  • The page is a browser tab that your test controls

Each test gets a new, clean page.

The test tells the page what to do, and then checks the result:

Example

test('can log in', async ({ page }) => {
  await page.goto('https://www.w3schools.com/playwright/practice/login.html');
  await page.getByLabel('Username').fill('student');
  await page.getByLabel('Password').fill('w3schools');
  await page.getByRole('button', { name: 'Log in' }).click();
  await expect(page.getByTestId('welcome')).toHaveText('Welcome, student!');
});

This test opens the login page, types a username and a password, clicks "Log in", and checks the welcome message.

You do not need to understand every line yet.

You will set up a project and write your first test in the next chapters.



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.