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)

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!

1 Upvotes

0 comments sorted by