
How to E2E Test AI Agents: Mocking API Responses with Playwright in Next.js
Building an AI agent is fun. At least, I have had so much fun building out Ozigi , a social media content manager agent (ps, we are in need of user experience testers!). But! Testing it in a CI/CD pipeline is a nightmare. If you are building an application that relies on an LLM (like OpenAI, Anthropic, or Google's Vertex AI), you quickly run into these three challanges when writing End-to-End (E2E) tests: Cost: Every time your test suite runs, you are burning API credits. Speed: LLMs are slow. Waiting 10-15 seconds per test will grind your deployment pipeline to a halt. Non-Determinism: LLMs never return the exact same string twice. If your Playwright test relies on expect(page.getByText('exact phrase')).toBeVisible() , your tests will randomly fail. While building Ozigi —an agentic content engine designed to turn raw technical research into structured social campaigns—I needed a way to test the complex UI state transitions (like custom loaders and dynamic grids) without actually hitti
Continue reading on Dev.to Webdev
Opens in a new tab




