r/Playwright • • 5h ago

Is there a better way to maintain Playwright scripts without constantly fixing selectors?

3 Upvotes

Quick question for anyone maintaining a decent-sized collection of Playwright scripts.

What's your strategy for dealing with third-party websites where you can't control the HTML?

Role-based locators help, but they're not exactly foolproof. Button labels change, elements move around, and sometimes an entirely new component replaces an existing one.

Would something like Oya Browser be useful for reducing maintenance here, or is investing more time in locator strategies still the better long-term approach?

Not necessarily looking for a replacement for Playwright. More interested in making existing automation less fragile.

Any suggestions?


r/Playwright • • 6h ago

Engenious University

1 Upvotes

Has anybody taken their courses, and are they good?


r/Playwright • • 13h ago

Built an open-source Python Playwright test runner driven by a local LLM (only tested on SauceDemo so far — looking for locator/DOM feedback)

1 Upvotes

Hey everyone, I'm building an open-source Python + Playwright project for my college capstone and wanted to get some Playwright-specific feedback before my final review.

Repo if you want to look at the code: https://github.com/saturn-16/Autonomous-Web-Testing-Agent

The goal was to take a target URL + a plain english prompt (like "add Bolt T-Shirt to cart and go to checkout"), explore the live page using a local LLM (Ollama / llama3.2, with cloud API fallback), and then run an independent pass/fail audit + export HTML/MD/JSON reports with screenshots streamed to a local web UI.

Where Playwright actually ended up doing most of the heavy lifting:

- Control inventory & locator fallback: Instead of letting the LLM write CSS selectors from scratch (which broke constantly), I extract interactive controls from the DOM along with source hints (text, value, placeholder, id) and run a fallback locator chain. I also had to strip out temporary data-agent-id attributes after interacting so injected IDs wouldn't pollute later state comparisons.

- Overlay recovery: When a click gets blocked, it tries closing slide-out menus, role=dialog modals, or sending Escape before marking the action futile.

- Mechanical state/safety checks: Off-domain links are checked via window.location.origin, and each state gets hashed from URL + visible controls so we catch no-op clicks and login error loops instead of burning max steps.

Being completely honest about where this stands: live browser testing has only been run end-to-end on saucedemo.com and local test fixture HTML pages so far. I haven't battle-tested it against messy real-world SPAs, heavy shadow DOM, nested iframes, or dynamic React/Angular hydration quirks yet, and even SauceDemo's final checkout confirmation steps still need work.

Two questions for people who write Playwright every day:

  1. For extracting clickable controls reliably across real SPAs, are there better Playwright patterns (like ARIA/accessibility tree snapshots vs DOM querying) that handle shadow DOM and dynamic modals more cleanly?
  2. Would adding a "record & export a clean deterministic Playwright Python test" after a successful LLM run make this way more practical for real teams, so nobody has to run an LLM in CI?

Appreciate any blunt Playwright advice or code critique!


r/Playwright • • 14h ago

Best Test Orchestration Platforms for Playwright CI

Thumbnail currents.dev
2 Upvotes

Playwright's --shard=x/y splits the suite before the run, and by default it splits by whole test file. If some files hold many more tests than others, one shard runs much longer than the rest. merge-reports then waits for that slowest shard. One failed test or one dead runner can also force a rerun of far more tests than the ones that broke.

We compared 10 tools that try to fix this: Currents, Knapsack Pro, Buildkite Test Engine, CircleCI, Testkube, Harness, Azure Pipelines, TestMu AI HyperExecute, BrowserStack and Sauce Labs. Each tool gets the same five checks: a live queue or a pre-run split, a file-level or test-level split, your own runners or the vendor's cloud, reruns of only the failed tests, and one merged run or report. All claims come from each vendor's own docs. We ran no benchmarks and quote no prices. The post also covers when built-in sharding is enough, with a GitHub Actions setup that uses fullyParallel: true, blob reports and merge-reports.

Disclosure: I work at Currents, and Currents is one of the 10 tools.

How do you split your Playwright suite in CI today? Is plain --shard enough, or did you hit uneven shards?


r/Playwright • • 22h ago

How should I start with Playwright + AI automation?

14 Upvotes

Hey everyone!

I have around 1 year of experience in manual testing and want to move into automation, particularly Playwright with TypeScript and AI testing.

I'm a beginner at coding, so I'm trying to figure out the right way to start.

