@democratize-quality/mcp-server 1.1.8 → 1.2.0

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 (64) hide show
  1. package/LICENSE +658 -12
  2. package/README.md +11 -6
  3. package/dist/server.d.ts +41 -0
  4. package/dist/server.d.ts.map +1 -0
  5. package/dist/server.js +225 -0
  6. package/dist/server.js.map +1 -0
  7. package/package.json +24 -25
  8. package/browserControl.js +0 -113
  9. package/cli.js +0 -228
  10. package/mcpServer.js +0 -335
  11. package/run-server.js +0 -140
  12. package/src/chatmodes//360/237/214/220 api-generator.chatmode.md" +0 -409
  13. package/src/chatmodes//360/237/214/220 api-healer.chatmode.md" +0 -494
  14. package/src/chatmodes//360/237/214/220 api-planner.chatmode.md" +0 -954
  15. package/src/config/environments/api-only.js +0 -53
  16. package/src/config/environments/development.js +0 -54
  17. package/src/config/environments/production.js +0 -69
  18. package/src/config/index.js +0 -341
  19. package/src/config/server.js +0 -41
  20. package/src/config/tools/api.js +0 -67
  21. package/src/config/tools/browser.js +0 -90
  22. package/src/config/tools/default.js +0 -32
  23. package/src/docs/Agent_README.md +0 -310
  24. package/src/docs/QUICK_REFERENCE.md +0 -111
  25. package/src/services/browserService.js +0 -325
  26. package/src/skills/api-planning/SKILL.md +0 -224
  27. package/src/skills/test-execution/SKILL.md +0 -728
  28. package/src/skills/test-generation/SKILL.md +0 -309
  29. package/src/skills/test-healing/SKILL.md +0 -405
  30. package/src/tools/api/api-generator.js +0 -1865
  31. package/src/tools/api/api-healer.js +0 -617
  32. package/src/tools/api/api-planner.js +0 -2598
  33. package/src/tools/api/api-project-setup.js +0 -313
  34. package/src/tools/api/api-request.js +0 -641
  35. package/src/tools/api/api-session-report.js +0 -1278
  36. package/src/tools/api/api-session-status.js +0 -395
  37. package/src/tools/api/prompts/README.md +0 -293
  38. package/src/tools/api/prompts/generation-prompts.js +0 -703
  39. package/src/tools/api/prompts/healing-prompts.js +0 -195
  40. package/src/tools/api/prompts/index.js +0 -25
  41. package/src/tools/api/prompts/orchestrator.js +0 -334
  42. package/src/tools/api/prompts/validation-rules.js +0 -339
  43. package/src/tools/base/ToolBase.js +0 -230
  44. package/src/tools/base/ToolRegistry.js +0 -269
  45. package/src/tools/browser/advanced/browser-console.js +0 -384
  46. package/src/tools/browser/advanced/browser-dialog.js +0 -319
  47. package/src/tools/browser/advanced/browser-evaluate.js +0 -337
  48. package/src/tools/browser/advanced/browser-file.js +0 -480
  49. package/src/tools/browser/advanced/browser-keyboard.js +0 -343
  50. package/src/tools/browser/advanced/browser-mouse.js +0 -332
  51. package/src/tools/browser/advanced/browser-network.js +0 -421
  52. package/src/tools/browser/advanced/browser-pdf.js +0 -407
  53. package/src/tools/browser/advanced/browser-tabs.js +0 -497
  54. package/src/tools/browser/advanced/browser-wait.js +0 -378
  55. package/src/tools/browser/click.js +0 -168
  56. package/src/tools/browser/close.js +0 -60
  57. package/src/tools/browser/dom.js +0 -70
  58. package/src/tools/browser/launch.js +0 -67
  59. package/src/tools/browser/navigate.js +0 -270
  60. package/src/tools/browser/screenshot.js +0 -351
  61. package/src/tools/browser/type.js +0 -174
  62. package/src/tools/index.js +0 -95
  63. package/src/utils/agentInstaller.js +0 -418
  64. package/src/utils/browserHelpers.js +0 -83
