Beyond the Script: Supercharging Test Automation with Agentic AI

The Balancing Act

In the fast paced world of modern software development, testing often becomes the bottleneck. Not because QA teams are slow, but because the scope of testing expands exponentially with every new feature. Teams constantly grapple with the balancing act between manual testing and test automation. Both are critical, but they serve entirely different purposes.
Manual testing is about empathy, exploration and human intuition. It’s the process of interacting with an application exactly as a chaotic, unpredictable user would. Manual QA catches layout quirks, confusing user experiences and edge cases that a strict script would blindly pass.
Test automation on the other hand, is built for the predictable. It exists to run repetitive regression suites, handle complex data setup and verify that the deterministic paths of the application haven't been broken by new commits. The golden rule of QA is simple: automate the predictable, highly trafficked flows, and manually test the new, the unpredictable and the subjective.
The core problem we faced was the sheer time it takes to build and maintain the ever expanding automation codebase. Writing robust end-to-end tests is software engineering in its own right. UI elements change, selectors break and test engineers often spend more time fixing old, brittle tests than covering new ground. We needed a way to accelerate the authoring of these tests without sacrificing quality, allowing testers to focus on strategy rather than boilerplate.
Two Paths Forward

1. Traditional, manual test scripting: Continuing to write our Playwright scripts entirely by hand. So far, this has remained our primary bottleneck to automation. There are only so many hours in a day, and with manual testing being the focus of most days, we had to expand our tool suite if we wanted to speed up the scripting process.
2. Cloud-based AI testing tools: Adopting proprietary SaaS testing platforms that promise "zero-code AI testing." While certainly viable (and sometimes necessary due to some limitations of our solution), having an independent AI that our team has full control over sounded like an enticing promise!
Or Perhaps Three

In the end, we decided to tinker with building an in-house, agentic AI workflow centered around Playwright, powered by locally hosted Large Language Models (LLMs).
Why Playwright? It has cemented itself as the industry standard for modern web automation. It handles asynchronous events flawlessly, supports multiple browser engines, and has fantastic built in tooling for tracing and debugging.
Why Agentic AI? Traditional autocomplete (like standard Copilot) is reactive; it predicts the next line of code. Agentic AI is proactive. We wanted an AI agent that could take a high level test objective (e.g., "Verify a user can check out with a discount code"), explore the target application, understand the DOM structure, structure the test cases logically, and generate the Playwright code.
Why Local Models?
It’s an independent solution to the cost and privacy concerns of cloud AI, thus we turned to the open weights ecosystem. The current generation of models, like Gemma 4 and Qwen 3.6, are phenomenally capable at coding tasks. More importantly, they have been optimized to run locally on standard consumer hardware. With a mid range local server (or even an Apple Silicon Mac or RTX 4000-series GPU workstation), we can run these models with zero latency and zero data sharing agreements.
Under the Hood

Integrating agentic AI into our Playwright pipeline required a shift in how we approach test architecture. We wanted a co-pilot that understood our testing patterns, not just a script generator.
First, we set up our local AI infrastructure. Using llama.cpp we spun up instances of Qwen 3.6 for heavy lifting reasoning tasks and DOM parsing, alongside Gemma 4 for fast, iterative code generation. Their coding capabilities out of the box are exceptional, especially when prompted with specific Playwright best practices.
When a new feature lands, the workflow looks like this:
1. Exploration: The agent is pointed at a staging URL and provided a user story. Using Playwright's ability to extract the DOM tree, the agent parses the page. It intelligently strips out noise (like inline SVGs or complex CSS) to understand the semantic structure of the UI.
2. Structuring: The AI doesn't immediately write a massive, procedural script. We prompt it to build Page Object Models (POM). It identifies key locators, preferring robust attributes like 'data-testid' or ARIA roles, and creates reusable class methods.
3. Test Generation: Using the POM, the agent drafts the actual '.spec.ts' files. It writes the setup, the interaction steps, and crucial assertions.
The AI shines in edge case generation. Models like Gemma 4 have ingested vast amounts of QA literature, and they automatically suggest tests for negative paths we might overlook - like submitting a form with invalid data, testing for extremely long string inputs, or checking how the UI responds when a network request is deliberately aborted via Playwright's network interception.
What changed (and what we learned)

The introduction of this agentic workflow significantly decreased the time it takes for us to automate tests. Previously, we were happy if we could find the time for scripting, debugging the scripts and deploying to our testing agent. Now with the help of AI, we can comfortably let the AI agents do the dull tasks of writing the code on the groundwork we’ve already had.
Experimenting with fully local AI models has been exciting, and they are surprisingly easy to use once the initial hassles of setup are dealt with. The capabilities of an LLM able to run on a modest desktop PC have already surpassed what free ChatGPT could output a couple of years ago! And while certainly capable, they unfortunately will not be completely replacing cloud solutions just yet – smaller context size (essentially "shorter memory") being the most significant limitation.
However, the most valuable lesson learned was that the AI is an assistant, not a replacement for a QA engineer. Agentic AI is incredibly fast, but it is not infallible. It will occasionally hallucinate a selector or misunderstand a highly complex, multi-step business logic flow.
Our process evolved into a "pilot and co-pilot" model. The AI writes the scaffolding, the locators and the baseline tests. The human engineer reviews the code, refines the logic and runs the local execution to verify stability.
Because the heavy lifting of script writing is offloaded, we can better spend our time designing better testing architectures, and focus on high value exploratory testing and UX validation.
What's next for your Test Architecture?
If you are looking to integrate agentic AI into your QA processes, keep these steps in mind:
Define your bounds: Clearly separate what should be automated (repetitive, data heavy, predictable flows) from what requires a human touch (exploratory, visual and UX testing).
Adopt modern tooling: Standardise on a robust automation framework like Playwright that supports modern web architectures and asynchronous operations natively.
Leverage local AI: Experiment with running highly capable local models like Gemma 4 and Qwen 3.6 on consumer hardware. The initial setup pays dividends in lack of API costs.
Architect for the AI: Feed your AI agents well structured prompts. Teach them to use Page Object Models and rely on robust selectors (like 'data-testid') rather than fragile CSS paths.
Implement a human-in-the-loop: Treat AI-generated tests as pull requests from a junior developer. Always review, run and refine the code before merging it into your CI/CD pipeline.