A few things I'd love your advice on:

  • Should I learn JavaScript first or jump into TypeScript?
  • Which tools should I focus on besides Playwright? (MCP, CLI, Copilot, Claude, ChatGPT, etc.)
  • How are companies actually using AI in automation testing?
  • What practical projects should I build to become job-ready?
  • How can I transition from manual testing into an automation role?
  • What skills are companies looking for when hiring junior automation engineers?

If you were starting today, what would your learning path look like?

I can dedicate around 20–25 hours a week and really want to use my time wisely.

Would love to hear advice from people already working in Playwright, automation, and AI testing.

Thanks!


r/Playwright • • 1d ago

Playwright priciples and best practices

4 Upvotes

Hi everyone,
I'm setting up Playwright MCP so an AI agent can drive the browser and write/run tests. Before I build a reference guide for it, I'd like to learn from people already doing this.
What core principles and best practices would you recommend when an AI uses Playwright MCP?
In particular:
Locators: How do you get the AI to prefer role-based/accessible locators over brittle CSS/XPath?
Snapshots vs. screenshots: When should the agent rely on the accessibility snapshot, and when on vision?
Waiting & stability: How do you avoid flaky tests and unnecessary hard waits?
Scope & safety: Any rules to keep the agent from taking unnecessary actions or leaking credentials/test data?
Prompting: Are there instructions or rule files you give the agent so the generated tests stay consistent and maintainable?
If there's an official guide, a repo, or a prompt/rules file you use as a reference, I'd really appreciate a link.
Thanks in advance!


r/Playwright • • 1d ago

whats the difference in syntax when defining locators by test id?

3 Upvotes

I have a personal project that I built and Im runing PW on CI/CD and Vue. So far everything is working, Im adding new components and making test files for them as I go. At work I use AI for basically everything, but I want to keep my code skills sharp so Im doing everything manually. I understand that AI is the future but I worked too hard to forget how to code (if anyone is wondering).

This is the issue Im running into. I have a main locator file using a class to define locators. When I use test-ids sometimes I have to define locators two different ways.

this.cookieBanner = page.getByTestId('cookieBanner');

this.cookieBanner = page.locator('[data-test="cookieBanner"]');

The way Ive been working through this is to try one, if it doesnt work, Ill use the PW console to get the locator, and it will suggest the other one, that will end up working. I'd like to be able to just use one syntax for code consistency. When I use getByRole, or getByText or other locators, things seem to be consistent.

My question is, what is the difference in the syntax of defining locators either way? I thought it was just two different ways of doing the same thing. Thanks.

Edit: ahhhh it looks like I am setting test id's differently in different components. The bug seems to be in between the chair and the laptop. Thanks.


r/Playwright • • 2d ago

Manual tester transitioning into Playwright automation

17 Upvotes

I have 7 years experience in manual testing and performance testing. My role got laid-off in the company restructuring sometime ago, and I am currently learning javascript and playwright.

  1. Please let me know what concepts to learn in playwright to secure a job in playwright automation.
  2. Also please let me know what techologies related to automation that I should know like Jenkins, CI CD, etc.
  3. Will companies employ me as an automation engineer if I say I am coming from a manual testing background?

Thanks.


r/Playwright • • 2d ago

Stopping an AI agent from writing XPath and waitForTimeout: a prompt didn't work, a hook did

11 Upvotes

If you've pointed Claude Code, Cursor or Copilot at a Playwright repo, you've probably seen output like this:

await page.locator('//div[@class="cart"]/button[2]').click();
await page.waitForTimeout(3000);
expect(await page.locator('#total').isVisible()).toBeTruthy();

XPath, a hard wait, and an assertion that checks visibility once instead of retrying. Putting "use getByRole, no hard waits" in the prompt helps for a while, then the agent drifts back, usually deep into a long session.

What fixed it for us was moving the rules out of the prompt and into three places:

  1. A short rules file at the repo root that the agent reads every turn. Locator strategy, no waitForTimeout, strict TypeScript, tests go through our fixtures and page objects. Ten lines, not a style guide.

  2. Separate rule files per file type (page objects, API tests, fixtures) that only load when the agent is working on that kind of file. Keeps the context small and the rules specific.

  3. A hook that checks the file before it's written. In Claude Code that's a PreToolUse hook; exiting with code 2 blocks the write and sends your message back to the agent. Ours is basically:

if grep -nE "waitForTimeout|locator\(['\"\`](//|xpath=)|: any\b" "$FILE"; then
  echo "Blocked: use getByRole/getByTestId and web-first assertions, no hard waits, no any" >&2
  exit 2
