Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Playwright is a browser automation framework for testing and scripting. Its Playwright Test runner adds test execution, assertions, fixtures, browser projects, and debugging tools. For a first TypeScript test, install the runner and its browser binaries, then describe a user action and verify the resulting page state with an auto-retrying assertion.

What is Playwright used for?

The Playwright project describes the tool as enabling “reliable web automation for testing, scripting, and AI agents.” It provides one automation API for Chromium, Firefox, and WebKit. Playwright Test is the project’s test runner; it adds such test-focused capabilities as fixtures, assertions, parallel execution, and tracing. See the official Playwright site.

This guide uses TypeScript and Playwright Test. Playwright also documents JavaScript, Python, Java, and .NET, but the package commands and test syntax differ by language.

What should you know before starting?

Basic familiarity with your chosen language, package manager, and HTML helps, but you do not need to learn browser internals first. For the TypeScript path below, have Node.js and npm available and be comfortable running commands in a project directory. The setup command creates a Playwright test project; it is not a universal command for the other supported languages.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How do you install Playwright with TypeScript?

  1. From the directory where you want the test project, run npm init playwright@latest. Follow the prompts to choose TypeScript and whether to add a GitHub Actions workflow or install browsers.

  2. If browser installation was skipped, install the default browsers with npx playwright install. To install just one, use npx playwright install chromium, npx playwright install firefox, or npx playwright install webkit. The CLI also offers npx playwright install --with-deps where system dependencies need installing, commonly on Linux CI machines.

  3. Run the generated tests with npx playwright test. Use npx playwright test --headed to watch browser windows while tests run, or npx playwright test --project=chromium to select a configured project.

Playwright releases are paired with compatible browser binaries. When you upgrade Playwright, rerun its CLI browser installation so the installed browsers match the package version. The current commands and browser-install details are documented in Playwright’s browser guide and writing tests guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do you write a first behavior-focused test?

This sample uses the Playwright Test runner and its test and expect imports. It opens the Playwright website, follows the visible “Get started” link, and verifies that the Installation heading appears:

import { test, expect } from '@playwright/test';

test('opens the installation guide', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  await page.getByRole('link', { name: 'Get started' }).click();
  await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});

The test expresses a journey and its expected outcome, rather than checking a CSS class or other implementation detail. The test file generated by the setup command can be replaced or extended with this example.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Which locators should you use?

Locators identify elements on the page. Prefer locators that reflect how a user or assistive technology identifies the control, especially role and accessible name:

page.getByRole('button', { name: 'Save changes' })
page.getByRole('link', { name: 'Account settings' })

Other locator methods, including text, label, placeholder, and test ID, are useful when they fit the interface. A locator that matches multiple elements ambiguously should be refined to identify the intended one; avoid blindly choosing the first match if that could hide a page defect. Playwright’s test generator can record interactions and suggest locators, but review generated code to confirm it represents the behavior you intend. See the locator guide and Playwright’s best practices.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does Playwright wait, and how do you avoid timing mistakes?

Playwright waits for actionability conditions before actions such as clicking. Its asynchronous web-first assertions retry while waiting for the expected state:

await expect(page.getByRole('status')).toHaveText('Saved');

By contrast, isVisible() reports the current state immediately. It does not wait for a future update, so treating it as equivalent to a retrying assertion can create a race. Prefer an assertion such as await expect(locator).toBeVisible() when the test needs to wait for visibility. Fixed sleeps are usually a poor substitute for asserting the state the test actually needs. Automatic waiting makes common interactions safer, but it does not make arbitrary script operations or application behavior immune to timing issues. Details are in the assertion guide and best practices.

How do fixtures and isolation work?

Playwright Test supplies built-in fixtures, including page, to tests. A fixture is a reusable resource or setup that the runner provides, not just a naming convention. Each test receives an isolated browser context, which helps prevent cookies, local storage, and other browser state from leaking between tests.

Use hooks such as beforeEach when shared setup makes several tests clearer. Keep test-specific behavior in the test where practical, so the setup remains understandable and a failure is easier to diagnose. See the fixtures guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Which browsers should your project test?

Playwright projects let one suite run against Chromium, Firefox, and WebKit, and can also use configured device profiles. These are Playwright-managed browser builds, not interchangeable names for branded browser installations:

Choose coverage based on your users and deployment needs: which browser engines matter, whether branded Chrome or Edge is required, whether desktop and emulated mobile profiles are relevant, and how much local and CI runtime your team can support. Platform-sensitive behavior such as media codecs may also make testing a branded browser channel useful. Consult the browser documentation for current channel and platform details.

When should you use Playwright for API testing?

APIRequestContext sends HTTP requests and supports validation of server APIs. Use it for service-level checks when you need to verify an endpoint’s response without driving a browser through the full UI. Use browser tests for user journeys whose value depends on the rendered page and interaction; endpoint checks do not replace those end-to-end checks. The API testing guide covers request-context usage.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

How do you run Playwright in CI?

A CI job needs the project’s dependencies and browser binaries, plus any operating-system dependencies required by those browsers. The official guide includes a GitHub Actions setup path; other providers may require adapting the workflow to their environment. Do not assume browsers installed on a developer’s machine are available in a clean CI runner.

For a GitHub Actions workflow, use the project’s setup output or follow the current Playwright CI guide. Revisit the browser-install step when updating Playwright, and choose the project matrix deliberately: all engines on every change provide broader coverage but take more runner time than a narrower fast-feedback job.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do you investigate a failed test with traces?

Trace Viewer can help reconstruct a test run using a timeline, DOM snapshots associated with actions, and network request information. A practical default is to collect traces on retry, then inspect a failing run through the test report or viewer:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    trace: 'on-first-retry',
  },
});

Trace collection has a performance cost, so avoid enabling it indiscriminately for every test unless that trade-off is acceptable. For a suspected intermittent failure, a targeted trace setting can provide evidence about what the page showed and which requests occurred without permanently tracing the entire suite. See the Trace Viewer guide and best practices.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common Playwright problems and fixes

  • Browser executable is missing: install the browsers with npx playwright install for the Playwright version in the project. Repeat after upgrading the package.

  • Browser launches locally but not in CI: check whether the runner has the necessary browser system dependencies and whether the workflow installed the required browser binaries. On supported Linux setups, the CLI’s --with-deps option can install dependencies.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Best Value
    Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
    • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
    • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
    • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
    • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
    • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • A locator matches more than one element: refine it with a more specific role, accessible name, label, or scoped locator so the test targets the intended control.

  • An assertion fails before the page updates: use an async web-first assertion that waits for the expected condition instead of a one-time state query or arbitrary delay.

  • A failure is hard to reproduce: enable trace collection on retry or for the targeted investigation, then review the timeline, DOM snapshots, and network activity.

Or skip the browser setup

If your goal is to capture a page screenshot rather than build a browser test, ScreenshotNeo provides a screenshot API and MCP server. One GET request returns an image or PDF; this cURL example saves a WebP screenshot of the Playwright homepage:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ScreenshotNeo API documentation

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://playwright.dev/ -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; those cleanup steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month—no card required.

Frequently Asked Questions

Can Playwright be used for AI-agent browser workflows?

Yes. The Playwright project describes its browser automation as suitable for AI agents as well as testing and scripting.

Does Playwright require a paid license to get started?

The official setup path described here installs the Playwright test runner and browser binaries in your project; consult the project’s current site for licensing and distribution details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.