How to Use Playwright to Run Tests

Kailash Pathak

Posted On: July 3, 2025

view count61994 Views

Read time8 Min Read

Playwright is an open-source framework that supports end-to-end testing through multiple browser and OS combinations. You can use Playwright to run tests across various rendering engines like Chromium, WebKit, and Firefox using a single API. Its cross-browser support ensures your website works as expected across all major browsers and browser versions.

Overview

Playwright is an end-to-end testing framework to run tests across multiple browsers and operating systems using a single API. It supports web browsers such as Chromium, Firefox and WebKit.

Steps to Use Playwright to Run Tests

  • Install Node.js.
  • Download Playwright and its required dependencies and browsers using the npm init playwright@latest command.
  • Write your first test using Playwright’s built-in test runner and an intuitive browser automation API.
  • Run tests across all supported browsers using the npx playwright test command.

How to Run Tests in Playwright?

Below are the steps to install Playwright, write your first test, and run it across browsers such as Chromium, Firefox, and WebKit.

Install Playwright

1. Install the latest version of Node.js. Once installed, you can confirm your Node.js version by running the following command:

2. Install Playwright using the below given command, which sets up everything: project files, dependencies, and browsers:

Once the installation is completed, you’ll see a playwright.config.ts file (or .js if you chose JavaScript), a package.json with dependencies, and a sample test file.

Note: Playwright doesn’t rely on your system’s browsers. Instead, it fetches its versions of Chromium, Firefox, and WebKit (Safari’s engine). These browsers are tied to Playwright’s release.

Write Your First Test

The ltKaneAi.spec file below automates the process of filling out the “Schedule a Demo” form on the LambdaTest KaneAI page.

Test Scenario:

  1. Visit the KaneAI website.
  2. Click on the Book a Demo button.
  3. Fill in personal and contact information.
  4. Provide a custom message to schedule the demo.

Run the Test

To run the tests, execute the following command in the terminal:

command

Using Playwright to run tests may help test how your website behaves on different browsers, such as Chromium, Firefox, and WebKit. However, there are a couple of challenges with scalability and reliability as your testing needs grow.

To overcome these challenges, opting for cloud-based testing solutions such as LambdaTest is a viable option.

How to Run Playwright Tests on LambdaTest?

LambdaTest is a GenAI-native test execution platform that allows you to perform Playwright automation across various browsers and operating systems.

By moving test execution to cloud testing platforms like LambdaTest, you can reduce costs related to setting up test infrastructure and accelerate your software release cycles.

To get started, refer to the documentation on Playwright testing with LambdaTest.

If you want to perform Playwright automation on the LambdaTest platform, update your test script to connect using the LambdaTest WebSocket URL.

After that, add your LambdaTest Username and Access Key as environment variables and define automation capabilities for browser, browser version, platform and other settings.

You can generate the above Playwright capabilities from the LambdaTest Automation Capabilities Generator.

After that, you can run the tests using the following command:

Now, visit the LambdaTest Web Automation dashboard to view the test execution results.

Web Automation dashboard

Methods to Run Playwright Tests

Playwright lets you run tests across different browsers with a single test suite. There are five different methods to perform Playwright automation.

Default Browser Configurations

By default, Playwright includes Chromium, Firefox, and WebKit rendering engines, and you can switch between them easily.

You can define multiple projects in your config file to target different browsers:

After doing the above configuration, run the command:

Let’s take a test scenario of the ltKaneAi.spec file and run it with default browser configurations using the below command:

Specific Browser From CLI

You can run tests on a specific browser by passing the project name.

Execute the below command to run the test cases in all three browsers.

UI Mode

Playwright UI Mode is a visual, interactive test runner that helps you explore, debug, and execute tests smoothly. You can launch UI mode by running the below command:

At the top-left corner of the UI Mode window, you’ll see a browser selector dropdown. From here, you can instantly switch between Chromium, Firefox, and WebKit.

Headed Mode

By default, you can perform Playwright browser testing in headless mode (no visible browser UI).

To launch browsers in headed mode, you can modify the playwright.config.js file and set the headless option to false.

To run the test cases in headed mode, use the following command:

CI Pipelines

You can also perform Playwright browser testing through CI pipelines.

Here’s an example of using GitHub Actions with Playwright:

How to Run Playwright Tests in Parallel?

To speed up test execution, you can use Playwright to run tests in parallel. By default, Playwright runs tests in parallel across multiple workers.

A worker in Playwright is an isolated environment that the test runner uses to run tests in parallel.

You can control the number of workers using the –workers flag:

You can also configure the workers property in your playwright.config.ts file:

For more advanced parallelization strategies, such as running tests fully in parallel or sequentially, you can use the fullyParallel and mode options in your configuration file.

Conclusion

Playwright makes it easy to get started with browser automation, from setup to writing and running your first test. It supports testing across all major browsers out of the box, ensuring cross-browser compatibility.

Moreover, you can also use Playwright to run tests on cloud-based testing platforms like LambdaTest to improve your testing efficiency and get much-needed scalability and reliability.

With different methods to run tests, such as through the default configuration file, CLI targeting, UI mode, headed mode, and CI/CD integration, Playwright can adapt to your various testing needs.

Citations

Frequently Asked Questions (FAQs)

How to run a Playwright test?

To run a Playwright test, you can use the npx playwright test command in your terminal.

Does Playwright have a test runner?

Yes, it comes with a built-in test runner: @playwright/test.

How do I run a single Playwright test file?

You can use the npx playwright test tests/example.spec.ts command to run just one file.

How do you run tests in order in Playwright?

Playwright runs tests in parallel by default, so order isn’t ensured. To run tests in sequence, combine steps in a single test or use the test.describe.serial() block for ordered execution.

How does Playwright run tests across multiple browsers?

Playwright uses the projects option in the config file to define and run tests in Chromium, Firefox, and WebKit.

How to run Playwright tests through CI?

To run Playwright tests through CI, configure your pipeline to install dependencies, Playwright browsers, and then execute the tests using the npx playwright test command. This works in a headless environment and can be customized via the playwright.config.ts file.

Author Profile Author Profile Author Profile

Author’s Profile

Kailash Pathak

Currently working as Sr. Quality Lead Manager in a US-based MNC company. Where I am responsible for setting up the overall QA Automation strategy and ensuring that we deliver a high-quality product to our end users. Apart from my role, I have involved myself in educating the community about Software Testing and Test Automation. I am a Blogger and YOUTUBER. I have written a couple of blogs which can find out on my site https://qaautomationlabs.com/

Blogs: 11



linkedintwitter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free