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 desk6 min

How to Generate Playwright Tests and Scale Browser Automation

A practical guide to recording Playwright tests, reviewing generated code, and scaling browser automation safely with projects, workers, and CI shards.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Playwright’s code generator to record a representative browser journey, then review the generated test before relying on it. To scale a reliable suite, first make tests independent, choose browser and device coverage with projects, and increase concurrency deliberately: workers add parallelism within a job, while shards distribute work across CI jobs or machines.

Record a browser journey with Playwright

From your project directory, run the generator with the starting URL:

As an Amazon Associate I earn from qualifying purchases.

npx playwright codegen https://your-site.example

The command opens a browser and the Playwright Inspector. Perform the journey you want to test; the generator records interactions and proposes test code. Stop recording and copy the result into your project. The URL is optional, so you can also launch codegen without one and navigate in the opened browser. See the Playwright codegen guide for the current workflow.

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

Review generated tests before keeping them

Codegen is a starting point, not proof that a test covers the intended behavior. Read the code and check that it includes the right setup, meaningful assertions, and the expected outcomes—not merely the clicks and typing you performed.

Playwright prioritizes role, text, and test-id locators, and attempts to make a locator unique when it finds multiple matches. Confirm that each locator identifies the semantically correct element. A unique locator can still target the wrong control, and interactions without assertions may not verify that the user journey succeeded. The Playwright best-practices guide explains locator and assertion practices.

Record a signed-in flow without exposing credentials

If you need codegen to begin in an authenticated session, load saved browser storage:

npx playwright codegen --load-storage=auth.json https://your-site.example

Playwright can use this state to restore cookies, local storage, and IndexedDB for a recording session. Treat the file as sensitive: keep it out of version control, use it locally, and delete it when you no longer need it. See Playwright’s generator and authentication documentation.

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

Organize browser and environment coverage with projects

A Playwright project is a logical group of tests that shares configuration. Projects let you express a coverage matrix—for example, the same tests under different browsers or device settings, or distinct groups for different environments. Choose the matrix based on the behavior you need to verify and the execution capacity available; adding projects can expand coverage and work to run.

Project dependencies allow setup projects to run before projects that depend on them. Browser projects then run subject to the configured worker limit. Consult the projects guide and configuration reference for the syntax supported by your installed version.

Scale execution with workers or shards

Playwright Test runs test files in parallel by default, while tests within a single file run in order by default. Parallel work is handled by separate worker processes; workers do not share in-memory state. Make tests independent and isolate their data before increasing concurrency, or parallel execution can expose collisions and order-dependent behavior.

Workers: concurrency within one job

Set a worker limit to control concurrent worker processes. For example, this command requests four workers:

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.
npx playwright test --workers=4

Four is an example, not a universal tuning recommendation. The useful limit depends on the machine’s CPU and memory, browser resource use, CI limits, and the suite’s ability to run tests independently. More workers can increase resource contention rather than improve completion time.

Shards: distribute the suite across jobs

Sharding divides a suite so separate CI jobs or machines can run different portions. For example, the following command selects shard two of three:

npx playwright test --shard=2/3

Configure the CI workflow to start the corresponding shard jobs and collect their reports. A shard is a distribution unit, not a performance guarantee: job startup, available machines, suite balance, and report collection affect the outcome. Playwright’s CI guide includes CI-specific configuration examples.

Choose a scaling path

Approach Where concurrency happens Best fit Trade-off to check
Workers Within one test job A job has spare resources and tests can safely run independently. Higher concurrency increases resource use; shared test data or accounts can cause interference.
Shards Across multiple jobs or machines The CI workflow can run separate jobs and the suite benefits from distribution. Requires coordinated shard configuration and report handling; actual gains depend on job capacity and suite balance.

These approaches can be combined, but choose their limits in light of total CI capacity rather than tuning each job in isolation.

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

Use stability-oriented CI settings and interpret retries

Playwright recommends one worker in CI to prioritize stability and reproducibility. This is a stability-oriented starting point, not a rule for every environment. If you need broader parallelization, the CI guide describes distributing execution with shards across jobs. Match the configuration to available hardware, CI resource limits, and test independence.

Retries are disabled by default. When enabled, a test that fails initially but passes on retry is reported as flaky; one that continues failing through its retries remains failed. A retry can help reveal intermittency in reports, but it does not fix the underlying cause. Investigate flaky results rather than treating a retry pass as an uncomplicated success. The retry guide and configuration reference document retry and trace settings.

Run and diagnose a suite with the CLI

Use a project name that exists in your configuration to run that project, and adjust worker and shard values to match your machine or CI plan:

npx playwright test --project=chromium
npx playwright test --workers=4
npx playwright test --shard=2/3

These commands illustrate selection and configuration; they do not prescribe a universal worker count or shard layout. For exact CLI options, check the Playwright CLI reference for the version installed in your project.

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

Common problems and fixes

  • The generated test clicks but does not prove success: add assertions for the user-visible result and review setup and expected outcomes.
  • A locator is unique but acts on the wrong element: inspect the page and choose a locator that represents the intended control, then verify its behavior.
  • Tests fail only when workers run concurrently: look for shared accounts, mutable records, or other shared state. Isolate test data and make tests independent before raising the worker limit.
  • CI results are less stable at higher worker counts: reduce workers and check CPU, browser memory, and CI resource limits; consider sharding across jobs if wider execution is needed.
  • A test passes only after a retry: use the flaky report as a signal to investigate timing, shared state, or other intermittent causes rather than treating the retry as a repair.
  • An authenticated recording uses the wrong session or leaks state: verify the intended storage file was loaded, keep it out of source control, and remove it when no longer needed.
  • A CLI option or project name is rejected: check spelling and the installed Playwright version, and confirm the project exists in the configuration. CLI details can be version-sensitive.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a website screenshot rather than an interactive Playwright test, ScreenshotNeo can return an image or PDF from one GET request. Its screenshot API is not a replacement for browser test coverage; it is an option when you need a capture without setting up a browser session yourself.

cURL example, with the API details in the ScreenshotNeo documentation:

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

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, and cache hits are not billed. Its MCP server offers screenshot, page-info, and PDF tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up free for 1,000 screenshots a month, with no card.

Frequently Asked Questions

Can I run tests from one Playwright project in parallel?

Yes. Select the project with --project; its tests follow the configured worker limit, so check your project configuration and available resources.

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

Does a passing retry mean a flaky test is fixed?

No. A fail-then-pass result is reported as flaky; investigate the intermittent cause rather than treating the retry as a fix.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.