7# End-to-End Application Testing
8
9## Pre-flight Check
10
11### 1. Platform Check
12
13agent-browser requires **Linux, WSL, or macOS**. Check the platform:
14```bash
15uname -s
16```
17- Linux or Darwin → proceed
18- Anything else (e.g., MINGW, CYGWIN, or native Windows) → stop with:
19
20> "agent-browser only supports Linux, WSL, and macOS. It cannot run on native Windows. Please run this command from WSL or a Linux/macOS environment."
21
22Stop execution if the platform is unsupported.
23
24### 2. Frontend Check
25
26Verify the application has a browser-accessible frontend. Check for:
27- A package.json with a dev/start script serving a UI
28- Frontend framework files (pages/, app/, src/components/, index.html, etc.)
29- Web server configuration
30
31If no frontend is detected:
32> "This application doesn't appear to have a browser-accessible frontend. E2E browser testing requires a UI to visit. For backend-only or API testing, a different approach is needed."
33
34Stop execution if no frontend is found.
35
36### 3. agent-browser Installation
37
38Check if agent-browser is installed:
39```bash
40agent-browser --version
41```
42
43If the command is not found, install it automatically:
44```bash
45npm install -g agent-browser
46```
47
48After installation (or if it was already installed), ensure the browser engine is set up:
49```bash
50agent-browser install --with-deps
51```
52
53The --with-deps flag installs system-level Chromium dependencies on Linux/WSL. On macOS it is harmless.
54
55Verify installation succeeded:
56```bash
57agent-browser --version
58```
59
60If installation fails, stop with:
61> "Failed to install agent-browser. Please install it manually with npm install -g agent-browser && agent-browser install --with-deps, then re-run this command."
62
63## Phase 1: Parallel Research
64
65Launch **three sub-agents simultaneously** using the Task tool. All three run in parallel.
66
67### Sub-agent 1: Application Structure & User Journeys
68
69> Research this codebase thoroughly. Return a structured summary covering:
70>
71> 1. **How to start the application** — exact commands to install dependencies and run the dev server, including the URL and port it serves on
72> 2. **Authentication/login** — if the app has protected routes, how to create a test account or log in (credentials from .env.example, seed data, or sign-up flow)
73> 3. **Every user-facing route/page** — each URL path and what it renders
74> 4. **Every user journey** — complete flows a user can take (e.g., "sign up → create profile → view public page"). For each journey, list the specific steps, interactions (clicks, form fills, navigation), and expected outcomes
75> 5. **Key UI components** — forms, modals, dropdowns, pickers, toggles, and other interactive elements that need testing
76>
77> Be exhaustive. Testing will only cover what you identify here.
78
79### Sub-agent 2: Database Schema & Data Flows
80
81> Research this codebase's database layer. Read .env.example to understand environment variables for database connections. DO NOT read .env directly. Return a structured summary covering:
82>
83> 1. **Database type and connection** — what database is used (Postgres, MySQL, SQLite, etc.) and the environment variable name for the connection string (from .env.example)
84> 2. **Full schema** — every table, its columns, types, and relationships
85> 3. **Data flows per user action** — for each user-facing action (form submit, button click, etc.), document exactly what records are created, updated, or deleted and in which tables
86> 4. **Validation queries** — for each data flow, provide the exact query to verify records are correct after the action
87
88### Sub-agent 3: Bug Hunting
89
90> Analyze this codebase for potential bugs, issues, and code quality problems. Focus on:
91>
92> 1. **Logic errors** — incorrect conditionals, off-by-one errors, missing null checks, race conditions
93> 2. **UI/UX issues** — missing error handling in forms, no loading states, broken responsive layouts, accessibility problems
94> 3. **Data integrity risks** — missing validation, potential orphaned records, incorrect cascade behavior
95> 4. **Security concerns** — SQL injection, XSS, missing auth checks, exposed secrets
96>
97> Return a prioritized list with file paths and line numbers.
98
99**Wait for all three sub-agents to complete before proceeding.**
100
101## Phase 2: Start the Application
102
103Using Sub-agent 1's startup instructions:
104
1051. Install dependencies if needed
1062. Start the dev server **in the background** (e.g., npm run dev &)
1073. Wait for the server to be ready
1084. Open the app with agent-browser open <url> and confirm it loads
1095. Take an initial screenshot: agent-browser screenshot e2e-screenshots/00-initial-load.png
110
111## Phase 3: Create Task List
112
113Using the user journeys from Sub-agent 1 and findings from Sub-agent 3, create a task (using TaskCreate) for each user journey. Each task should include:
114
115- **subject:** The journey name (e.g., "Test profile creation flow")
116- **description:** Steps to execute, expected outcomes, database records to verify, and any related bug findings from Sub-agent 3
117- **activeForm:** Present continuous (e.g., "Testing profile creation flow")
118
119Also create a final task: "Responsive testing across viewports."
120
121## Phase 4: User Journey Testing
122
123For each task, mark it in_progress with TaskUpdate and execute the following.
124
125### 4a. Browser Testing
126
127Use the Vercel Agent Browser CLI for all browser interaction:
128
129```
130agent-browser open <url> # Navigate to a page
131agent-browser snapshot -i # Get interactive elements with refs (@e1, @e2...)
132agent-browser click @eN # Click element by ref
133agent-browser fill @eN "text" # Clear field and type
134agent-browser select @eN "option" # Select dropdown option
135agent-browser press Enter # Press a key
136agent-browser screenshot <path> # Save screenshot
137agent-browser screenshot --annotate # Screenshot with numbered element labels
138agent-browser set viewport W H # Set viewport (e.g., 375 812 for mobile)
139agent-browser wait --load networkidle # Wait for page to settle
140agent-browser console # Check for JS errors
141agent-browser errors # Check for uncaught exceptions
142agent-browser get text @eN # Get element text
143agent-browser get url # Get current URL
144agent-browser close # End session
145```
146
147**Refs become invalid after navigation or DOM changes.** Always re-snapshot after page navigation, form submissions, or dynamic content updates (modals, tabs, theme changes).
148
149For each step in a user journey:
150
1511. Snapshot to get current refs
1522. Perform the interaction
1533. Wait for the page to settle
1544. **Take a screenshot** — save to a descriptive path under e2e-screenshots/ organized by journey (e.g., e2e-screenshots/profile-creation/03-form-submitted.png)
1555. **Analyze the screenshot** — use the Read tool to view the screenshot image. Check for visual correctness, UX issues, broken layouts, missing content, error states
1566. Check agent-browser console and agent-browser errors periodically for JavaScript issues
157
158Be thorough. Go through EVERY interaction, EVERY form field, EVERY button. The goal is that by the time this finishes, every part of the UI has been exercised and screenshotted.
159
160### 4b. Database Validation
161
162After any interaction that should modify data (form submits, deletions, updates):
163
1641. Query the database to verify records. Use the environment variable from Sub-agent 2's research for the connection string and the schema docs to know what to check.
165 - **Postgres:** use psql directly — e.g., psql "$DATABASE_URL" -c "SELECT theme FROM profiles WHERE username = 'testuser'"
166 - **SQLite:** use sqlite3 directly — e.g., sqlite3 db.sqlite "SELECT theme FROM profiles WHERE username = 'testuser'"
167 - **Other databases:** write a small ad hoc script in the application's language, run it, then delete it
1682. Verify:
169 - Records created/updated/deleted as expected
170 - Values match what was entered in the UI
171 - Relationships between records are correct
172 - No orphaned or duplicate records
173
174### 4c. Issue Handling
175
176When an issue is found (UI bug, database mismatch, JS error):
177
1781. **Document it:** what was expected vs what happened, screenshot path, relevant DB query results
1792. **Fix the code** — make the correction directly
1803. **Re-run the failing step** to verify the fix worked
1814. **Take a new screenshot** confirming the fix
182
183### 4d. Responsive Testing
184
185For the responsive testing task, revisit key pages at these viewports:
186
187- **Mobile:** agent-browser set viewport 375 812
188- **Tablet:** agent-browser set viewport 768 1024
189- **Desktop:** agent-browser set viewport 1440 900
190
191At each viewport, screenshot every major page. Analyze for layout issues, overflow, broken alignment, and touch target sizes on mobile.
192
193After completing each journey, mark its task as completed with TaskUpdate.
194
195## Phase 5: Cleanup
196
197After all testing is complete:
1981. Stop the dev server background process
1992. Close the browser session: agent-browser close
200
201## Phase 6: Report
202
203### Text Summary (always output)
204
205Present a concise summary:
206
207```
208## E2E Testing Complete
209
210**Journeys Tested:** [count]
211**Screenshots Captured:** [count]
212**Issues Found:** [count] ([count] fixed, [count] remaining)
213
214### Issues Fixed During Testing
215- [Description] — [file:line]
216
217### Remaining Issues
218- [Description] — [severity: high/medium/low] — [file:line]
219
220### Bug Hunt Findings (from code analysis)
221- [Description] — [severity] — [file:line]
222
223### Screenshots
224All saved to: e2e-screenshots/
225```
226
227### Markdown Export (ask first)
228
229After the text summary, ask the user:
230
231> "Would you like me to export the full testing report to a markdown file? It includes per-journey breakdowns, all screenshot references, database validation results, and detailed findings — useful as context for follow-up fixes or GitHub issues."
232
233If yes, write a detailed report to e2e-test-report.md in the project root containing:
234- Full summary with stats
235- Per-journey breakdown: steps taken, screenshots, database checks, issues found
236- All issues with full details, fix status, and file references
237- Bug hunt findings from the code analysis sub-agent
238- Recommendations for any unresolved issues
239