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

Use Playwright Codegen to record a browser journey and turn it into a test draft: run npx playwright codegen https://your-site.example, interact with the page, add assertions in the Inspector, then copy and refine the generated code. Codegen can also record from Playwright’s VS Code extension. Treat the result as a starting point—not a finished test—because you still need to check its locators, assertions, setup, and expected behavior.

Generate a test from a browser flow with the CLI

Run Codegen from a project where Playwright is available. It opens a browser for you to use and Playwright Inspector, which displays the generated code. You can supply a page address at launch or omit it and navigate in the browser.

  1. Start a recording: run npx playwright codegen https://your-site.example. Replace the example address with the page where the flow begins.
  2. Perform the journey: use the opened browser as a real visitor would. Codegen records interactions such as clicks and filling fields.
  3. Add checks: use the Inspector’s assertion control and select an element to add a visibility, text, or value assertion. Actions alone do not verify that the application behaved correctly.
  4. Stop and copy: stop recording, inspect the generated code, and copy it into the project’s test file.
  5. Refine and run: review selectors, add any missing checks, and adapt the test to the project’s fixtures and setup before relying on it.

For example, a sign-in recording should not end with only a button click and form fills. Add a check for the expected post-login result—such as a visible account heading—so the test can distinguish success from a page that merely accepted input.

Record directly in Visual Studio Code

If you use the Playwright VS Code extension, open the Testing sidebar and choose Record new to create a test by recording. The extension writes the recorded code into a test file. You can also choose to record at the cursor to append actions to an existing test. Its recording toolbar includes assertion controls, and the locator picker can copy a locator to the clipboard. Review the file after recording just as you would code copied from Inspector.

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.

Choose the output language, browser, and destination

The CLI form is npx playwright codegen [options] [url]. Use the options that fit the project rather than recording under arbitrary defaults.

Need Option or example What it does
Write output to a file -o tests/example.spec.js Saves generated code to the specified output file.
Select a target language --target=python Sets the generated code language. Choose a target compatible with the project where the test will live.
Select a browser -b firefox Chooses a browser; documented choices include chromium, firefox, and webkit.
Set a test ID attribute --test-id-attribute data-pw Configures which attribute Codegen treats as the test ID attribute.

For instance, a Python recording saved to a file can be started with npx playwright codegen --target=python -o test_example.py https://your-site.example. Confirm the exact option syntax against the Playwright Codegen documentation if your installed release behaves differently.

Record under the conditions the test should cover

Viewport, device, locale, color scheme, timezone, and location can change what a page displays. Codegen supports options for setting these conditions, so record with settings that reflect the scenario the eventual test is meant to verify.

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.
  • --viewport-size="800,600" sets a viewport size.
  • --device="iPhone 13" emulates a named device.
  • --color-scheme=dark requests dark color scheme.
  • --timezone="America/New_York", --geolocation="37.7749,-122.4194", and --lang="en-US" set timezone, geolocation, and language.

Example: npx playwright codegen --viewport-size="800,600" https://playwright.dev. These settings make the recording context more representative; they do not remove the need to run and validate the test in the project’s intended environment.

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

Handle authenticated pages without leaking account state

For a flow behind login, Codegen can save and restore browser state. Start a session with --load-storage=auth.json to load saved state, and use --save-storage=auth.json to save cookies, local storage, and IndexedDB data at the end of the session. A saved file may contain information that grants access to an account.

  • Keep authentication-state files local and out of source control; add them to .gitignore.
  • Delete a state file when it is no longer needed, and do not attach it to a bug report or share it casually.
  • Review generated code for credentials or other secrets before committing or sharing it.

Playwright’s authentication guidance likewise warns that browser state can include cookies or headers that can impersonate an account.

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.

Using HTTP Basic Authentication

The --http-credentials option supplies HTTP credentials. The documented scope matters: credentials may be sent to any origin requesting them during the session, and they can appear in generated code. Use it only when that scope is appropriate, and remove or securely manage credentials before sharing the test.

Using an existing browser profile

Codegen supports --user-data-dir to use a dedicated browser profile. Playwright’s Codegen guide notes that, following a Chrome 136 change, automation cannot access Chrome’s default user data directory; create and use a separate directory for testing rather than pointing automation at the default profile.

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

Improve generated locators before keeping the test

Generated selectors are suggestions to inspect, not guarantees that the test expresses the right contract. After stopping the recording, use Pick Locator to select an element, examine the suggested locator, and refine it in the locator playground before copying it.

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
  • Prefer readable, user-facing locators such as getByRole() with an accessible name when they uniquely identify the intended control.
  • Use a test ID when the application has an explicit, stable test contract for that element.
  • Check whether the locator matches one intended element. Codegen attempts to disambiguate multiple matches, but you should verify the result in the context of the page.
  • Avoid preserving a brittle locator just because it was generated. If the page structure changes, a locator tied to incidental markup may break even when the user-facing behavior has not changed.

See Playwright’s locator guidance for the locator strategies and APIs available to tests.

Use Codegen with custom setup

If the default recording launch does not match the project’s setup, Playwright documents a headed-browser approach: launch a browser, create a context and page, then call page.pause() to open Codegen controls. This is useful when you need to establish context configuration in code before recording. Adapt the setup to the project’s installed Playwright language and fixtures rather than pasting a standalone example unchanged.

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

Common problems and fixes

Problem Likely cause What to try
The Codegen command is not found or fails to start Playwright is not available in the project context, or the command is being run from the wrong directory. Run it from the project where Playwright is installed and use npx playwright codegen.
The test contains actions but does not catch a failed outcome No meaningful assertion was added during recording. Use Inspector’s assertion control or add an assertion in the test for the behavior that defines success.
A locator matches more than one element or breaks easily The recorded page has duplicate labels or the selector depends on incidental structure. Use Pick Locator and the locator playground; prefer a specific role and accessible name or a deliberate test ID.
A login recording loses its session Browser state was not saved or was not loaded for the recording. Use --save-storage=auth.json and --load-storage=auth.json as appropriate, and protect the state file as a secret.
Automation cannot use the default Chrome profile Chrome 136 changed access to the default user data directory. Configure a separate profile with --user-data-dir.
Credentials appear in generated output or reach an unexpected origin HTTP credentials were recorded and can be sent to any origin requesting them during the session. Avoid recording sensitive credentials into shareable code; remove them from output and use a safer project-specific secret-handling approach.
The recording looks different from the intended test run Viewport or emulation conditions differed. Record with the relevant viewport, device, color scheme, timezone, geolocation, and language options.

Or skip the browser setup

If you need a screenshot of a page rather than an interactive test, ScreenshotNeo can return an image or PDF with one API request. It is a screenshot API and MCP server—not a replacement for Playwright test generation.

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.
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.

ScreenshotNeo API documentation · cURL:

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

Cookie banners are accepted before capture and more than 60 known consent platforms, newsletter popups, and chat widgets are removed; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I generate Playwright tests in Python?

Yes. Use the CLI’s --target=python option to generate Python output.

Does Codegen create a complete, production-ready test automatically?

No. It records interactions and helps produce a starting point; review and adapt the code, locators, and assertions for the behavior your project needs.

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

Can I use Codegen without entering a URL in the command?

Yes. Omit the URL and navigate to the page in the browser after Codegen opens.

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.