Modern test automation often promises speed—but in reality, getting started usually means:
- setting up Node and npm
- installing Playwright
- configuring TypeScript
- wiring reporters, retries, CI
- creating page objects
- choosing stable locators
- writing the first meaningful test suite
That’s hours of setup before you even validate a login form.
In this tutorial, I’ll show how Cursor, an AI-powered code editor, can generate a fully working Playwright test framework and test suite—including configuration, dependencies, locators, and scenarios—all out of the box.
π― What We’re Building
We’ll generate a complete Playwright Test (TypeScript) framework for this site:
π https://practicetestautomation.com/practice-test-login/
The final result includes:
- ✅ Playwright + TypeScript setup
- ✅ Page Object Model
- ✅ Stable, role-based locators
- ✅ Login test suite (positive & negative scenarios)
- ✅ CI-ready configuration
- ✅ GitHub Actions workflow
- ✅ ESLint + Prettier
- ✅ HTML reports, traces, screenshots
And yes—Cursor handles all of it.
π€ Why Cursor Changes the Game for QA Automation
Traditional automation setup is repetitive and error-prone. Cursor flips the model:
With Cursor, you get:
- π A production-ready framework generated instantly
- π§ Context-aware test scenarios
- π― Correct locators chosen automatically
- π§± Best practices applied by default
- π Zero copy-paste from old projects
Instead of writing boilerplate, you focus on test intent and coverage.
π§ Step 1: Describe What You Want (That’s It)
In Cursor, you don’t start by creating folders or config files.
You start by describing the outcome.
Here’s the exact prompt you can paste into Cursor π
You are a senior QA automation engineer. Create a Playwright Test framework in TypeScript that runs out-of-the-box and includes a complete, best-practice test suite for:
https://practicetestautomation.com/practice-test-login/
Hard requirements:
- Use Playwright Test + TypeScript.
- Provide a complete folder structure and all necessary files.
- Everything must work out-of-the-box after:
1) npm install
2) npx playwright install --with-deps
3) npm test
- Use best practices: page objects, stable locators, fixtures, test isolation, clean assertions, retries in CI, trace/video/screenshots on failure, reporters.
- Do NOT use brittle CSS selectors. Prefer getByRole / getByLabel / getByText and data-testid if available.
- Make baseURL configurable via env (dotenv) and default to the target site.
- Add useful npm scripts (test, test:ui, test:headed, test:debug, lint, format).
- Include ESLint + Prettier config for TypeScript.
- Include a GitHub Actions workflow to run tests on push/PR with HTML report artifact upload.
- Add a README with exact commands and explanations.
Framework details to implement:
1) Project setup
- package.json with dependencies: @playwright/test, typescript, eslint, prettier, eslint-config-prettier, eslint-plugin-playwright, @typescript-eslint/*, dotenv
- tsconfig.json with sensible defaults.
2) Playwright configuration
- playwright.config.ts should:
- set baseURL from process.env.BASE_URL with fallback to "https://practicetestautomation.com"
- use testDir = "tests"
- use expect timeout and action timeout reasonable defaults
- configure projects: chromium, firefox, webkit
- enable screenshot: only-on-failure, video: retain-on-failure, trace: retain-on-failure
- set retries: 0 locally, 2 on CI (process.env.CI)
- set reporter: list + html
- forbidOnly on CI
- fullyParallel true
3) Test architecture
- /pages:
- LoginPage.ts
- SecureAreaPage.ts
- /tests:
- login.spec.ts covering valid login, invalid credentials, empty fields, logout
- /test-data:
- users.ts with valid creds:
- username: "student"
- password: "Password123"
- /fixtures:
- baseTest.ts exposing page objects
4) Robustness
- Web-first assertions
- Proper navigation handling
- Independent tests
Output:
- Print all files with full content
- Include a "How to run" section
⏱️ What Cursor Does for You Automatically
After submitting the prompt, Cursor:
π§± Builds the entire framework
- Creates
package.json,tsconfig.json,playwright.config.ts - Installs Playwright Test correctly
- Configures retries, reporters, artifacts
π§ Understands the application
- Identifies the login form
- Picks role- and label-based locators
- Detects success and error states
π§ͺ Generates meaningful test scenarios
- Valid login
- Invalid username
- Invalid password
- Empty credentials
- Logout flow
π§Ό Applies best practices automatically
- Page Object Model
- Test isolation
- Web-first assertions
- CI-friendly setup
No tutorials. No StackOverflow. No guesswork.
π₯ Live Cursor Demo
π Step 2: Run the Tests (That’s All)
Once Cursor finishes, you can simply run:
Or ask Cursor to run it for you, as shown in the recording.
You immediately get:
- ✅ Browser launch
- ✅ Login tests executed
- ✅ HTML report generated
- ✅ Screenshots/traces on failure
π₯ Why This Matters for QA Teams
This isn’t just faster test writing.
It fundamentally changes how QA automation scales.
Traditional approach
- Days of setup
- Inconsistent patterns
- Copy-paste frameworks
- Tribal knowledge
Cursor + AI approach
- Minutes to bootstrap
- Consistent architecture
- Senior-level patterns by default
- QA focuses on risk, not boilerplate
π Bonus Benefits You Might Not Expect
- π§ Cursor adapts to your existing codebase
- π Refactors tests as the app evolves
- π Suggests missing scenarios
- π§ͺ Helps convert manual tests into automation
- π Improves onboarding for new QA engineers
π§© Final Thoughts
Cursor doesn’t replace QA engineers.
It amplifies them.
Instead of spending energy on setup and syntax, you spend it on:
- coverage
- risk
- quality
- confidence
If you haven’t tried Cursor for test automation yet—this is your sign.
No comments:
Post a Comment