Playwright Tutorial
Learn Playwright
Playwright is a free tool from Microsoft that tests websites in real browsers.
You write a test in JavaScript that opens a page, clicks and types like a user, and checks that the page shows the right result.
Playwright runs the test in Chromium, Firefox and WebKit.
What You Will Learn
This tutorial teaches you to write and run end-to-end tests with Playwright and JavaScript.
You will learn:
- What Playwright is, and how to set up a project
- How to write a test and run it from the command line
- How to find elements with locators, act on them, and check the result with assertions
- How to use the Playwright tools: Codegen, the Trace Viewer, UI mode and the HTML report
- How to configure browsers, retries, parallel runs and reporters
- Advanced topics: page objects, fixtures, login, network mocking, API testing, visual comparisons and running tests in CI
The last chapters show how to use Playwright with Python.
Learn with Practice Pages
All the examples test our own practice pages, made for this tutorial: Playwright Practice Pages.
There is a login page, a todo list, a sign up form and a small shop.
You can run every example on your own computer, against the same pages, and get the same result.
Why Learn Playwright?
Playwright tests a website the way a user uses it, from the first click to the last page.
This is called end-to-end testing.
Reasons to learn Playwright:
- One test runs in all major browser engines: Chromium, Firefox and WebKit
- Auto-waiting: Playwright waits for elements to be ready, so your tests are stable
- Good tools: a test generator, a trace viewer, a UI mode and an HTML report are built in
- It is free and open source
Prerequisites
You should know basic JavaScript before you start.
Playwright runs on Node.js, so you should also know how to run a command in a terminal and what npm is.
If you are new to these, start with our JavaScript Tutorial and our Node.js Tutorial.