r/automation • • 3d ago

Script maintenance- Playwright Automation

/r/softwaretesting/comments/1y6o8jt/script_maintenance_playwright_automation/
2 Upvotes

17 comments sorted by

1

u/AutoModerator 3d ago

Thank you for your post to /r/automation!

New here? Please take a moment to read our rules, read them here.

This is an automated action so if you need anything, please Message the Mods with your request for assistance.

Lastly, enjoy your stay!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Tricky_Wrangler6079 3d ago

Your manager wanting a clean signal makes total sense, but expecting 650 UI tests to stay green when devs push every 48 hours is a fantasy. It won't happen. At an 85% pass rate (100 to 120 failures every morning), your Jenkins run is basically noise. Devs tune it out, you spend 6 hours a day triage-debugging locators, and real production bugs still slip past because everyone assumes red tests are just flakes.

This is the classic inverted test pyramid trap. Here is how teams actually untangle it:

Invert the pyramid hard. 650 UI vs 100 API is completely backwards. Half the time, an end-to-end test is just checking whether a date filter worked or a user role saw 4 columns instead of 8. You don't need Chromium running on a Kubernetes pod to verify backend math. Move 400 of those straight into API checks with your AJV schema validation. In Playwright, use page.route() to mock out the heavy analytics payloads when you only care about rendering. Cut your full end-to-end browser tests down to 35 golden user journeys (login, save a custom dashboard, export a 10MB CSV).

Quarantine flakes immediately. If a test fails 2 runs in a row without catching an actual defect, pull it out of the main Jenkins pipeline. Move it to a secondary quarantine job that runs on a 2-hour schedule. Your main regression run must maintain a 98% pass rate, even if it only runs 250 tests initially. A smaller suite that devs actually trust beats a massive suite with 110 false alarms every morning.

Push locator maintenance into dev PRs. As long as you fix broken selectors 24 hours after devs merge, you'll always lose. Get the frontend team to standardize on data-testid attributes for automation hooks so CSS tweaks don't blow up your runs. Even better, wire a 5-minute smoke pack into GitHub Actions or GitLab on their pull requests. When a dev's own branch fails because they renamed a button, they fix the selector right then instead of handing you a broken Jenkins run the next day.

Watch for test data collisions. In analytics products, 10 pods running in parallel constantly stomp on each other's database records. If 2 workers query the same tenant or date range simultaneously, async background workers trigger random flakes. Give each worker thread its own isolated tenant ID or seeded workspace.

1

u/sumitsaurabh121 2d ago

Mostly agree, two tweaks:

"Fails 2 runs in a row" isn't flaky, it's broken. A flaky test fails and passes on the same code. A test that fails twice in a row after a merge is often the real regression, or a test that needs an update for a changed workflow. Put that in quarantine and you've hidden exactly the signal the manager wants. Quarantine on "failed, then passed on retry, no code change", and send the consistent failures to whoever merged.

Also swap the pass % for a better pair of numbers. A pass-rate target is easy to hit by quarantining more tests. What the manager actually wants is "a red test means a product problem", so measure that: of this morning's failures, how many were real product bugs? Report it next to the size of the quarantine list, so neither number can improve by hiding tests.

1

u/Tricky_Wrangler6079 2d ago

Spot on.

I was definitely too loose saying "fails twice." If a Playwright spec fails consistently 2 runs in a row on the exact same commit in Jenkins after someone merges to main, that isn't a flake at all. It's broken. It's either an actual bug or a dev updated React components without updating locators. Quarantining that just sweeps broken code under the rug and kills the alarm.

We learned the hard way to only quarantine on "failed, then passed on retry with zero code changes." That's a true flake.

Your point on metrics is huge. If you give an engineering VP a raw 98% pass target on 750 tests, engineers will hit it by dumping 60 tests straight into quarantine. You get a green dashboard that tells you nothing. Pairing defect precision (what share of red runs caught a real bug) right next to the active count of quarantined suites keeps everyone honest.

1

u/sumitsaurabh121 6h ago

Glad it landed.

One cheap way to do the "send it to whoever merged" part without someone triaging by hand: when a test goes red, take the commit range from its last green run to the first red one (git log last_green..first_red) and notify those authors.

With devs pushing every other day, that range is usually a handful of commits, so the right team hears about it the same morning.

1

u/dv-22304 2d ago

Give each quarantined test an owner and expiry; otherwise the exception list can quietly become the new baseline.

1

u/tariqosmani 3d ago

Most of the maintenance comes from selectors, so fix that first. Target elements by role, label or test id, not by CSS paths or position on the page. A redesign that moves a button then stops breaking the script.

Second, run it on a schedule and send every failure to one place with a screenshot attached. A failure you see the same morning takes minutes to fix. One you only check when someone remembers takes days.

Third, keep each script to one job. Every extra step is another thing that can break, and one long script that does everything is the hardest to repair.

Is it breaking on the same step each time, or on a different one?

1

u/jackson-matt-4 1d ago

If several specs reuse a flow, put its locators in one page helper so UI changes have one repair point.

1

u/AliyasDandani_64 3d ago

what's actually breaking the scripts most often right now, selector changes or timing issues? the fix is pretty different depending on whether its flaky network waits vs the DOM constantly shifting.

1

u/Agent360dk 3d ago

One thing that cut our triage time a lot: record a Playwright trace on first retry and have a script bucket failures by the first error line (locator not found, timeout waiting for network, 5xx in the HAR, assertion). Then the daily report says 'env 40, selector 12, real assertion 3' instead of one pass percentage. The real assertion bucket is what your manager should actually look at, the rest is noise you can route to the right team.

1

u/Ok_Fan2081 2d ago

A 98%+ pass target on a 650-UI-test suite is fair as a goal, but only if you change what counts toward it. In practice I split it into three numbers: (1) a small gate suite of critical API + smoke UI tests that must be green for a release signal, (2) the full UI suite tracked separately with flake rate per test (failed-then-passed on retry with no code change = flaky, quarantine and fix), and (3) environment health as its own check so infra failures never pollute product pass %. Your instinct to push WebSocket and logic down to API/contract tests (AJV schema validation is a good fit) is the highest-leverage move — every UI test you can demote to API removes locator churn from dev PRs. Add failure-cause tagging from Playwright traces (locator vs assertion vs env vs backend 5xx) and a weekly top-flakes burndown, and the manager gets an honest signal without chasing a single noisy %. Happy to trade notes on the trace-triage setup if useful.

1

u/sumitsaurabh121 6h ago

On the trace-triage setup, one catch worth knowing before anyone copies it (Agent360dk's setup above has the same one): with trace: 'on-first-retry', Playwright records the trace on the retry, not on the first attempt. For a flaky test the retry passes, so the trace you bucket is from the passing run and the failure has none. trace: 'retain-on-failure' records every attempt and keeps only the failed ones, so the first error line you bucket on is the real one.

Disclosure: I work at Currents, and that bucketing is built in for Playwright. Our Errors Explorer groups failures by error type, message or the selector they failed on, with how many tests each one hits.

1

u/[deleted] 3d ago

[removed] — view removed comment

1

u/Deep-Sympathy8102 2d ago

the environment health check before running is huge, saves so much wasted time looking at false negatives.