@democratize-quality/mcp-server 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/cli.js +248 -0
  2. package/package.json +7 -5
  3. package/src/chatmodes//360/237/214/220 api-generator.chatmode.md" +409 -0
  4. package/src/chatmodes//360/237/214/220 api-healer.chatmode.md" +494 -0
  5. package/src/chatmodes//360/237/214/220 api-planner.chatmode.md" +954 -0
  6. package/src/config/environments/api-only.js +72 -0
  7. package/src/config/environments/development.js +73 -0
  8. package/src/config/environments/production.js +88 -0
  9. package/src/config/index.js +360 -0
  10. package/src/config/server.js +60 -0
  11. package/src/config/tools/api.js +86 -0
  12. package/src/config/tools/browser.js +109 -0
  13. package/src/config/tools/default.js +51 -0
  14. package/src/docs/Agent_README.md +310 -0
  15. package/src/docs/QUICK_REFERENCE.md +111 -0
  16. package/src/server.ts +234 -0
  17. package/src/services/browserService.js +344 -0
  18. package/src/skills/api-planning/SKILL.md +224 -0
  19. package/src/skills/test-execution/SKILL.md +777 -0
  20. package/src/skills/test-generation/SKILL.md +309 -0
  21. package/src/skills/test-healing/SKILL.md +405 -0
  22. package/src/tools/api/api-generator.js +1884 -0
  23. package/src/tools/api/api-healer.js +636 -0
  24. package/src/tools/api/api-planner.js +2617 -0
  25. package/src/tools/api/api-project-setup.js +332 -0
  26. package/src/tools/api/api-request.js +660 -0
  27. package/src/tools/api/api-session-report.js +1297 -0
  28. package/src/tools/api/api-session-status.js +414 -0
  29. package/src/tools/api/prompts/README.md +293 -0
  30. package/src/tools/api/prompts/generation-prompts.js +722 -0
  31. package/src/tools/api/prompts/healing-prompts.js +214 -0
  32. package/src/tools/api/prompts/index.js +44 -0
  33. package/src/tools/api/prompts/orchestrator.js +353 -0
  34. package/src/tools/api/prompts/validation-rules.js +358 -0
  35. package/src/tools/base/ToolBase.js +249 -0
  36. package/src/tools/base/ToolRegistry.js +288 -0
  37. package/src/tools/browser/advanced/browser-console.js +403 -0
  38. package/src/tools/browser/advanced/browser-dialog.js +338 -0
  39. package/src/tools/browser/advanced/browser-evaluate.js +356 -0
  40. package/src/tools/browser/advanced/browser-file.js +499 -0
  41. package/src/tools/browser/advanced/browser-keyboard.js +362 -0
  42. package/src/tools/browser/advanced/browser-mouse.js +351 -0
  43. package/src/tools/browser/advanced/browser-network.js +440 -0
  44. package/src/tools/browser/advanced/browser-pdf.js +426 -0
  45. package/src/tools/browser/advanced/browser-tabs.js +516 -0
  46. package/src/tools/browser/advanced/browser-wait.js +397 -0
  47. package/src/tools/browser/click.js +187 -0
  48. package/src/tools/browser/close.js +79 -0
  49. package/src/tools/browser/dom.js +89 -0
  50. package/src/tools/browser/launch.js +86 -0
  51. package/src/tools/browser/navigate.js +289 -0
  52. package/src/tools/browser/screenshot.js +370 -0
  53. package/src/tools/browser/type.js +193 -0
  54. package/src/tools/index.js +114 -0
  55. package/src/utils/agentInstaller.js +437 -0
  56. package/src/utils/browserHelpers.js +102 -0
