Using AI for Automated Testing: From Test-Case Generation to Regression Runs

1. The conclusion first: AI writes drafts, you set the standard
Conclusion first: hand test-case generation to AI, and keep assertions and acceptance criteria with yourself. AI is good at generating cases in bulk from existing code and test styles, adding edge cases, and fixing failures — but only you can judge which behavior is correct for the business. This fits developers whose projects already have substantial code, thin test coverage, and no time to hand-write cases from scratch. It does not fit projects with no runnable test baseline, where the behavior under test is not even defined yet.

2. What you need
A runnable project, ideally with a few existing test files for the AI to mirror in style; Node.js installed — Playwright's official docs list Node.js 22.x, 24.x, or 26.x as the system requirement; and one coding agent: Claude Code, started with the claude command in the terminal; Cursor, with Plan Mode and Agent mode; or GitHub Copilot, which covers the IDE, the command line, and cloud agents. Finally, pick one critical user path, such as placing an order after signing in, to serve as the regression backbone.

3. Step by step: build the testing pipeline in three steps
Step one: build the regression backbone with Playwright. In your project, run npm init playwright@latest, choose TypeScript when prompted, and confirm the test folder (tests by default). Then record the critical path with npx playwright codegen plus the target URL: click through the page while code is generated, using the toolbar's assert visibility, assert text, or assert value assertions. Save the generated code into the tests folder, then run npx playwright test to confirm the backbone passes.
Step two: let Claude Code fill in cases in bulk. Run claude in the project root and follow the official workflow order: first ask it to find uncovered functions, then generate test scaffolding, then add edge cases. Ask it explicitly to mirror the style and assertion patterns of your existing test files and to state the behavior each case verifies. After generation, run the tests and have it fix failures one by one against the error output until the whole batch passes.
Step three: regress and review with Cursor and Copilot. After changing code, run a round of tests in Cursor's Agent mode and fix failures; for large refactors, open Plan Mode first and review the plan before executing. Before submitting, run the change through GitHub Copilot's code review and agent sessions, letting it check from the Issue or PR for missed regression points. Finally, open the HTML report with npx playwright show-report and filter by browser and passed, failed, or skipped to confirm no failing case slipped through.
4. Common blockers and fixes
Generated cases only cover the happy path, with assertions written too loosely — the most common flaw. Name the boundary conditions and error branches in your request, such as empty input, timeouts, and insufficient permissions, and require every assertion to state its expected value. After the run, spot-check a few cases by hand and send back any with vague assertions for a rewrite.
Fragile locators and flaky tests: Playwright's generator prefers role, text, and test id locators, so avoid deeply nested CSS selectors. For flaky failures, check timing first, then watch the run step by step with --ui mode. Keep login state out of code: save it separately with npx playwright codegen --save-storage=auth.json, keep auth.json local only, and add it to .gitignore — the official docs also warn that it contains sensitive information.
5. Things to watch
Generated tests must pass before they are merged in; do not merge failing cases first and fix them later. Do not let the agent change business code just to satisfy a test — when a test and the implementation disagree, confirm which side is wrong first. Quotas and plans follow the official sites; Cursor and GitHub Copilot are both freemium, with details on their respective official pages.
Verification note
The steps in this article were checked against official pages on 2026-11-17. If platform rules change, the official pages apply.
Tools mentioned
Sources
- Common workflows — Work with tests — Claude Code
- Cursor Documentation — Agent — Cursor
- How-tos for GitHub Copilot — GitHub Docs
- Installation — Playwright
- Test generator — Playwright
This article is compiled from the public sources above and does not reproduce the originals in full; see the official sources for details.