Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
Explore Playwright with this tutorial! Learn how to set up and use Playwright for seamless automated testing with practical examples.
Published on: July 21 2025
Playwright is an open-source framework for automating and testing web applications across Chromium, Firefox, and WebKit. Due to its cross-browser support, fast execution, and robust API, it enables reliable Playwright testing across modern browsers and platforms.
Built by Microsoft, Playwright is a Node.js library that, with a single API, automates websites and web apps running on Chromium, Firefox, and WebKit. These APIs can be used by developers writing JavaScript code to create new browser pages, navigate to URLs, and then interact with elements on a page.
In addition, since Microsoft Edge is built on the open-source Chromium web platform, Playwright can also automate Microsoft Edge.
Playwright launches a headless browser by default. The command line is the only way to use a headless browser, as it does not display a UI. Playwright also supports running full (non-headless) Microsoft Edge.
Playwright stands out due to its cross-browser, cross-platform, and cross-language capabilities. It's trusted by developers and QA engineers for Playwright automation because of its consistent architecture, rich tooling, and flexibility for complex test scenarios.
Here’s why it’s a popular choice:
Note : Now test your mobile apps with Playwright - Checkout how!
To understand how Playwright's architecture works, we’ll compare it with Selenium.
When we talk about Selenium or compare it with Playwright automation, we mean that Selenium sends each command as an independent HTTP request and receives JSON responses.
Each interaction, such as opening a browser window, clicking an element, or entering text into an input box, is sent as a separate HTTP request.
Instead of communicating with each driver through a separate WebSocket connection, Playwright relies on a single WebSocket connection to communicate with all drivers, which remains in place until testing is finished.
This allows commands to be sent quickly over one connection, reducing the points of failure and improving test stability. It's one of the reasons Playwright testing is preferred in modern automation pipelines.
Follow these steps to install Playwright manually via terminal:
npm init -y
npm init playwright@latest
This sets up the foundation for your Playwright automation environment. Make sure Node.js is already installed on your system. If not, download and install it from the official Node.js website.
Follow these steps to install Playwright using Visual Studio Code:
Ctrl + Shift + X
Ctrl + Shift + P (or Cmd + Shift + P on macOS)
Install Playwright
These steps will set up your project so you can start writing your Playwright tests.
Let’s get started with your first Playwright test case using TypeScript. For demonstration purposes, you’ll run the test locally on the LambdaTest eCommerce Playground website.
Test Scenario:
|
Code Implementation:
import { test, expect } from '@playwright/test';
test('shop by category button has aria-expanded false', async ({ page }) => {
await page.goto('https://ecommerce-playground.lambdatest.io/');
await expect(page.getByRole('button', { name: 'Shop by Category' })).toHaveAttribute('aria-expanded', 'false');
});
Code Walkthrough:
Test Execution:
To execute the tests, run the below command:
npx playwright test
The image below shows the test execution report, run the following command given below:
npx playwright show-report
Running tests on a single setup might work for small projects, but it quickly becomes limiting when dealing with larger test suites or legacy systems. To ensure consistent performance across browsers and platforms, you need a scalable solution.
LambdaTest, a GenAI-powered test execution platform, lets you run Playwright tests in parallel across 3000+ real browser and OS combinations, helping you scale your Playwright tests efficiently without managing infrastructure.
The above test scenarios have been executed on the local grid. To run the same Playwright tests on the LambdaTest cloud platform, a few additional configurations are required in your local setup.
Code Implementation:
To get started, refer to the documentation on Playwright testing with LambdaTest.
To run Playwright automation on LambdaTest, update your test script to connect via the LambdaTest WebSocket URL.
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
Next, set your LambdaTest Username and Access Key as environment variables, and define the browser, version, platform, and other automation capabilities needed for Playwright testing.
// LambdaTest capabilities
const capabilities = {
browserName: "Chrome", // Browsers allowed: 'Chrome', 'MicrosoftEdge', 'pw-chromium', 'pw-firefox' and 'pw-webkit'
browserVersion: "latest",
"LT:Options": {
platform: "Windows 11",
build: "Playwright Demo",
name: "Playwright Demo",
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
network: false,
video: false,
console: false
},
};
You can generate the required capabilities using the LambdaTest Automation Capabilities , based on your desired test setup.
Once generated, add them to your setup and then modify your test file to import the custom test method defined in the lambdatest-setup.ts file.
import { expect } from '@playwright/test';
import test from "../lambdatest-setup";
Test Execution:
Now execute the tests using the below command:
npx playwright test
Head over to the LambdaTest Web Automation Dashboard to monitor your test execution results in real time.
When performing Playwright testing, here are some of the best practices you can follow:
You can explore the Playwright resources listed below to deepen your understanding and enhance your learning journey. These resources provide valuable insights, tutorials, and best practices that will help you gain a more comprehensive knowledge of the subject.
Complete Playwright Java Tutorial
Complete Playwright TypeScript Tutorial
Playwright JavaScript Tutorial
In addition to the above learning resources, it’s essential to elevate your Playwright skills further.
Following are the LambdaTest Certifications in Playwright that provide a great opportunity to validate and showcase your expertise, taking your knowledge to the next level.
On This Page
Did you find this page helpful?
Get 100 minutes of automation test minutes FREE!!