@@ -0,0 +1,309 @@
1
+ ---
2
+ name: test-generation
3
+ description: Generate executable API tests from test plans in multiple formats (Playwright, Jest, Postman). Automatically detects project configuration and creates tests with proper authentication, setup, and error handling. Use when user wants to generate tests, create test files, convert test plans to code, or needs automated API test creation.
4
+ ---
5
+
6
+ # API Test Generation Skill
7
+
8
+ Use this skill to convert API test plans into executable test code in Playwright, Jest, or Postman formats.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - User has a test plan and wants to generate executable tests
13
+ - User mentions generating Playwright tests or Jest tests
14
+ - User needs to create Postman collections
15
+ - User wants to convert test documentation to code
16
+ - User requests automated test generation
17
+
18
+ ## Core Workflow
19
+
20
+ ### Step 1: Project Setup Detection (REQUIRED FIRST STEP)
21
+
22
+ **ALWAYS call `api_project_setup` tool FIRST** before generating any tests:
23
+
24
+ ```javascript
25
+ const setupResult = await tools.api_project_setup({
26
+ outputDir: "./tests" // or user-specified directory
27
+ })
28
+ ```
29
+
30
+ **The tool uses Smart Detection:**
31
+ - ✅ **Has playwright.config.ts** → Auto-detects: Playwright + TypeScript
32
+ - ✅ **Has playwright.config.js** → Auto-detects: Playwright + JavaScript
33
+ - ✅ **Has jest.config.ts** → Auto-detects: Jest + TypeScript
34
+ - ✅ **Has jest.config.js** → Auto-detects: Jest + JavaScript
35
+ - ⚠️ **Has tsconfig.json only** → Asks user: Which framework?
36
+ - ❓ **No config files** → Asks user: Framework + Language
37
+
38
+ ### Step 2: Handle Detection Results
39
+
40
+ **Case A: Auto-Detected Configuration**
41
+ ```javascript
42
+ if (setupResult.autoDetected) {
43
+ // Configuration found - proceed directly to generation
44
+ const framework = setupResult.config.framework; // 'playwright' or 'jest'
45
+ const language = setupResult.config.language; // 'typescript' or 'javascript'
46
+
47
+ console.log(`✓ Detected ${framework} project with ${language}`);
48
+ // Proceed to Step 3
49
+ }
50
+ ```
51
+
52
+ **Case B: Partial Detection (TypeScript found, need framework)**
53
+ ```javascript
54
+ if (setupResult.needsUserInput && setupResult.detected.hasTypeScript) {
55
+ // Ask user: "I found TypeScript. Which framework would you like to use?"
56
+ // Options: Playwright (recommended), Jest, Postman, All formats
57
+ // After user responds, store: language='typescript', framework=<user choice>
58
+ }
59
+ ```
60
+
61
+ **Case C: No Configuration (Empty project)**
62
+ ```javascript
63
+ if (setupResult.needsUserInput && !setupResult.detected.hasTypeScript) {
64
+ // Ask user both:
65
+ // 1. Which test framework? Playwright / Jest / Postman / All
66
+ // 2. Which language? TypeScript (recommended) / JavaScript
67
+ // After user responds, store both values
68
+ }
69
+ ```
70
+
71
+ ### Step 3: Extract Test Plan Content (When User Specifies Sections)
72
+
73
+ When user requests specific sections (e.g., "generate tests for section 1"):
74
+
75
+ ```javascript
76
+ // Read test plan file
77
+ const testPlanContent = await readFile("./api-test-plan.md");
78
+
79
+ // Parse sections using markdown headers (##)
80
+ // Extract requested sections preserving structure
81
+
82
+ // User says: "generate tests for section 1"
83
+ // Extract: Section at index 0 (first ## after title)
84
+
85
+ // User says: "tests for GET /api/v1/Users"
86
+ // Extract: Section(s) matching pattern in title
87
+ ```
88
+
89
+ **Include base URL** from plan overview in extracted content.
90
+
91
+ ### Step 4: Generate Tests with api_generator
92
+
93
+ ```javascript
94
+ await tools.api_generator({
95
+ // Use extracted content OR full plan path
96
+ testPlanContent: extractedContent, // for specific sections
97
+ // OR testPlanPath: "./api-test-plan.md", // for full plan
98
+
99
+ // Use detected/chosen configuration from Step 1
100
+ outputFormat: detectedConfig.framework, // 'playwright', 'jest', 'postman', 'all'
101
+ language: detectedConfig.language, // 'typescript' or 'javascript'
102
+
103
+ // Pass project info from Step 1
104
+ projectInfo: {
105
+ hasTypeScript: detectedConfig.hasTypeScript,
106
+ hasPlaywrightConfig: detectedConfig.hasPlaywrightConfig,
107
+ hasJestConfig: detectedConfig.hasJestConfig
108
+ },
109
+
110
+ // Additional parameters
111
+ outputDir: "./tests",
112
+ sessionId: "api-gen-" + Date.now(),
113
+ includeAuth: true,
114
+ includeSetup: true,
115
+ baseUrl: "https://api.example.com" // optional override
116
+ })
117
+ ```
118
+
119
+ ## Output Formats
120
+
121
+ ### Playwright Tests (TypeScript/JavaScript)
122
+ - Browser-based API testing with request fixture
123
+ - Full HTTP client with assertions
124
+ - TypeScript types for better IDE support
125
+
126
+ ### Jest Tests (TypeScript/JavaScript)
127
+ - Node.js API testing with axios
128
+ - Popular testing framework
129
+ - Easy integration with existing projects
130
+
131
+ ### Postman Collections
132
+ - Import-ready JSON format
133
+ - Environment variables included
134
+ - Can be used in Postman or Newman
135
+
136
+ ### All Formats
137
+ - Generate all three formats simultaneously
138
+ - Maximum compatibility
139
+ - Ready for different testing scenarios
140
+
141
+ ## Example Generation Scenarios
142
+
143
+ ### Scenario 1: New Empty Project
144
+ ```
145
+ 1. User asks to generate tests
146
+ 2. Call api_project_setup → No config detected
147
+ 3. Ask user: Framework? Language?
148
+ 4. User chooses: Playwright + JavaScript
149
+ 5. Call api_generator with choices
150
+ 6. Generate tests + setup instructions
151
+ ```
152
+
153
+ ### Scenario 2: Existing TypeScript Project
154
+ ```
155
+ 1. User asks to generate tests
156
+ 2. Call api_project_setup → Auto-detects Playwright + TypeScript
157
+ 3. Call api_generator with detected config
158
+ 4. Generate tests (no user input needed)
159
+ ```
160
+
161
+ ### Scenario 3: Specific Section Request
162
+ ```
163
+ 1. User: "Generate tests for section 2"
164
+ 2. Call api_project_setup → Detect config
165
+ 3. Read test plan and extract section 2
166
+ 4. Call api_generator with extracted content + config
167
+ 5. Generate tests for that section only
168
+ ```
169
+
170
+ ### Scenario 4: Override Auto-Detection
171
+ ```
172
+ 1. User: "Generate Jest tests in JavaScript"
173
+ 2. Call api_project_setup (may detect Playwright)
174
+ 3. User explicitly wants Jest + JS → Use user preference
175
+ 4. Call api_generator with outputFormat='jest', language='javascript'
176
+ 5. Generate requested format
177
+ ```
178
+
179
+ ## Session Management and Validation
180
+
181
+ After generation, validate using API request tools:
182
+
183
+ ```javascript
184
+ // Validate generated tests work
185
+ await tools.api_request({
186
+ sessionId: "validation-session",
187
+ method: "POST",
188
+ url: "https://api.example.com/auth/login",
189
+ data: { email: "test@example.com", password: "test123" },
190
+ expect: { status: 200 },
191
+ extract: { token: "access_token" }
192
+ })
193
+
194
+ // Check session status
195
+ await tools.api_session_status({
196
+ sessionId: "validation-session"
197
+ })
198
+
199
+ // Generate validation report
200
+ await tools.api_session_report({
201
+ sessionId: "validation-session",
202
+ outputPath: "./validation-report.html"
203
+ })
204
+ ```
205
+
206
+ ## Manual Test Creation (Fallback)
207
+
208
+ When automatic generation needs refinement:
209
+
210
+ ```javascript
211
+ // Create custom test files
212
+ await tools.edit_createFile({
213
+ path: "./tests/custom-api-test.spec.ts",
214
+ content: `import { test, expect } from '@playwright/test';
215
+
216
+ test.describe('Custom API Tests', () => {
217
+ test('should validate custom scenario', async ({ request }) => {
218
+ const response = await request.get('https://api.example.com/custom');
219
+ expect(response.status()).toBe(200);
220
+ });
221
+ });`
222
+ })
223
+ ```
224
+
225
+ ## Best Practices
226
+
227
+ ### DO:
228
+ - Always call `api_project_setup` first
229
+ - Let tool auto-detect configuration when possible
230
+ - Extract specific sections when user requests them
231
+ - Validate generated tests with api_request
232
+ - Provide clear feedback about detected configuration
233
+ - Use consistent sessionId for related operations
234
+ - Generate comprehensive reports
235
+
236
+ ### DON'T:
237
+ - Don't skip project setup detection
238
+ - Don't guess configuration - detect or ask
239
+ - Don't generate without confirmation if detection fails
240
+ - Don't ignore user's explicit format preferences
241
+ - Don't generate without preserving test plan structure
242
+
243
+ ## Error Handling
244
+
245
+ If test generation fails:
246
+ 1. Check if project setup was called first
247
+ 2. Verify test plan format is correct
248
+ 3. Ensure configuration matches project structure
249
+ 4. Try manual file creation as fallback
250
+ 5. Provide clear error messages to user
251
+
252
+ ## Generated Test Structure
253
+
254
+ ### Playwright Example:
255
+ ```typescript
256
+ import { test, expect } from '@playwright/test';
257
+
258
+ test.describe('Books API', () => {
259
+ test('GET /api/v1/Books - should return all books', async ({ request }) => {
260
+ const response = await request.get('https://api.example.com/api/v1/Books');
261
+ expect(response.ok()).toBeTruthy();
262
+ expect(response.status()).toBe(200);
263
+ const books = await response.json();
264
+ expect(Array.isArray(books)).toBeTruthy();
265
+ });
266
+ });
267
+ ```
268
+
269
+ ### Jest Example:
270
+ ```typescript
271
+ import axios from 'axios';
272
+
273
+ describe('Books API', () => {
274
+ const baseUrl = 'https://api.example.com';
275
+
276
+ test('GET /api/v1/Books - should return all books', async () => {
277
+ const response = await axios.get(`${baseUrl}/api/v1/Books`);
278
+ expect(response.status).toBe(200);
279
+ expect(Array.isArray(response.data)).toBe(true);
280
+ });
281
+ });
282
+ ```
283
+
284
+ ## Additional Tools Available
285
+
286
+ Use these file manipulation tools when needed:
287
+ - `search/fileSearch` - Find test files
288
+ - `search/textSearch` - Search within files
289
+ - `search/listDirectory` - List test directory
290
+ - `search/readFile` - Read existing tests
291
+ - `edit/createFile` - Create new test files
292
+ - `edit/editFiles` - Modify existing tests
293
+
294
+ ## Troubleshooting
295
+
296
+ ### Project setup not detecting configuration
297
+ - Verify config files exist in correct location
298
+ - Check file names match expected patterns
299
+ - Manually ask user for preferences
300
+
301
+ ### Generated tests don't match project structure
302
+ - Ensure project setup was called first
303
+ - Verify outputFormat matches project framework
304
+ - Check language setting matches project
305
+
306
+ ### Tests fail to run after generation
307
+ - Validate with api_request tool
308
+ - Check API endpoint availability
309
+ - Verify authentication configuration
@@ -0,0 +1,405 @@
1
+ ---
2
+ name: test-healing
3
+ description: Debug and automatically fix failing API tests using intelligent analysis and healing strategies. Repairs authentication issues, endpoint changes, schema mismatches, and assertion failures. Use when tests are failing, broken, or need debugging after API changes.
4
+ ---
5
+
6
+ # API Test Healing Skill
7
+
8
+ Use this skill to automatically diagnose and fix failing API tests through systematic analysis and intelligent healing strategies.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - User mentions failing tests or broken tests
13
+ - Tests are not passing after API changes
14
+ - Authentication errors in API tests
15
+ - Schema mismatches or validation failures
16
+ - User needs to debug API test failures
17
+ - Tests need updating after API deployment
18
+
19
+ ## Core Workflow
20
+
21
+ ### Step 1: Automated Healing (Primary Approach)
22
+
23
+ **ALWAYS use `api_healer` tool first** for automated healing:
24
+
25
+ ```javascript
26
+ // Heal specific test file
27
+ await tools.api_healer({
28
+ testPath: "./tests/api-tests.spec.js",
29
+ testType: "auto", // jest, playwright, postman, auto
30
+ sessionId: "healing-session",
31
+ maxHealingAttempts: 3,
32
+ autoFix: true,
33
+ backupOriginal: true,
34
+ healingStrategies: [
35
+ "schema-update",
36
+ "endpoint-fix",
37
+ "auth-repair",
38
+ "data-correction",
39
+ "assertion-update"
40
+ ]
41
+ })
42
+
43
+ // Heal multiple test files
44
+ await tools.api_healer({
45
+ testFiles: [
46
+ "./tests/auth.test.js",
47
+ "./tests/users.test.js",
48
+ "./tests/orders.test.js"
49
+ ],
50
+ autoFix: true,
51
+ analysisOnly: false // set to true for analysis without fixing
52
+ })
53
+ ```
54
+
55
+ ### Step 2: Healing Strategies
56
+
57
+ The `api_healer` tool implements these automatic strategies:
58
+
59
+ #### Schema Update
60
+ - Detects API response schema changes
61
+ - Updates test assertions to match current API structure
62
+ - Fixes property name changes and type mismatches
63
+
64
+ #### Endpoint Fix
65
+ - Identifies 404 errors from changed endpoints
66
+ - Attempts to discover correct endpoint URLs
67
+ - Updates test configurations with working endpoints
68
+
69
+ #### Authentication Repair
70
+ - Fixes expired or invalid authentication tokens
71
+ - Updates authentication methods and headers
72
+ - Repairs OAuth flows and API key issues
73
+
74
+ #### Data Correction
75
+ - Fixes request payload validation errors
76
+ - Updates test data to match current API requirements
77
+ - Corrects data types and required fields
78
+
79
+ #### Assertion Update
80
+ - Updates test expectations based on actual API responses
81
+ - Fixes assertion mismatches and validation rules
82
+ - Aligns test expectations with current API behavior
83
+
84
+ ### Step 3: Manual Healing (When Automated Healing Needs Assistance)
85
+
86
+ #### Analysis Mode
87
+ ```javascript
88
+ // Use analysis-only mode first
89
+ await tools.api_healer({
90
+ testPath: "./failing-test.js",
91
+ analysisOnly: true,
92
+ sessionId: "analysis-session"
93
+ })
94
+ ```
95
+
96
+ #### Diagnostic Testing
97
+ ```javascript
98
+ // Test authentication manually
99
+ await tools.api_request({
100
+ sessionId: "diagnostic-session",
101
+ method: "POST",
102
+ url: "https://api.example.com/auth/login",
103
+ data: { email: "test@example.com", password: "test123" },
104
+ expect: { status: [200, 401] },
105
+ extract: { token: "access_token" }
106
+ })
107
+
108
+ // Test failing endpoint with auth
109
+ await tools.api_request({
110
+ sessionId: "diagnostic-session",
111
+ method: "GET",
112
+ url: "https://api.example.com/protected-resource",
113
+ headers: { "Authorization": "Bearer {{token}}" },
114
+ expect: { status: [200, 401, 403, 404] }
115
+ })
116
+ ```
117
+
118
+ #### Targeted Fixes
119
+ ```javascript
120
+ // Apply specific healing strategies
121
+ await tools.api_healer({
122
+ testPath: "./failing-test.js",
123
+ healingStrategies: ["auth-repair"], // Target specific issues
124
+ maxHealingAttempts: 1,
125
+ autoFix: true
126
+ })
127
+ ```
128
+
129
+ ## Common Failure Categories
130
+
131
+ ### 1. Authentication Failures
132
+ **Symptoms:** 401 Unauthorized, 403 Forbidden responses
133
+
134
+ **Causes:**
135
+ - Expired tokens
136
+ - Invalid credentials
137
+ - Missing authorization headers
138
+
139
+ **Healing Actions:**
140
+ - Refresh authentication flow
141
+ - Update token generation
142
+ - Fix header format
143
+
144
+ ### 2. Request Format Issues
145
+ **Symptoms:** 400 Bad Request, validation errors
146
+
147
+ **Causes:**
148
+ - Invalid JSON
149
+ - Missing required fields
150
+ - Incorrect data types
151
+
152
+ **Healing Actions:**
153
+ - Update request payload structure
154
+ - Fix field mappings
155
+ - Correct data types
156
+
157
+ ### 3. Response Validation Mismatches
158
+ **Symptoms:** Test assertions failing on response content
159
+
160
+ **Causes:**
161
+ - API schema changes
162
+ - New fields added/removed
163
+ - Data format updates
164
+
165
+ **Healing Actions:**
166
+ - Update validation rules
167
+ - Adjust expected response structure
168
+ - Fix assertion patterns
169
+
170
+ ### 4. Endpoint Changes
171
+ **Symptoms:** 404 Not Found, method not allowed errors
172
+
173
+ **Causes:**
174
+ - API versioning
175
+ - Endpoint deprecation
176
+ - URL structure changes
177
+
178
+ **Healing Actions:**
179
+ - Update endpoint URLs
180
+ - Change HTTP methods
181
+ - Handle API versioning
182
+
183
+ ### 5. Data Dependencies
184
+ **Symptoms:** Tests failing due to missing/invalid test data
185
+
186
+ **Causes:**
187
+ - Test data cleanup
188
+ - External service dependencies
189
+ - Race conditions
190
+
191
+ **Healing Actions:**
192
+ - Improve test data setup
193
+ - Add proper cleanup
194
+ - Handle async operations
195
+
196
+ ## Debugging Methodology
197
+
198
+ ### 1. Parse Error Messages
199
+ - Analyze validation failures, HTTP errors, timeout issues
200
+ - Examine differences between expected and actual responses
201
+ - Identify error patterns
202
+
203
+ ### 2. Compare Expected vs Actual
204
+ - Look at response structure differences
205
+ - Check data type mismatches
206
+ - Identify missing or extra fields
207
+
208
+ ### 3. Trace Request Flow
209
+ - Follow the complete request/response cycle
210
+ - Identify break points in the flow
211
+ - Check intermediate steps
212
+
213
+ ### 4. Check Dependencies
214
+ - Verify prerequisite API calls work
215
+ - Validate test data setup
216
+ - Confirm authentication is valid
217
+
218
+ ## Session Management and Reporting
219
+
220
+ ```javascript
221
+ // Check healing session status
222
+ await tools.api_session_status({
223
+ sessionId: "healing-session"
224
+ })
225
+
226
+ // Generate healing report
227
+ await tools.api_session_report({
228
+ sessionId: "healing-session",
229
+ outputPath: "./healing-report.html"
230
+ })
231
+ ```
232
+
233
+ ## Best Practices
234
+
235
+ ### DO:
236
+ - Use api_healer tool immediately for automated fixing
237
+ - Create backups before making changes (default: true)
238
+ - Analyze patterns in multiple failing tests
239
+ - Apply targeted healing strategies when possible
240
+ - Validate fixes by re-running tests
241
+ - Document changes made during healing
242
+ - Use session tracking for comprehensive analysis
243
+
244
+ ### DON'T:
245
+ - Don't manually edit tests before trying automated healing
246
+ - Don't ignore error patterns across multiple tests
247
+ - Don't skip analysis mode for complex failures
248
+ - Don't apply all strategies blindly
249
+ - Don't forget to verify fixes work
250
+ - Don't lose track of what was changed
251
+
252
+ ## Standard Test Pattern Examples
253
+
254
+ ### Jest Test Structure
255
+ ```javascript
256
+ const axios = require('axios');
257
+
258
+ describe('API Test Suite', () => {
259
+ const baseUrl = 'https://api.example.com/v1';
260
+ let authToken;
261
+
262
+ beforeAll(async () => {
263
+ // Setup code
264
+ const authResponse = await axios.post(`${baseUrl}/auth/login`, {
265
+ username: 'test',
266
+ password: 'password'
267
+ });
268
+ authToken = authResponse.data.token;
269
+ });
270
+
271
+ test('should get data successfully', async () => {
272
+ const response = await axios.get(`${baseUrl}/data`, {
273
+ headers: { 'Authorization': `Bearer ${authToken}` }
274
+ });
275
+
276
+ expect(response.status).toBe(200);
277
+ expect(response.data).toHaveProperty('id');
278
+ });
279
+ });
280
+ ```
281
+
282
+ ### Playwright Test Structure
283
+ ```typescript
284
+ import { test, expect } from '@playwright/test';
285
+
286
+ test.describe('API Test Suite', () => {
287
+ let authToken: string;
288
+
289
+ test.beforeAll(async ({ request }) => {
290
+ const response = await request.post('/auth/login', {
291
+ data: { username: 'test', password: 'password' }
292
+ });
293
+ const data = await response.json();
294
+ authToken = data.token;
295
+ });
296
+
297
+ test('should get data successfully', async ({ request }) => {
298
+ const response = await request.get('/data', {
299
+ headers: { 'Authorization': `Bearer ${authToken}` }
300
+ });
301
+
302
+ expect(response.ok()).toBeTruthy();
303
+ const data = await response.json();
304
+ expect(data).toHaveProperty('id');
305
+ });
306
+ });
307
+ ```
308
+
309
+ ## Common Fix Patterns
310
+
311
+ ### Authentication Fix
312
+ ```javascript
313
+ // Before (failing)
314
+ const response = await axios.get('/protected-endpoint');
315
+
316
+ // After (fixed with proper auth)
317
+ const response = await axios.get('/protected-endpoint', {
318
+ headers: {
319
+ 'Authorization': `Bearer ${authToken}`,
320
+ 'Content-Type': 'application/json'
321
+ }
322
+ });
323
+ ```
324
+
325
+ ### Response Validation Fix
326
+ ```javascript
327
+ // Before (failing due to wrong expectations)
328
+ expect(response.data.items).toHaveLength(10);
329
+
330
+ // After (fixed based on actual API response)
331
+ expect(Array.isArray(response.data.items)).toBe(true);
332
+ expect(response.data.items.length).toBeGreaterThan(0);
333
+ ```
334
+
335
+ ### Error Handling Improvement
336
+ ```javascript
337
+ // Before (basic error handling)
338
+ try {
339
+ const response = await axios.get('/endpoint');
340
+ expect(response.status).toBe(200);
341
+ } catch (error) {
342
+ throw error;
343
+ }
344
+
345
+ // After (proper error handling)
346
+ test('should handle 404 errors correctly', async () => {
347
+ await expect(axios.get('/nonexistent-endpoint'))
348
+ .rejects
349
+ .toMatchObject({
350
+ response: {
351
+ status: 404
352
+ }
353
+ });
354
+ });
355
+ ```
356
+
357
+ ## Output Requirements
358
+
359
+ When healing tests, provide:
360
+
361
+ 1. **Detailed failure analysis** - Categorize error types
362
+ 2. **Applied healing strategies** - List what was attempted
363
+ 3. **Fixed test files** - Show modified code with backups
364
+ 4. **Healing report** - Summary of changes and success rate
365
+ 5. **Recommendations** - Suggest how to prevent similar issues
366
+ 6. **Verification status** - Confirm tests now pass
367
+
368
+ ## Error Resolution Strategy
369
+
370
+ - Make reasonable assumptions and fix issues automatically
371
+ - Fix one issue at a time and re-test to verify
372
+ - Use standard test patterns (Jest/Playwright conventions)
373
+ - Preserve test coverage while updating for API changes
374
+ - Improve test maintainability during fixes
375
+ - If API is fundamentally broken, mark tests as skipped with comments
376
+ - Continue until all tests pass or are properly documented
377
+
378
+ ## Additional Tools Available
379
+
380
+ Use these tools for manual investigation when needed:
381
+ - `search/fileSearch` - Find test files
382
+ - `search/textSearch` - Search for error patterns
383
+ - `search/readFile` - Read test file contents
384
+ - `edit/editFiles` - Manually fix tests after analysis
385
+ - `search/listDirectory` - List test directories
386
+
387
+ ## Troubleshooting
388
+
389
+ ### Automated healing not working
390
+ - Check if test file path is correct
391
+ - Verify test type detection is accurate
392
+ - Try analysis mode first to understand issues
393
+ - Apply targeted strategies instead of all
394
+
395
+ ### Tests still failing after healing
396
+ - Use api_request for manual endpoint testing
397
+ - Check if API is actually working
398
+ - Validate authentication separately
399
+ - Consider if API changes are breaking
400
+
401
+ ### Cannot identify failure cause
402
+ - Use analysis-only mode
403
+ - Check session status for more details
404
+ - Generate healing report for comprehensive view
405
+ - Test API endpoints manually with api_request