@@ -1,703 +0,0 @@
1
- /**
2
- * Code Generation Prompts for API Test Generator
3
- *
4
- * This module contains all prompts used for AI-based test code generation.
5
- * Separated for easy iteration, versioning, and prompt engineering.
6
- */
7
-
8
- module.exports = {
9
- /**
10
- * Playwright test generation prompts
11
- */
12
- playwright: {
13
- system: `You are an expert Playwright test engineer. Generate clean, idiomatic, production-ready Playwright API tests.
14
-
15
- CRITICAL - File Generation Rules:
16
- - Generate ONLY the ONE requested test file
17
- - DO NOT create any additional files (README, SUMMARY, GUIDE, NOTES, etc.)
18
- - DO NOT create documentation files unless explicitly requested
19
- - DO NOT create helper files unless explicitly requested
20
- - Output ONLY the test code for the specified file
21
-
22
- Requirements:
23
- - Use Playwright's request fixture directly (no wrappers)
24
- - Use proper TypeScript types when language=typescript
25
- - Include proper async/await patterns
26
- - Use template literals for URL construction with \${baseUrl}
27
- - Generate proper assertions with expect()
28
- - Handle both single and chained requests
29
- - Include proper error handling
30
- - Add descriptive comments for complex logic
31
-
32
- Code Style:
33
- - 2-space indentation
34
- - Single quotes for strings (except template literals)
35
- - Semicolons at end of statements
36
- - Clear variable naming
37
- - Proper spacing and formatting`,
38
-
39
- /**
40
- * Generate a section test file with multiple scenarios
41
- */
42
- generateTest: (context) => {
43
- const { testPlanTitle, baseUrl, sectionTitle, scenarios, language, isTypeScript, sessionId } = context;
44
-
45
- let prompt = `Generate a complete Playwright test file for this section:
46
-
47
- **Test Plan:** ${testPlanTitle}
48
- **Section:** ${sectionTitle}
49
- **Base URL:** ${baseUrl}
50
- **Language:** ${language}
51
- **Session ID:** ${sessionId}
52
-
53
- **Scenarios to test:**
54
- `;
55
-
56
- scenarios.forEach((scenario, idx) => {
57
- prompt += `
58
- ${idx + 1}. **${scenario.title}**
59
- - Method: ${scenario.method}
60
- - Endpoint: ${scenario.endpoint}
61
- - Expected Status: ${scenario.expectedStatus || 200}
62
- `;
63
-
64
- if (scenario.requestBody) {
65
- prompt += ` - Request Body: ${JSON.stringify(scenario.requestBody, null, 2).substring(0, 200)}...
66
- `;
67
- }
68
-
69
- if (scenario.expectedBody) {
70
- prompt += ` - Expected Body Fields: ${Object.keys(scenario.expectedBody).join(', ')}
71
- `;
72
- }
73
-
74
- if (scenario.steps && scenario.steps.length > 0) {
75
- prompt += ` - Multi-step test with ${scenario.steps.length} sequential requests
76
- `;
77
- }
78
- });
79
-
80
- prompt += `
81
- **Instructions:**
82
- 1. Generate a COMPLETE test file including imports and test structure
83
- 2. ${isTypeScript ? 'Use TypeScript with proper types' : 'Use JavaScript'}
84
- 3. Import from '@playwright/test' for Playwright
85
- 4. Create test.describe() for the section: "${sectionTitle}"
86
- 5. Create one test() for each scenario above
87
- 6. Use \`const baseUrl = '${baseUrl}';\` at the top of describe block
88
- 7. Use Playwright's \`request\` fixture directly (no helper classes)
89
- 8. Construct URLs as template literals: \`\${baseUrl}/endpoint\`
90
- 9. Include proper assertions for status codes and response body structure
91
- 10. For multi-step tests, chain requests and pass data between steps
92
- 11. Add error handling where appropriate
93
- 12. Include comments for complex logic
94
-
95
- **CRITICAL - Output Restrictions:**
96
- - Generate ONLY this ONE test file: ${sectionTitle}
97
- - DO NOT generate README, SUMMARY, GUIDE, or any other files
98
- - DO NOT suggest creating additional files
99
- - DO NOT include file creation instructions
100
- - Return ONLY the test file code as plain text
101
-
102
- **File structure:**
103
- \`\`\`
104
- // Header comment
105
- import/require statements
106
- test.describe('${sectionTitle}', () => {
107
- const baseUrl = '${baseUrl}';
108
-
109
- test('scenario 1', async ({ request }) => {
110
- // test code
111
- });
112
-
113
- test('scenario 2', async ({ request }) => {
114
- // test code
115
- });
116
- });
117
- \`\`\`
118
-
119
- Return the COMPLETE file content for THIS FILE ONLY.`;
120
-
121
- return prompt;
122
- },
123
-
124
- /**
125
- * Generate main test file that runs all sections
126
- */
127
- generateMainTest: (context) => {
128
- const { testPlanTitle, baseUrl, sections, language, isTypeScript, sessionId } = context;
129
-
130
- let prompt = `Generate a main Playwright test file that orchestrates all test sections:
131
-
132
- **Test Plan:** ${testPlanTitle}
133
- **Base URL:** ${baseUrl}
134
- **Language:** ${language}
135
- **Session ID:** ${sessionId}
136
-
137
- **Sections:**
138
- `;
139
-
140
- sections.forEach((section, idx) => {
141
- prompt += `${idx + 1}. ${section.title} (${section.scenarioCount} scenarios)
142
- `;
143
- });
144
-
145
- prompt += `
146
- **Instructions:**
147
- 1. Generate a COMPLETE main test file
148
- 2. ${isTypeScript ? 'Use TypeScript' : 'Use JavaScript'}
149
- 3. Import from '@playwright/test'
150
- 4. Create one main test.describe() for "${testPlanTitle}"
151
- 5. Set \`const baseUrl = '${baseUrl}';\`
152
- 6. Import or reference individual section test files
153
- 7. Keep it simple - this is just an orchestration file
154
- 8. Add a comment noting individual sections are in separate files
155
-
156
- **CRITICAL - Output Restrictions:**
157
- - Generate ONLY this ONE main test file
158
- - DO NOT generate README, SUMMARY, GUIDE, or any other files
159
- - DO NOT create section files (they're generated separately)
160
- - Return ONLY the main test file code
161
-
162
- Return the COMPLETE main file content for THIS FILE ONLY.`;
163
-
164
- return prompt;
165
- }
166
- },
167
-
168
- /**
169
- * Jest test generation prompts
170
- */
171
- jest: {
172
- system: `You are an expert Jest test engineer. Generate clean, idiomatic, production-ready Jest API tests using axios.
173
-
174
- CRITICAL - File Generation Rules:
175
- - Generate ONLY the ONE requested test file
176
- - DO NOT create any additional files (README, SUMMARY, GUIDE, NOTES, etc.)
177
- - DO NOT create documentation files unless explicitly requested
178
- - Output ONLY the test code for the specified file
179
-
180
- Requirements:
181
- - Use axios for API calls
182
- - Use proper TypeScript types when language=typescript
183
- - Include proper async/await patterns
184
- - Generate proper assertions with expect()
185
- - Handle both single and chained requests
186
- - Include proper error handling
187
-
188
- Code Style:
189
- - 2-space indentation
190
- - Single quotes for strings (except template literals)
191
- - Semicolons at end of statements
192
- - Clear variable naming`,
193
-
194
- /**
195
- * Generate a section test file with multiple scenarios
196
- */
197
- generateTest: (context) => {
198
- const { testPlanTitle, baseUrl, sectionTitle, scenarios, language, isTypeScript, sessionId } = context;
199
-
200
- let prompt = `Generate a complete Jest test file for this section:
201
-
202
- **Test Plan:** ${testPlanTitle}
203
- **Section:** ${sectionTitle}
204
- **Base URL:** ${baseUrl}
205
- **Language:** ${language}
206
- **Session ID:** ${sessionId}
207
-
208
- **Scenarios to test:**
209
- `;
210
-
211
- scenarios.forEach((scenario, idx) => {
212
- prompt += `
213
- ${idx + 1}. **${scenario.title}**
214
- - Method: ${scenario.method}
215
- - Endpoint: ${scenario.endpoint}
216
- - Expected Status: ${scenario.expectedStatus || 200}
217
- `;
218
-
219
- if (scenario.requestBody) {
220
- prompt += ` - Request Body: ${JSON.stringify(scenario.requestBody, null, 2).substring(0, 200)}...
221
- `;
222
- }
223
-
224
- if (scenario.expectedBody) {
225
- prompt += ` - Expected Body Fields: ${Object.keys(scenario.expectedBody).join(', ')}
226
- `;
227
- }
228
-
229
- if (scenario.steps && scenario.steps.length > 0) {
230
- prompt += ` - Multi-step test with ${scenario.steps.length} sequential requests
231
- `;
232
- }
233
- });
234
-
235
- prompt += `
236
- **Instructions:**
237
- 1. Generate a COMPLETE test file including imports and test structure
238
- 2. ${isTypeScript ? 'Use TypeScript with proper types' : 'Use JavaScript'}
239
- 3. Import axios for HTTP requests
240
- 4. Create describe() for the section: "${sectionTitle}"
241
- 5. Create one test() for each scenario above
242
- 6. Use \`const baseUrl = '${baseUrl}';\` at the top
243
- 7. Use axios methods (axios.get, axios.post, etc.)
244
- 8. Construct URLs as template literals: \`\${baseUrl}/endpoint\`
245
- 9. Include proper assertions with Jest's expect()
246
- 10. For multi-step tests, chain requests and pass data between steps
247
- 11. Add error handling where appropriate
248
-
249
- **CRITICAL - Output Restrictions:**
250
- - Generate ONLY this ONE test file
251
- - DO NOT generate README, SUMMARY, GUIDE, or any other files
252
- - DO NOT suggest creating additional files
253
- - Return ONLY the test file code as plain text
254
-
255
- **File structure:**
256
- \`\`\`
257
- // Header comment
258
- import/require statements
259
- describe('${sectionTitle}', () => {
260
- const baseUrl = '${baseUrl}';
261
-
262
- test('scenario 1', async () => {
263
- // test code
264
- });
265
-
266
- test('scenario 2', async () => {
267
- // test code
268
- });
269
- });
270
- \`\`\`
271
-
272
- Return the COMPLETE file content for THIS FILE ONLY.`;
273
-
274
- return prompt;
275
- },
276
-
277
- /**
278
- * Generate main test file
279
- */
280
- generateMainTest: (context) => {
281
- const { testPlanTitle, baseUrl, sections, language, isTypeScript, sessionId } = context;
282
-
283
- let prompt = `Generate a main Jest test file that orchestrates all test sections:
284
-
285
- **Test Plan:** ${testPlanTitle}
286
- **Base URL:** ${baseUrl}
287
- **Language:** ${language}
288
- **Session ID:** ${sessionId}
289
-
290
- **Sections:**
291
- `;
292
-
293
- sections.forEach((section, idx) => {
294
- prompt += `${idx + 1}. ${section.title} (${section.scenarioCount} scenarios)
295
- `;
296
- });
297
-
298
- prompt += `
299
- **Instructions:**
300
- 1. Generate a COMPLETE main test file
301
- 2. ${isTypeScript ? 'Use TypeScript' : 'Use JavaScript'}
302
- 3. Import axios
303
- 4. Create one main describe() for "${testPlanTitle}"
304
- 5. Set \`const baseUrl = '${baseUrl}';\`
305
- 6. Add a comment noting individual sections are in separate files
306
-
307
- **CRITICAL - Output Restrictions:**
308
- - Generate ONLY this ONE main test file
309
- - DO NOT generate README, SUMMARY, GUIDE, or any other files
310
- - Return ONLY the main test file code
311
-
312
- Return the COMPLETE main file content for THIS FILE ONLY.`;
313
-
314
- return prompt;
315
- }
316
- },
317
-
318
- /**
319
- * Legacy scenario-level prompts (kept for backward compatibility)
320
- */
321
- playwrightScenario: {
322
- system: `You are an expert Playwright test engineer for REST and GraphQL APIs. Generate clean, idiomatic, production-ready Playwright API tests.
323
-
324
- Requirements:
325
- - Support both REST and GraphQL API testing
326
- - For REST APIs: Use appropriate HTTP methods (GET, POST, PUT, DELETE, etc.)
327
- - For GraphQL APIs: Always use POST method to /graphql (or specified) endpoint
328
- - For GraphQL APIs: Format request body with 'query' and 'variables' fields
329
- - For GraphQL APIs: Validate response has 'data' (success) or 'errors' (failure)
330
- - Use Playwright's request fixture directly (no wrappers)
331
- - Use proper TypeScript types when language=typescript
332
- - Include proper async/await patterns
333
- - Use template literals for URL construction with \${baseUrl}
334
- - Generate proper assertions with expect()
335
- - Handle both single and chained requests
336
- - Include proper error handling
337
- - Add descriptive comments for complex logic
338
-
339
- Code Style:
340
- - 2-space indentation
341
- - Single quotes for strings (except template literals)
342
- - Semicolons at end of statements
343
- - Clear variable naming
344
- - Proper spacing and formatting`,
345
-
346
- user: (context) => {
347
- const { scenario, baseUrl, language, options } = context;
348
-
349
- let prompt = `Generate a Playwright test for this scenario:
350
-
351
- **Test Details:**
352
- - Title: "${scenario.title}"
353
- - API Type: ${scenario.isGraphQL ? 'GraphQL' : 'REST'}
354
- - Method: ${scenario.method}
355
- - Endpoint: ${scenario.endpoint}
356
- - Base URL: ${baseUrl}
357
- - Language: ${language}
358
-
359
- `;
360
-
361
- // NEW: GraphQL-specific section
362
- if (scenario.isGraphQL && scenario.graphql) {
363
- prompt += `**GraphQL Query:**
364
- \`\`\`graphql
365
- ${scenario.graphql.query}
366
- \`\`\`
367
-
368
- `;
369
- if (scenario.graphql.variables && Object.keys(scenario.graphql.variables).length > 0) {
370
- prompt += `**GraphQL Variables:**
371
- \`\`\`json
372
- ${JSON.stringify(scenario.graphql.variables, null, 2)}
373
- \`\`\`
374
-
375
- `;
376
- }
377
-
378
- prompt += `**GraphQL Request Instructions:**
379
- - Use POST method to endpoint: ${scenario.endpoint || '/graphql'}
380
- - Send request body with this structure:
381
- \`\`\`javascript
382
- {
383
- query: \`<query string>\`,
384
- variables: <variables object>
385
- }
386
- \`\`\`
387
- - Validate GraphQL response structure:
388
- - Success case: expect(responseData).toHaveProperty('data')
389
- - Error case: expect(responseData).toHaveProperty('errors')
390
-
391
- `;
392
- } else {
393
- // EXISTING: REST-specific sections
394
- // Add request details
395
- if (scenario.data && Object.keys(scenario.data).length > 0) {
396
- prompt += `**Request Body:**
397
- \`\`\`json
398
- ${JSON.stringify(scenario.data, null, 2)}
399
- \`\`\`
400
-
401
- `;
402
- }
403
-
404
- if (scenario.headers && Object.keys(scenario.headers).length > 0) {
405
- prompt += `**Headers:**
406
- \`\`\`json
407
- ${JSON.stringify(scenario.headers, null, 2)}
408
- \`\`\`
409
-
410
- `;
411
- }
412
-
413
- if (scenario.query && Object.keys(scenario.query).length > 0) {
414
- prompt += `**Query Parameters:**
415
- \`\`\`json
416
- ${JSON.stringify(scenario.query, null, 2)}
417
- \`\`\`
418
-
419
- `;
420
- }
421
-
422
- if (scenario.pathParams && Object.keys(scenario.pathParams).length > 0) {
423
- prompt += `**Path Parameters:**
424
- \`\`\`json
425
- ${JSON.stringify(scenario.pathParams, null, 2)}
426
- \`\`\`
427
-
428
- `;
429
- }
430
- }
431
-
432
- // Add expectations
433
- if (scenario.expect) {
434
- prompt += `**Expected Response:**
435
- - Status Code: ${scenario.expect.status || 200}
436
- `;
437
- if (scenario.expect.body) {
438
- prompt += `- Response Body Structure:
439
- \`\`\`json
440
- ${JSON.stringify(scenario.expect.body, null, 2)}
441
- \`\`\`
442
- `;
443
- }
444
- }
445
-
446
- // Add chained requests if present
447
- if (scenario.chain && scenario.chain.length > 0) {
448
- prompt += `\n**Chained Requests:**
449
- This is a multi-step test with ${scenario.chain.length} sequential API calls.
450
- `;
451
- scenario.chain.forEach((step, index) => {
452
- prompt += `
453
- Step ${index + 1}: ${step.name}
454
- - Method: ${step.method}
455
- - Endpoint: ${step.endpoint}
456
- `;
457
- if (step.extract) {
458
- prompt += `- Extract: ${JSON.stringify(step.extract)}
459
- `;
460
- }
461
- });
462
- }
463
-
464
- prompt += `
465
- **Instructions:**
466
- 1. Generate ONLY the test body code (the code inside the test() function)
467
- 2. Start at the correct indentation level (6 spaces for test body)
468
- `;
469
-
470
- if (scenario.isGraphQL) {
471
- prompt += `3. Use \`await request.post()\` for GraphQL (always POST)
472
- 4. Construct URL as: \`\${baseUrl}${scenario.endpoint || '/graphql'}\`
473
- 5. Include request body with 'query' and 'variables' fields
474
- 6. Add GraphQL-specific assertions (check for 'data' or 'errors' properties)
475
- `;
476
- } else {
477
- prompt += `3. Use \`await request.${scenario.method.toLowerCase()}()\` for the API call
478
- 4. Construct URL as: \`\${baseUrl}${scenario.endpoint}\`
479
- 5. Include all request options (headers, params, data)
480
- 6. Add proper assertions for status code and response body
481
- `;
482
- }
483
-
484
- prompt += `7. For TypeScript, use proper types
485
- 8. For chained requests, store results and use them in subsequent calls
486
-
487
- DO NOT include:
488
- - test.describe() wrapper
489
- - test() function declaration
490
- - import statements
491
- - Extra blank lines at start/end
492
-
493
- Return ONLY the test body code, properly indented.`;
494
-
495
- return prompt;
496
- }
497
- },
498
-
499
- /**
500
- * Generate a complete Jest test for a single scenario
501
- */
502
- jestScenario: {
503
- system: `You are an expert Jest test engineer for REST and GraphQL APIs. Generate clean, idiomatic, production-ready Jest API tests using axios.
504
-
505
- Requirements:
506
- - Support both REST and GraphQL API testing
507
- - For REST APIs: Use appropriate HTTP methods (GET, POST, PUT, DELETE, etc.)
508
- - For GraphQL APIs: Always use POST method to /graphql (or specified) endpoint
509
- - For GraphQL APIs: Format request body with 'query' and 'variables' fields
510
- - For GraphQL APIs: Validate response has 'data' (success) or 'errors' (failure)
511
- - Use axios for API calls
512
- - Use proper TypeScript types when language=typescript
513
- - Include proper async/await patterns
514
- - Generate proper assertions with expect()
515
- - Handle both single and chained requests
516
- - Include proper error handling
517
- - Add descriptive comments for complex logic
518
-
519
- Code Style:
520
- - 2-space indentation
521
- - Single quotes for strings
522
- - Semicolons at end of statements
523
- - Clear variable naming
524
- - Proper spacing and formatting`,
525
-
526
- user: (context) => {
527
- const { scenario, baseUrl, language, options } = context;
528
-
529
- let prompt = `Generate a Jest/axios test for this scenario:
530
-
531
- **Test Details:**
532
- - Title: "${scenario.title}"
533
- - API Type: ${scenario.isGraphQL ? 'GraphQL' : 'REST'}
534
- - Method: ${scenario.method}
535
- - Endpoint: ${scenario.endpoint}
536
- - Base URL: ${baseUrl}
537
- - Language: ${language}
538
-
539
- `;
540
-
541
- // NEW: GraphQL-specific section
542
- if (scenario.isGraphQL && scenario.graphql) {
543
- prompt += `**GraphQL Query:**
544
- \`\`\`graphql
545
- ${scenario.graphql.query}
546
- \`\`\`
547
-
548
- `;
549
- if (scenario.graphql.variables && Object.keys(scenario.graphql.variables).length > 0) {
550
- prompt += `**GraphQL Variables:**
551
- \`\`\`json
552
- ${JSON.stringify(scenario.graphql.variables, null, 2)}
553
- \`\`\`
554
-
555
- `;
556
- }
557
-
558
- prompt += `**GraphQL Request Instructions:**
559
- - Use POST method to endpoint: ${scenario.endpoint || '/graphql'}
560
- - Send request body with this structure:
561
- \`\`\`javascript
562
- {
563
- query: \`<query string>\`,
564
- variables: <variables object>
565
- }
566
- \`\`\`
567
- - Validate GraphQL response structure:
568
- - Success case: expect(response.data).toHaveProperty('data')
569
- - Error case: expect(response.data).toHaveProperty('errors')
570
-
571
- `;
572
- } else {
573
- // EXISTING: REST-specific sections
574
- // Add request details (similar to Playwright)
575
- if (scenario.data && Object.keys(scenario.data).length > 0) {
576
- prompt += `**Request Body:**
577
- \`\`\`json
578
- ${JSON.stringify(scenario.data, null, 2)}
579
- \`\`\`
580
-
581
- `;
582
- }
583
-
584
- if (scenario.headers && Object.keys(scenario.headers).length > 0) {
585
- prompt += `**Headers:**
586
- \`\`\`json
587
- ${JSON.stringify(scenario.headers, null, 2)}
588
- \`\`\`
589
-
590
- `;
591
- }
592
-
593
- if (scenario.query && Object.keys(scenario.query).length > 0) {
594
- prompt += `**Query Parameters:**
595
- \`\`\`json
596
- ${JSON.stringify(scenario.query, null, 2)}
597
- \`\`\`
598
-
599
- `;
600
- }
601
- }
602
-
603
- // Add expectations
604
- if (scenario.expect) {
605
- prompt += `**Expected Response:**
606
- - Status Code: ${scenario.expect.status || 200}
607
- `;
608
- if (scenario.expect.body) {
609
- prompt += `- Response Body Structure:
610
- \`\`\`json
611
- ${JSON.stringify(scenario.expect.body, null, 2)}
612
- \`\`\`
613
- `;
614
- }
615
- }
616
-
617
- prompt += `
618
- **Instructions:**
619
- 1. Generate ONLY the test body code (the code inside the test() function)
620
- 2. Start at the correct indentation level (6 spaces for test body)
621
- `;
622
-
623
- if (scenario.isGraphQL) {
624
- prompt += `3. Use \`await apiUtils.makeRequest()\` with method: 'POST'
625
- 4. Set URL to: '${scenario.endpoint || '/graphql'}'
626
- 5. Include request data with 'query' and 'variables' fields
627
- 6. Add GraphQL-specific assertions (check for 'data' or 'errors' properties in response.data)
628
- `;
629
- } else {
630
- prompt += `3. Use \`await apiUtils.makeRequest()\` helper for API calls
631
- 4. Include all request options (method, url, headers, params, data)
632
- 5. Add proper assertions for status code and response body
633
- `;
634
- }
635
-
636
- prompt += `6. For TypeScript, use proper types
637
- 7. Handle errors appropriately
638
-
639
- DO NOT include:
640
- - describe() wrapper
641
- - test() function declaration
642
- - import statements
643
- - Extra blank lines at start/end
644
-
645
- Return ONLY the test body code, properly indented.`;
646
-
647
- return prompt;
648
- }
649
- },
650
-
651
- /**
652
- * Generate Postman test scripts
653
- */
654
- postmanTestScript: {
655
- system: `You are a Postman automation expert. Generate clear, effective Postman test scripts.
656
-
657
- Requirements:
658
- - Use pm.test() for assertions
659
- - Use pm.response for response validation
660
- - Use pm.expect() for assertions
661
- - Include proper error messages
662
- - Add descriptive test names`,
663
-
664
- user: (context) => {
665
- const { expect, extract } = context;
666
-
667
- let prompt = `Generate Postman test script for this validation:
668
-
669
- `;
670
-
671
- if (expect && expect.status) {
672
- prompt += `**Expected Status:** ${expect.status}
673
- `;
674
- }
675
-
676
- if (expect && expect.body) {
677
- prompt += `**Expected Response Body:**
678
- \`\`\`json
679
- ${JSON.stringify(expect.body, null, 2)}
680
- \`\`\`
681
- `;
682
- }
683
-
684
- if (extract) {
685
- prompt += `**Extract Variables:**
686
- ${Object.entries(extract).map(([key, field]) => `- ${key} from ${field}`).join('\n')}
687
- `;
688
- }
689
-
690
- prompt += `
691
- **Instructions:**
692
- 1. Generate test script as array of strings
693
- 2. Each line should be a separate array element
694
- 3. Include status code validation
695
- 4. Include response body validation
696
- 5. Extract and store variables if specified
697
-
698
- Return JavaScript array of test script lines.`;
699
-
700
- return prompt;
701
- }
702
- }
703
- };