E2E Playwright Diagnosis
Overview
This skill provides a systematic procedure for diagnosing and resolving E2E test failures in Playwright. It orchestrates multiple MCP tools (Playwright, Chrome DevTools, Serena) and delegates code corrections to specialized agents, ensuring all tests pass based on actual application behavior.
When to Use
- E2E test failure messages are received
- Playwright tests need root cause analysis
- Test failures require browser reproduction for debugging
- Multiple tests in a file are failing and need systematic resolution
Workflow Decision Tree
Error Message Received
│
▼
┌───────────────────┐
│ 1. Analyze Error │
│ Extract info │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ 2. Locate Test │
│ Read test file │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ 3. Prepare Env │
│ rm .next │
│ rebuild │
└─────────┬─────────┘
│
▼
┌───────────────────────────────┐
│ 4. Reproduce in Browser │
│ MCP Playwright + │
│ MCP Chrome DevTools │
└─────────┬─────────────────────┘
│
▼
Test passes?
/ \
Yes No
│ │
▼ ▼
┌─────────┐ ┌─────────────────┐
│ Run all │ │ Collect info │
│ tests │ │ via MCP Serena │
└────┬────┘ └────────┬────────┘
│ │
▼ ▼
All pass? ┌─────────────────┐
/ \ │ Delegate fix to │
Yes No │ context-manager │
│ │ │ → frontend-dev │
▼ ▼ └────────┬────────┘
┌────┐ ┌─────┐ │
│Done│ │Align│ ▼
│ │ │tests│ ┌─────────────────┐
└────┘ │to │ │ Validate fix │
│code │ │ Loop until pass │
└─────┘ └─────────────────┘
Detailed Procedure
Step 1: Analyze Initial Failure
- Receive the E2E test error message
- Analyze the complete error content
- Extract relevant information:
- Error type
- Stack trace
- Test file name
- Failed test name
Step 2: Identify Problematic Test
- Locate the E2E test file mentioned in the error
- Open the test file
- Identify the specific test that failed
- Read:
- The title (describe / test)
- The test body
- Infer which application behavior the test attempts to validate
Step 3: Prepare Environment
- Remove the
.next folder from the project:rm -rf apps/gateway-financeiro/.next
- Execute complete project rebuild to generate a new
.next folder:npm run build --workspace=apps/gateway-financeiro
Step 4: Reproduce Test in Browser
- Use MCP Playwright to execute the test in the browser
- Simultaneously use MCP Chrome DevTools to:
- Observe the DOM
- Monitor console errors
- Track network requests
- Execute only the test that failed
MCP Playwright tools to use:
mcp__playwright__browser_navigate - Navigate to test URL
mcp__playwright__browser_snapshot - Capture accessibility snapshot
mcp__playwright__browser_click - Interact with elements
mcp__playwright__browser_type - Fill form fields
MCP Chrome DevTools tools to use:
mcp__chrome-devtools__take_snapshot - Capture DOM state
mcp__chrome-devtools__list_console_messages - Check for errors
mcp__chrome-devtools__list_network_requests - Monitor API calls
Step 5: Evaluate Isolated Test Result
If the test passes in the browser:
- Read all other E2E tests present in the same file
- Execute all tests from that file, still via Playwright in the browser
- If tests pass isolated but fail in suite → Check for data isolation issues:
- Verify unique identifiers are generated per test, not per describe block
- Check backend logs for 409 Conflict or "already exists" errors
- Look for shared state between tests (cookies, localStorage, database records)
If all tests in the file pass:
- Invoke the
context-manager agent
- Through it, invoke the
frontend-nextjs-developer agent to:
- Adjust E2E tests to faithfully reflect the behavior already implemented in the code
- Consider the code as the source of truth
- Finalize the process
Step 6: When Test Cannot Be Reproduced in Browser
- If Playwright + Chrome DevTools cannot reproduce the error in the browser:
- Use MCP Serena to navigate the project
- Collect maximum possible information:
- Execution logs
- Server logs
- Playwright logs
- Execute only non-committable commands:
- Project rebuild
- Docker container rebuild
- Log inspection
- Do not alter any code or test files
MCP Serena tools to use:
mcp__serena__search_for_pattern - Search for error patterns in logs
mcp__serena__find_symbol - Locate relevant code symbols
mcp__serena__get_symbols_overview - Understand file structure
Step 7: Delegate Code Correction
- Invoke the
context-manager agent via Task tool:subagent_type: "context-manager"
- Through it, invoke the
frontend-nextjs-developer agent
- Provide the agent with:
- Error context
- Collected logs
- Expected behavior
- Await response confirming the code bug was fixed
Step 8: Validate Correction After Code Change
After fix confirmation:
- Remove the
.next folder again
- Execute project rebuild
- Execute only one test from the affected file
If the test passes:
- Execute the remaining tests from the same file
If the test does not pass:
- Use again:
- MCP Playwright
- MCP Chrome DevTools
- Execute the test in the browser
- Collect new information
Step 9: Validation Loop
- Repeat steps 21 to 23 until:
- All tests in the file pass successfully
- No remaining E2E failures related to the original error
Termination Condition
- Terminate the process only when:
- All E2E tests in the affected file are passing
- Test behavior is aligned with the actual application behavior
Important Notes
- Code is the source of truth: If the application behaves correctly but tests fail, adjust the tests
- Do not modify code during investigation: Only collect information until Step 7
- Always rebuild after changes: The
.next folder must be regenerated after any code change
- Use browser reproduction first: Visual debugging often reveals issues faster than log analysis
- Delegate appropriately: Code fixes go to
frontend-nextjs-developer, not handled directly by this skill
Quick Troubleshooting Checklist
When tests fail, check these common issues first:
- Backend validation errors (400) → Check API logs for "Bad Request" - often timeout masks schema mismatch (e.g., enum values, unexpected fields)
- Manual testing works, tests fail → Test in browser first; if app works, issue is in tests or contracts, not code
- Timeout on form submit → Check global timeout
playwright.config.ts (30s minimum); verify backend accepts request schema
- Strict mode violation → Multiple elements match selector; add
.first() or scope to container (e.g., dialog.locator())
- Stale locators after re-render → Use inline
.nth() selectors instead of storing references; re-query DOM after state changes
- Dropdown not opening/selecting → Add
waitForTimeout(500) after .click(); use waitForLoadState('networkidle') for async data
- Build cache stale →
rm -rf .next && npm run build, then restart Docker containers (docker restart administramos-gateway-financeiro)
- Redirect loops → Middleware must use
request.headers.get('host') not request.nextUrl.href (localhost vs public domain)
- Missing JS chunks (404) → Rebuild Next.js and restart container; browser may cache old build references
- Element not found → Use
browser_snapshot to see actual DOM; shadcn components often use portals (render outside parent)
- Timeout on element interaction (manual test works, logs show success) → Selector uses
.filter({ hasText: /pattern/ }) but element text is dynamic (e.g., "Loading...", "Select option"). Use getByRole('role', { name: 'Label' }) to match accessible name from label, not visible text
- 409 Conflict when creating records (passes isolated, fails in suite) → Unique identifier generated once at describe level, causing duplicate keys when multiple tests create records. Generate unique ID inside each test function that creates data:
const uniqueId = \E2E-${Date.now()}`;`. Discovery: Backend logs show "already exists" or duplicate key error
- Submit button clicked but form not submitted (no navigation, no errors) → Form validation not complete before submit, or button briefly disabled. Add
waitForTimeout(500) after filling last field, verify button not disabled before clicking: await expect(button).not.toBeDisabled(). Discovery: Screenshot shows filled form, button present but no action occurred
1---2name: e2e-playwright-diagnosis3description: Diagnose and resolve E2E test failures in Playwright. This skill should be used when E2E tests fail and need investigation, when Playwright test errors require root cause analysis, or when test failures need to be reproduced in the browser for debugging. Orchestrates MCP tools (Playwright, Chrome DevTools, Serena) and delegates code fixes to specialized agents.4---5
6# E2E Playwright Diagnosis
7
8## Overview
9
10This skill provides a systematic procedure for diagnosing and resolving E2E test failures in Playwright. It orchestrates multiple MCP tools (Playwright, Chrome DevTools, Serena) and delegates code corrections to specialized agents, ensuring all tests pass based on actual application behavior.
11
12## When to Use
13
14- E2E test failure messages are received
15- Playwright tests need root cause analysis
16- Test failures require browser reproduction for debugging
17- Multiple tests in a file are failing and need systematic resolution
18
19## Workflow Decision Tree
20
21```
22Error Message Received
23 │
24 ▼
25┌───────────────────┐
26│ 1. Analyze Error │
27│ Extract info │
28└─────────┬─────────┘
29 │
30 ▼
31┌───────────────────┐
32│ 2. Locate Test │
33│ Read test file │
34└─────────┬─────────┘
35 │
36 ▼
37┌───────────────────┐
38│ 3. Prepare Env │
39│ rm .next │
40│ rebuild │
41└─────────┬─────────┘
42 │
43 ▼
44┌───────────────────────────────┐
45│ 4. Reproduce in Browser │
46│ MCP Playwright + │
47│ MCP Chrome DevTools │
48└─────────┬─────────────────────┘
49 │
50 ▼
51 Test passes?
52 / \
53 Yes No
54 │ │
55 ▼ ▼
56┌─────────┐ ┌─────────────────┐
57│ Run all │ │ Collect info │
58│ tests │ │ via MCP Serena │
59└────┬────┘ └────────┬────────┘
60 │ │
61 ▼ ▼
62All pass? ┌─────────────────┐
63 / \ │ Delegate fix to │
64Yes No │ context-manager │
65 │ │ │ → frontend-dev │
66 ▼ ▼ └────────┬────────┘
67┌────┐ ┌─────┐ │
68│Done│ │Align│ ▼
69│ │ │tests│ ┌─────────────────┐
70└────┘ │to │ │ Validate fix │
71 │code │ │ Loop until pass │
72 └─────┘ └─────────────────┘
73```
74
75## Detailed Procedure
76
77### Step 1: Analyze Initial Failure
78
791. Receive the E2E test error message
802. Analyze the complete error content
813. Extract relevant information:
82 - Error type
83 - Stack trace
84 - Test file name
85 - Failed test name
86
87### Step 2: Identify Problematic Test
88
894. Locate the E2E test file mentioned in the error
905. Open the test file
916. Identify the specific test that failed
927. Read:
93 - The title (describe / test)
94 - The test body
958. Infer which application behavior the test attempts to validate
96
97### Step 3: Prepare Environment
98
999. Remove the `.next` folder from the project:
100 ```bash
101 rm -rf apps/gateway-financeiro/.next
102 ```
10310. Execute complete project rebuild to generate a new `.next` folder:
104 ```bash
105 npm run build --workspace=apps/gateway-financeiro
106 ```
107
108### Step 4: Reproduce Test in Browser
109
11011. Use **MCP Playwright** to execute the test in the browser
11112. Simultaneously use **MCP Chrome DevTools** to:
112 - Observe the DOM
113 - Monitor console errors
114 - Track network requests
11513. Execute only the test that failed
116
117**MCP Playwright tools to use:**
118- `mcp__playwright__browser_navigate` - Navigate to test URL
119- `mcp__playwright__browser_snapshot` - Capture accessibility snapshot
120- `mcp__playwright__browser_click` - Interact with elements
121- `mcp__playwright__browser_type` - Fill form fields
122
123**MCP Chrome DevTools tools to use:**
124- `mcp__chrome-devtools__take_snapshot` - Capture DOM state
125- `mcp__chrome-devtools__list_console_messages` - Check for errors
126- `mcp__chrome-devtools__list_network_requests` - Monitor API calls
127
128### Step 5: Evaluate Isolated Test Result
129
13014. **If the test passes in the browser:**
131 1. Read all other E2E tests present in the same file
132 2. Execute all tests from that file, still via Playwright in the browser
133 3. **If tests pass isolated but fail in suite** → Check for data isolation issues:
134 - Verify unique identifiers are generated per test, not per describe block
135 - Check backend logs for 409 Conflict or "already exists" errors
136 - Look for shared state between tests (cookies, localStorage, database records)
137
13815. **If all tests in the file pass:**
139 - Invoke the `context-manager` agent
140 - Through it, invoke the `frontend-nextjs-developer` agent to:
141 - Adjust E2E tests to faithfully reflect the behavior already implemented in the code
142 - Consider the code as the source of truth
143 - Finalize the process
144
145### Step 6: When Test Cannot Be Reproduced in Browser
146
14716. **If Playwright + Chrome DevTools cannot reproduce the error in the browser:**
148 1. Use **MCP Serena** to navigate the project
149 2. Collect maximum possible information:
150 - Execution logs
151 - Server logs
152 - Playwright logs
153 3. Execute only non-committable commands:
154 - Project rebuild
155 - Docker container rebuild
156 - Log inspection
157 4. **Do not alter any code or test files**
158
159**MCP Serena tools to use:**
160- `mcp__serena__search_for_pattern` - Search for error patterns in logs
161- `mcp__serena__find_symbol` - Locate relevant code symbols
162- `mcp__serena__get_symbols_overview` - Understand file structure
163
164### Step 7: Delegate Code Correction
165
16617. Invoke the `context-manager` agent via Task tool:
167 ```
168 subagent_type: "context-manager"
169 ```
17018. Through it, invoke the `frontend-nextjs-developer` agent
17119. Provide the agent with:
172 - Error context
173 - Collected logs
174 - Expected behavior
17520. Await response confirming the code bug was fixed
176
177### Step 8: Validate Correction After Code Change
178
17921. **After fix confirmation:**
180 1. Remove the `.next` folder again
181 2. Execute project rebuild
182 3. Execute only one test from the affected file
183
18422. **If the test passes:**
185 - Execute the remaining tests from the same file
186
18723. **If the test does not pass:**
188 - Use again:
189 - MCP Playwright
190 - MCP Chrome DevTools
191 - Execute the test in the browser
192 - Collect new information
193
194### Step 9: Validation Loop
195
19624. Repeat steps 21 to 23 until:
197 - All tests in the file pass successfully
198 - No remaining E2E failures related to the original error
199
200## Termination Condition
201
20225. Terminate the process only when:
203 - All E2E tests in the affected file are passing
204 - Test behavior is aligned with the actual application behavior
205
206## Important Notes
207
208- **Code is the source of truth**: If the application behaves correctly but tests fail, adjust the tests
209- **Do not modify code during investigation**: Only collect information until Step 7
210- **Always rebuild after changes**: The `.next` folder must be regenerated after any code change
211- **Use browser reproduction first**: Visual debugging often reveals issues faster than log analysis
212- **Delegate appropriately**: Code fixes go to `frontend-nextjs-developer`, not handled directly by this skill
213
214## Quick Troubleshooting Checklist
215
216When tests fail, check these common issues first:
217
2181. **Backend validation errors (400)** → Check API logs for "Bad Request" - often timeout masks schema mismatch (e.g., enum values, unexpected fields)
2192. **Manual testing works, tests fail** → Test in browser first; if app works, issue is in tests or contracts, not code
2203. **Timeout on form submit** → Check global timeout `playwright.config.ts` (30s minimum); verify backend accepts request schema
2214. **Strict mode violation** → Multiple elements match selector; add `.first()` or scope to container (e.g., `dialog.locator()`)
2225. **Stale locators after re-render** → Use inline `.nth()` selectors instead of storing references; re-query DOM after state changes
2236. **Dropdown not opening/selecting** → Add `waitForTimeout(500)` after `.click()`; use `waitForLoadState('networkidle')` for async data
2247. **Build cache stale** → `rm -rf .next && npm run build`, then restart Docker containers (`docker restart administramos-gateway-financeiro`)
2258. **Redirect loops** → Middleware must use `request.headers.get('host')` not `request.nextUrl.href` (localhost vs public domain)
2269. **Missing JS chunks (404)** → Rebuild Next.js and restart container; browser may cache old build references
22710. **Element not found** → Use `browser_snapshot` to see actual DOM; shadcn components often use portals (render outside parent)
22811. **Timeout on element interaction (manual test works, logs show success)** → Selector uses `.filter({ hasText: /pattern/ })` but element text is dynamic (e.g., "Loading...", "Select option"). Use `getByRole('role', { name: 'Label' })` to match accessible name from label, not visible text
22912. **409 Conflict when creating records (passes isolated, fails in suite)** → Unique identifier generated once at describe level, causing duplicate keys when multiple tests create records. Generate unique ID inside each test function that creates data: `const uniqueId = \`E2E-${Date.now()}\`;`. Discovery: Backend logs show "already exists" or duplicate key error
23013. **Submit button clicked but form not submitted (no navigation, no errors)** → Form validation not complete before submit, or button briefly disabled. Add `waitForTimeout(500)` after filling last field, verify button not disabled before clicking: `await expect(button).not.toBeDisabled()`. Discovery: Screenshot shows filled form, button present but no action occurred