fi

The agent gets the reason and rewrites it:

await cartPage.checkoutButton.click();
await expect(cartPage.orderTotal).toHaveText('$42.00');

A prompt is advice. The hook is the part that actually changed the output.

The full version of this pattern is open source: Agentic Playwright by Ivan Davidov, which packages the rules file, per-file skills and the hook into one scaffold.

Anyone else enforcing this with hooks, or are you catching it in review?


r/Playwright • • 2d ago

How do you keep locators up to date with the increasing amount of code from devs?

9 Upvotes

I realize that this is an obvious question that has been repeated many times, but things are changing so rapidly now that maybe someone has come up with a better solution than just "ask the devs to fix the tests." Honestly, I feel like they will flood our test framework with poorly written tests, bad locators, etc. You might say, "Well, create a better harness then." I did. I'm still unsure, though, and just want to see what you are doing in this world of rapid changes. I'd be happy to hear about your experience, because, you know, it's all about sharing after all


r/Playwright • • 3d ago

I built mustfail, an open-source CLI that finds Playwright tests that stay green when the app is broken

4 Upvotes

mustfail, a free, open-source CLI that finds Playwright tests that pass when the app is broken.

You run `npx mustfail run` in your project. It reruns your suite several times: once with every API call failing, then with the values your assertions read changed, lists emptied, and the test's own saves failed. It grades each test by what it noticed. A test that stays green with the whole API down is decorative. A test that stays green when its own data is wrong is weak. You don't change your tests or your config, and it writes an HTML report. It needs Node 20+ and Playwright 1.50+.

I ran it on Strapi's open-source e2e suite. The test that deletes the Author role checks:

await expect(page.getByRole('row', { name: 'Author', exact: true })).not.toBeVisible();

I made `POST /admin/roles/batch-delete` return 500 with `page.route`. The role stayed in the table and the test stayed green. Playwright names a row after the text of all its cells, so no row is named exactly "Author", and `not.toBeVisible()` on a locator that matches nothing passes every time. Checking `getByRole('gridcell', ...)` instead fixes it. I filed it with a second test it found, a homepage widget test that never reloads to check the save: https://github.com/strapi/strapi/issues/28805

Across the 189 admin and content-manager tests I ran, 86 failed an assertion when their data was wrong.

It's an alpha. It reruns your tests several times (a full run takes 3 to 4 times your suite's runtime), so point it at a local or disposable environment, since it repeats your tests' writes.

I'd like to hear where a grade is wrong on your suite. Reply here, or open an issue with the test and the reason mustfail gave.

https://github.com/ashwink-tech/mustfail


r/Playwright • • 4d ago

Piwi: Our demo video is a Playwright test that runs every night, and films itself

Thumbnail youtu.be
7 Upvotes

I maintain Piwi, a free, self-hosted dashboard for Playwright results (a reporter, a dashboard, a VS Code extension and a browser extension). A video of all of them together is out of date at every release, so I didn't want to edit by hand each time.

Instead, one Playwright script plays a story on the real tools: a red CI run, debugging it in VS Code, picking the right locator on the live page, recording a missing step, then watching the fix run on three CI workers. Each step ends with a check of what it left behind (the file on disk, the dashboard's API, the editor's DOM). Played without a camera, it's the only test that drives all the tools together, and it runs nightly.

A few things that may be useful beyond this project:

  • Playwright drives Chromium, the test's own browser and VS Code (Electron) with trusted input, and every click and key is logged with its box on the screen.
  • There's no waitForTimeout in it: each step waits on a state (a line on disk, a row in an API, a CodeLens).
  • Filming is the same run on a 4K Xvfb screen recorded by ffmpeg. The edit is a web page that renders each frame from the recording and the gesture log (camera, cursor, subtitles), so the motion is unit-tested like any other code.
  • Running nightly, it has caught four product bugs that no other test saw; watching the film caught a fifth (the page's own CSS leaking into the picker's panels).

How it's made: https://piwitests.dev/blog/the-demo-video-is-a-test

The video: https://youtu.be/ugsqKraU1KY

The script: https://github.com/PiwiTests/piwi/tree/main/apps/showcase


r/Playwright • • 4d ago

Migrating from UiPath to Playwright - anyone done this?

4 Upvotes

We’re in the process of migrating some complex UiPath automations to Playwright. Has anyone here done a similar migration? Curious about the challenges you faced, things you wish you’d known beforehand, and whether it was worth it in the long run.


