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

To use Playwright for browser automation: install the Playwright package, download the matching browser binaries, choose Playwright Test or a direct browser API, then write actions with resilient locators and assertions. Keep tracing enabled for useful failures. The workflow below uses JavaScript/TypeScript examples and includes equivalent Python, cURL, Node.js, and ScreenshotNeo options.

What Playwright can automate

Playwright drives Chromium, Firefox, and WebKit through one API. It also documents branded Chrome and Edge channels when testing those installations is part of your compatibility requirement. You can use it for end-to-end tests, smoke checks, regression suites, data-entry workflows, and one-off browser scripts.

There are two practical entry points:

  • Playwright Test: a managed test runner with fixtures, projects, retries, assertions, parallel execution, and trace configuration.
  • Direct browser APIs: explicit control over browser, context, and page lifecycles without adopting a test runner.

Use Playwright Test for a maintained test suite. Use direct APIs for a focused automation job, a utility script, or integration into another runner.

Install Playwright and its browsers

Start a Playwright Test project

  1. Install Node.js supported by your project.
  2. Run npm init playwright@latest.
  3. Choose TypeScript or JavaScript, select the test directory, and allow the installer to add a workflow if you need CI setup.
  4. Install browsers with npx playwright install.

Every Playwright package version expects specific browser binaries. Run the install command again after upgrading the package. In a Linux CI image where only Chromium is required, the documented pattern is npx playwright install --with-deps chromium; verify the option against the release installed by your project.

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.

Install the library for a standalone script

npm install playwright
npx playwright install

Python projects install the language package and then download browsers:

pip install playwright
playwright install

Playwright also supports .NET and Java. Keep the package release and downloaded browsers aligned in each environment.

Choose a browser and context deliberately

A browser process is expensive and represents an engine. A browser context is an isolated session with its own cookies, storage, permissions, and cache. Pages belong to contexts. Reuse one browser process while creating separate contexts for independent users or test cases.

import { chromium, firefox, webkit } from 'playwright';

const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
const page = await context.newPage();
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
console.log(await page.title());
await browser.close();

Switch chromium to firefox or webkit when that engine matters. Add branded Chrome or Edge channels only when your compatibility question specifically concerns those browsers; managed binaries usually provide more reproducible runs.

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

Write a maintainable first test

A Playwright Test file describes behavior, not implementation details. The example below logs in, checks the resulting heading, and captures a screenshot only when useful for a local run.

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

test('user can sign in', async ({ page }) => {
  await page.goto('https://example.com/login');
  await page.getByLabel('Email').fill('qa@example.com');
  await page.getByLabel('Password').fill('correct-horse-battery-staple');
  await page.getByRole('button', { name: 'Sign in' }).click();
  await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
});

Run it with npx playwright test. Use npx playwright test --headed to watch the browser, and npx playwright test --project=chromium when your configuration defines browser projects.

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.

Use locators that survive UI changes

Locators are the central piece of Playwright’s auto-waiting and retry behavior. A locator is resolved when an action or assertion runs, so it can find the current element after a re-render.

Preferred locator order

  • getByRole() for buttons, links, headings, checkboxes, and other accessible controls.
  • getByLabel() for form fields with an associated label.
  • getByText() for meaningful visible copy.
  • getByPlaceholder(), getByAltText(), or getByTitle() when those attributes express the control.
  • getByTestId() when your application intentionally publishes a stable test contract.

Use chaining and filtering to disambiguate repeated components:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const card = page.getByRole('article').filter({ hasText: 'Annual plan' });
await card.getByRole('button', { name: 'Choose' }).click();

CSS and XPath remain available, but long selectors tied to nested DOM structure tend to fail when markup changes. If two controls have the same accessible name, improve the page’s accessible labels or scope the locator to the correct region instead of adding an arbitrary positional selector.

Understand auto-waiting and assertions

Before locator.click(), Playwright checks that the locator resolves to exactly one element and that it is visible, stable, able to receive events, and enabled. It waits for those conditions and raises a timeout if they never become true. This removes many manual sleeps, but it cannot repair an application state that is genuinely stuck.

Assertions retry until their condition is met or the timeout expires:

await expect(page.getByText('Saved')).toBeVisible();
await expect(page.getByRole('textbox', { name: 'Status' })).toHaveValue('Complete');

Prefer an assertion about user-visible behavior over a fixed delay. Use page.waitForTimeout() only while diagnosing timing and remove it from the finished test.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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.

Generate a draft with Codegen

Codegen is useful when you need a starting point:

