Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Generate Playwright Tests with Codegen

Use Playwright Codegen to record a browser journey, add assertions, and create editable test code—then refine it to fit your project.

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.

Playwright Codegen records browser interactions and turns them into editable test code. In a project with Playwright installed, run npx playwright codegen https://your-site.example, perform the user journey in the opened browser, add assertions in the Inspector, then stop recording and copy the generated code into your test file. Treat that output as a starting point: review its locators and assertions, adapt it to your project, and run it as a test.

Record a test with the Playwright CLI

  1. Start Codegen. From your Playwright project, run npx playwright codegen https://your-site.example. Playwright opens a browser for the interactions and an Inspector that displays generated code. You can omit the URL and navigate to a page in the browser after launch.
  2. Perform the scenario. Click, fill, and navigate as a user would. Codegen records browser actions; choose a representative journey rather than clicking around without a test goal.
  3. Add assertions. In the Inspector, use its assertion control and select the relevant element. Documented choices include visibility, text, and value. Assertions make the test check an outcome, not just replay actions.
  4. Stop and review. Stop recording and copy the code into your test file. Read it in the context of your project’s fixtures, setup, and expected behavior, then add any missing checks.
  5. Run and refine. Run the test with your project’s usual Playwright test command. If a locator is ambiguous or brittle, use the locator picker and playground to inspect and refine it before copying.

Generate code in a chosen language or file

The CLI form is npx playwright codegen [options] [url]. Use --target to choose an output language, -o to write output to a file, and -b to select a browser: chromium, firefox, or webkit. For example, to generate Python output for a site, run:

npx playwright codegen --target=python https://your-site.example

To direct the output to a file, add -o and a filename, for example:

npx playwright codegen -o tests/recorded.spec.ts https://your-site.example

Use --test-id-attribute when your application uses a test-id attribute name other than the default expected by your project. Choose the output language and file arrangement to fit the test suite you intend to maintain; recording output does not automatically account for all of a suite’s conventions.

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.

Record from Visual Studio Code

With the Playwright VS Code extension, open the Testing sidebar and choose Record new to create a test by interacting with the browser. You can also record at the cursor to append actions to an existing test. The recording toolbar includes assertion controls, and the locator picker can copy a locator to the clipboard. Inspect the resulting test code just as you would CLI output.

Choose locators that remain understandable

After recording, use the locator picker to inspect a suggested locator and refine it in the locator playground. Codegen prioritizes role, text, and test-id locators and attempts to disambiguate multiple matches. Prefer a readable user-facing locator such as getByRole() when it accurately identifies the intended control. Review selectors against the interface and the test’s purpose; a generated locator is not automatically the right long-term contract for your test.

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.

Record under the conditions the test needs

Viewport, device, and appearance

Use emulation options when the scenario depends on screen size, device, color scheme, timezone, location, or language. Documented flags include --viewport-size, --device, --color-scheme, --timezone, --geolocation, and --lang. Examples:

npx playwright codegen --viewport-size="800,600" https://playwright.dev
npx playwright codegen --device="iPhone 13" https://playwright.dev
npx playwright codegen --color-scheme=dark https://playwright.dev

Record using settings that reflect the conditions under which the test is expected to run. Otherwise, the recorded flow may not represent the target scenario.

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.

Reuse an authenticated session safely

To save browser state at the end of a recording, use --save-storage=auth.json; to restore it in a later session, use --load-storage=auth.json. Saved state can include cookies, local storage, and IndexedDB data. Treat it as a secret: keep it local, exclude it from Git, and delete it when it is no longer needed. Browser state may contain credentials or headers that could let someone impersonate an account.

Use a dedicated browser profile

--user-data-dir lets Codegen use a dedicated browser profile. Playwright’s Codegen guide notes a Chrome 136 change: automation cannot access the default user data directory, so create a separate directory for testing instead.

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

Handle HTTP Basic Authentication carefully

--http-credentials supplies HTTP credentials. The documented scope matters: credentials can be sent to any origin that requests them during the session, and they are included in generated code. Avoid recording sensitive credentials into test files that may be shared or committed.

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

Open Codegen from a custom setup

For a non-standard browser context, the documented approach is to launch a headed browser, create a context, and call page.pause() to open Codegen controls. This lets you prepare the context before recording rather than relying only on the default CLI launch.

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.

Common problems and fixes

  • The recording contains actions but does not verify success. Add assertions deliberately using the Inspector or VS Code assertion controls, then check that they match the behavior the test is meant to protect.
  • A locator matches multiple elements or the wrong one. Stop recording, use Pick Locator, inspect the suggestion in the locator playground, and refine it. Prefer a clear role and accessible name when those identify the intended control.
  • The generated code does not fit the project. Copy or write the output into the intended test file, then adapt it to the project’s fixtures, setup, and conventions. Generated scripts are a starting point, not a claim that every project-specific check is already present.
  • The flow behaves differently on another device or locale. Record with the relevant viewport, device, color scheme, timezone, geolocation, or language options, and ensure those conditions match the scenario being tested.
  • A saved session exposes account access. Keep the storage-state file out of source control, restrict access, and remove it when done. Review generated code for embedded credentials before sharing it.
  • Automation cannot use the default Chrome profile. For Chrome 136 and later, use a separate directory with --user-data-dir rather than the default user data directory.

Or skip the browser setup

ScreenshotNeo is a website screenshot API, not a Playwright test generator: it returns a screenshot or PDF of a URL rather than recording interactions into a test. If your task is capturing a page image, one GET request is enough. See the ScreenshotNeo API documentation for request options.

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

ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Learn more at ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Codegen record a flow without opening a URL in the command?

Yes. Omit the URL from the CLI command and navigate to the site in the browser after Codegen opens.

Can I add recorded actions to a test I already have?

Yes. In the VS Code extension, use Record at cursor to append actions to an existing test.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.