r/Playwright • • 6d ago

Playwright MCP vs AI Browser Agents: Which Is Better for Repetitive Tasks?

6 Upvotes

I think I've been overcomplicating browser automation a bit lol. Why bother with scripts when an AI agent can just figure out where to click? Sounds great until it's figuring out the same buttons and forms every single time.

So I've been looking into letting AI handle a task once, then turning the successful steps into a reusable Playwright workflow. Came across oya browser while researching this, and the approach caught my attention. Seems like a reasonable middle ground between AI-driven browsing and manually writing scripts.

Of course, websites change, sessions expire, and workflows still need maintenance. But having an agent start from scratch every time feels like unnecessary overhead for repetitive tasks.

How are you guys handling this with MCP browser automation? Do you let agents figure things out each time, or reuse Playwright workflows once they're working?


r/Playwright • • 7d ago

I built MailGate: a self-hosted, receive-only OTP and magic-link inbox on Cloudflare Workers and D1 with Playwright SDK and MCP server

Post image
7 Upvotes

I built MailGate, a self-hosted, receive-only email inbox for verification codes and magic sign-in links running on Cloudflare Email Routing, Workers, and D1. It fits the free tier with no VPS or SMTP server to maintain.

I made it because I got tired of paying for hosted QA inbox services or keeping Mailhog running just to read OTP codes during Playwright authentication tests and Claude Code sessions.

What it includes:

  • Strict recipient allowlist at SMTP ingest and optional PBKDF2-SHA256 inbox passwords
  • Automatic OTP code and magic-link extraction that ignores calendar years in receipts
  • Defense-in-depth HTML sanitization rendered inside a sandboxed iframe with a strict CSP
  • Daily Cron Trigger auto-cleanup with configurable retention TTL
  • Zero-dependency TypeScript/JS SDK and Playwright fixture via mailgate-sdk/playwright
  • Built-in stdio MCP server via npx -y mailgate-sdk mcp, listed on the Official MCP Registry and rated B on Glama

GitHub (MIT): https://github.com/Dicka18/mailgate npm: https://www.npmjs.com/package/mailgate-sdk

Happy to answer any questions about running receive-only email on Cloudflare Workers and D1, or hear what features to add next.


r/Playwright • • 7d ago

Any Claude Code & Playwright for Automated Tests on a B2B + Skills Question

0 Upvotes

Hi all!

Wanted to see if anyone has been using Claude Code and Playwright for automated testing in a B2B site? If so, I understand those tend to be more complex to do automated tests for given their multi-tenant and role-based permissions, as well as multi-step workflows. Any suggestions, ideas, things to watch out for our plan for completely different than a B2C?

I've also noticed some Playwright skills out there that have been developed. The site below does a nice job listing a bunch with details. Has anyone used or heard about any of them?

Playwright Skills & Plugins for AI Coding Agents https://currents.dev/posts/best-playwright-skills-and-plugins-for-ai-coding-agents

Thanks!


r/Playwright • • 7d ago

forcing closed shadow roots open worked until the vendor updated

16 Upvotes

the approve button in our ap vendor's portal sits inside a closed shadow root. for months the bot only worked because of an init script that patches attachShadow to force mode open. hacky, but it held until the vendor's last update

with the patch on, the invoice widget throws on load and renders blank. with it off the widget renders but element.shadowRoot is null and locators walk straight past the button

before anyone says frame locators, those already handle the iframe bits fine. the button lives on the main page, in that one closed root

i'd rather not fight their frontend every release. anyone reaching elements in closed roots without monkeypatching the page?


r/Playwright • • 8d ago

Has an AI agent ever told you a test step passed when it didn't?

4 Upvotes

I work in QA at ThinkSys, so I see this across a few client teams. The failure mode that worries me most with agentic testing isn't the agent failing. it's the agent saying it succeeded.

With normal Playwright tests, failures are loud. an element isn't found and the test stops. with agents, we've seen runs where the agent reports a step as done when it actually landed somewhere else. one got stuck looping on a login page because it didn't recognise a 2FA prompt, and still reported progress.

Those failures are much harder to trace, because there's no line of code that broke. you have to read through what the agent thought it was doing.

The only thing that's helped so far is checking results outside the agent, like querying the API or database to confirm the step actually happened instead of trusting the agent's report.

How are others catching this? Is there a good way to verify agent runs without checking every step by hand?


r/Playwright • • 8d ago

Reviewing AI-generated tests: the 5 drifts to check before anything merges

12 Upvotes