npx playwright codegen https://example.com

The CLI can target a browser, language, and output file. It prioritizes role, text, and test-id locators and can record visibility, text, or value assertions. Treat the result as a draft: remove accidental clicks, rename tests, narrow ambiguous locators, and keep only assertions that express the requirement.

Configure projects, retries, and traces

A Playwright Test configuration can run the same suite against several engines and define diagnostics centrally:

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

export default defineConfig({
  testDir: './tests',
  use: {
    baseURL: 'https://example.com',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure'
  },
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
    { name: 'webkit', use: { ...devices['Desktop Safari'] } }
  ]
});

trace: 'on-first-retry' records a detailed artifact only when a retry is needed. Tracing every run produces more diagnostic data but increases runtime and artifact volume. If you do not use retries, retain-on-failure is another documented retention policy.

Open a trace with:

npx playwright show-trace path/to/trace.zip

Trace Viewer exposes the action sequence, screenshots, DOM snapshots, logs, and source locations. The lower-level browserContext.tracing API records browser operations and network activity, but it does not capture test assertions; configure Playwright Test when assertion details matter.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Build a standalone Python automation script

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://example.com", wait_until="domcontentloaded")
    print(page.title())
    page.get_by_role("link", name="More information").click()
    browser.close()

The asynchronous Python API follows the same browser, context, page, locator, and assertion concepts. Explicitly close the browser in scripts, including cleanup paths.

Use network, identity, and page-state controls

Contexts can model the conditions your users encounter. Set a viewport, locale, timezone, permissions, extra HTTP headers, storage state, or a proxy at context creation. Route requests when a test must stub an unstable service, and block selected resource types when a performance check intentionally excludes them. Keep such controls visible in configuration so a test’s environment is understandable.

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

For authenticated suites, save a prepared storage state and load it into a new context rather than logging in through every test. Do not commit files containing real credentials or session cookies.

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

Troubleshoot common failures

Browser executable is missing

Cause: the package was installed without its binaries, or the binaries belong to another version. Fix: run npx playwright install (or the language-specific install command), then repeat it after package upgrades.

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

Timeout while clicking

Cause: the locator matched zero or multiple elements, the element stayed hidden or disabled, an overlay intercepted events, or the application never reached the expected state. Fix: inspect the locator in the trace, make it unique, wait for the meaningful state with an assertion, and investigate the overlay or failed network request. Avoid increasing the timeout until you understand the cause.

Tests pass locally but fail in CI

Cause: missing Linux dependencies, different browser binaries, slower resources, timezone, or environment data. Fix: install dependencies with the documented CI command, pin package versions, use deterministic test data, and collect a first-retry trace.

Codegen produced brittle selectors

Cause: the recorded page exposed no stable accessible name or test contract. Fix: edit the generated code to use roles and labels, add intentional test IDs where appropriate, and scope locators to a component.

A trace does not explain an assertion failure

Cause: tracing was captured through the low-level context API or was not enabled for the failing attempt. Fix: configure Playwright Test tracing, preferably on the first retry in CI, and rerun the failed test.

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.

Performance and reliability practices

  • Launch one browser per worker and create isolated contexts for tests.
  • Run independent tests in parallel only when their data and external side effects are isolated.
  • Use API setup or storage state for authentication instead of repeating a full login flow.
  • Keep assertions specific; broad page snapshots can hide the behavior that actually regressed.
  • Choose engine coverage based on the compatibility risk, not habit. Chromium-only smoke tests are faster; Firefox and WebKit runs reveal engine-specific defects.
  • Retain traces, screenshots, and videos on failure rather than for every successful run unless you have a deliberate diagnostic reason.

Or skip the browser setup

If your goal is a clean image or PDF rather than interactive browser control, ScreenshotNeo provides a website screenshot API and MCP server. One GET request captures a URL as PNG, JPEG, WebP, or PDF, while its pre-capture flow accepts consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Each step can be disabled.

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

See the ScreenshotNeo documentation for all options. The same request in Python is:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Plans include 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

FAQ

Should I use Playwright Test for every automation script?

No. Use direct browser APIs when you need a small, explicitly managed script; use Playwright Test when you need a durable suite with runner features and diagnostics.

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

Can one test run on all three engines?

Yes. Define separate projects for Chromium, Firefox, and WebKit, then run the projects that match the compatibility surface you support.

Why does a locator work once and fail after a re-render?

Prefer a locator object over storing an element handle. Locators resolve the current matching element when each action executes.

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.