AI-written tests fail in predictable ways. They usually pass, and that's the problem: a passing test that checks the wrong thing is worse than no test. These are the five drifts worth checking every time:

1. Selector drift

The agent picks whatever locator works right now: XPath, deep CSS chains, nth-child, auto-generated class names. Those break on the next UI change.

Check: locators should be based on role, label, text or test ID, matching your project's strategy.

2. Data drift

Hard-coded emails, IDs and dates invented on the spot, instead of your project's data factories or fixtures. Tests then collide or depend on state that won't exist in CI.

Check: test data comes from your helpers, not literals.

3. Import drift

The agent imports test utilities directly, bypasses your custom fixtures, or pulls in a new library to solve something you already have a helper for.

Check: imports match the patterns used in the rest of the suite.

4. Assertion drift

The most dangerous one. Assertions that can't fail (checking that an element exists that always exists), asserting on implementation details, or replacing real checks with arbitrary waits.

Check: every assertion would fail if the feature broke.

5. Structure drift

Each generated file looks slightly different: logic in tests instead of page objects, duplicated setup, inconsistent naming. Individually harmless, collectively unmaintainable.

Check: the file looks like the best existing test in your suite.

The bigger fix

Reviewing for drift catches problems. Preventing them works better: give the agent a scaffold where the rules already live, and block the worst patterns automatically before a file is even written.

Which drift do you see most in AI-generated tests?


r/Playwright • • 9d ago

In the last 3 months, did any of your browser (UI/E2E) test fail on just one browser or device? Pick the one it failed on most.

0 Upvotes

r/Playwright • • 9d ago

Check API/steps performance regression - Playwright

5 Upvotes

Hi all,

QA engineer here. Our e2e/api suites hit the backend thousands of times a day, but nobody looked at how long those requests took. A slow endpoint only got noticed once users complained. So I built playwright-performance-regression (MIT, free).

What it does:
- Measures the backend requests your browser makes (and `request` calls in API tests) while your existing tests run. No new tests to write.
- Groups them into endpoint keys like `GET /api/orders/:id` and computes median, p95, p99 and error rate. It can also time your `test.step` blocks.
- Derives thresholds into JSON files that you review and commit like code.
- Fails the run when an endpoint gets slower or starts erroring, with a console summary, a self-contained HTML report and `junit.xml` for CI.

Zero maintenance, by design:

- Setup takes minutes: one command, a guided setup, done. No new tests, no page objects, no instrumentation.
- Coverage grows on its own: every new e2e test that hits a new endpoint gets measured automatically. The more you test, the more performance coverage you get, with zero extra work.
- Your normal `npx playwright test` runs stay untouched. Measuring is a separate run you switch on with an env variable: `PW_PERF_MODE=test npm run e2e`.

Setup:

npm init playwright-performance-regression

A guided setup asks a few questions and shows a diff of every change before writing it. It never touches `package.json`. Then you generate thresholds once on CI, commit them, and forget about it.

Statistics:

Timings are noisy, so the run repeats your suite a few times (passes) and the thresholds are derived from those samples. I validated this on a benchmark before building the tool. CI recipes are included for GitHub Actions, GitLab, Jenkins and Azure.

- Live demo report: https://meser6.github.io/playwright-performance-regression/

- GitHub: https://github.com/Meser6/playwright-performance-regression

It's 1.0.0, so I'd really appreciate feedback: does it work on your setup, what's confusing, what's missing?


r/Playwright • • 11d ago

Which browsers do your automated browser (UI/E2E) tests run on today? Pick the widest that applies.

0 Upvotes

r/Playwright • • 11d ago

How do your automated browser (UI/E2E) tests cover phones today? Pick the closest to a real phone that you use.

2 Upvotes

r/Playwright • • 12d ago

Disposable Inboxes as an API for Automation & QA

3 Upvotes

One interesting way to use disposable email inboxes is in automated testing and QA for playwright.

Instead of switching to a mailbox every time your application sends a verification email, OTP, password reset link, or notification, your automation can:

  • Create a disposable inbox through an API.
  • Trigger the actual application workflow.
  • Fetch incoming emails using email APIs.
  • Extract OTPs, verification links, or relevant content.
  • Validate the response and let the automation continue.

This makes it possible to test complete, real-world user flows without manual mailbox interaction.

I've been exploring this approach while building Mail My Agents, and I think disposable inbox APIs have some interesting applications beyond temporary email.

Curious how others are handling email verification in automated QA pipelines.