#!/usr/bin/env node /** * Comprehensive test script for the new request monitoring system * Tests all the new tools and their integration */ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); async function testRequestMonitoring() { console.log('๐ต๏ธ Testing Request Monitoring System'); console.log('====================================='); // Create a test HTML page with various types of requests const testHtml = `
This page generates various HTTP requests for testing the monitoring system.
`; const testFile = path.join(__dirname, 'test-request-monitoring.html'); fs.writeFileSync(testFile, testHtml); console.log('โ Created comprehensive test page'); console.log(`๐ Test page: file://${testFile}`); console.log(''); console.log('๐งช Manual Testing Instructions:'); console.log('================================'); console.log(''); console.log('1. **Start MCP Server:**'); console.log(' npm run build && node lib/index.js'); console.log(''); console.log('2. **Start Request Monitoring:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_start_request_monitoring",'); console.log(' "parameters": {'); console.log(' "captureBody": true,'); console.log(' "maxBodySize": 1048576,'); console.log(' "autoSave": false'); console.log(' }'); console.log(' }'); console.log(' ```'); console.log(''); console.log('3. **Navigate to Test Page:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_navigate",'); console.log(` "parameters": { "url": "file://${testFile}" }`); console.log(' }'); console.log(' ```'); console.log(''); console.log('4. **Interact with Page:**'); console.log(' - Click "Generate Test Requests" button'); console.log(' - Click "Generate Failed Requests" button'); console.log(' - Click "Generate Slow Requests" button'); console.log(' - Wait for requests to complete'); console.log(''); console.log('5. **Test Analysis Tools:**'); console.log(''); console.log(' **Check Status:**'); console.log(' ```json'); console.log(' { "tool": "browser_request_monitoring_status" }'); console.log(' ```'); console.log(''); console.log(' **Get All Requests:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_get_requests",'); console.log(' "parameters": { "format": "detailed", "limit": 50 }'); console.log(' }'); console.log(' ```'); console.log(''); console.log(' **Get Failed Requests:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_get_requests",'); console.log(' "parameters": { "filter": "failed", "format": "detailed" }'); console.log(' }'); console.log(' ```'); console.log(''); console.log(' **Get Slow Requests:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_get_requests",'); console.log(' "parameters": { "filter": "slow", "slowThreshold": 1500 }'); console.log(' }'); console.log(' ```'); console.log(''); console.log(' **Get Statistics:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_get_requests",'); console.log(' "parameters": { "format": "stats" }'); console.log(' }'); console.log(' ```'); console.log(''); console.log('6. **Test Export Features:**'); console.log(''); console.log(' **Export to JSON:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_export_requests",'); console.log(' "parameters": { "format": "json", "includeBody": true }'); console.log(' }'); console.log(' ```'); console.log(''); console.log(' **Export to HAR:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_export_requests",'); console.log(' "parameters": { "format": "har" }'); console.log(' }'); console.log(' ```'); console.log(''); console.log(' **Export Summary Report:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_export_requests",'); console.log(' "parameters": { "format": "summary" }'); console.log(' }'); console.log(' ```'); console.log(''); console.log('7. **Test Enhanced Network Tool:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_network_requests",'); console.log(' "parameters": { "detailed": true }'); console.log(' }'); console.log(' ```'); console.log(''); console.log('8. **Test Filtering:**'); console.log(' ```json'); console.log(' {'); console.log(' "tool": "browser_get_requests",'); console.log(' "parameters": { "domain": "jsonplaceholder.typicode.com" }'); console.log(' }'); console.log(' ```'); console.log(''); console.log('9. **Check File Paths:**'); console.log(' ```json'); console.log(' { "tool": "browser_get_artifact_paths" }'); console.log(' ```'); console.log(''); console.log('10. **Clean Up:**'); console.log(' ```json'); console.log(' { "tool": "browser_clear_requests" }'); console.log(' ```'); console.log(''); console.log('๐ฏ Expected Results:'); console.log('==================='); console.log(''); console.log('โ **Should work:**'); console.log('- Request monitoring captures all HTTP traffic'); console.log('- Different request types are properly categorized'); console.log('- Failed requests are identified and logged'); console.log('- Slow requests are flagged with timing info'); console.log('- Request/response bodies are captured when enabled'); console.log('- Export formats (JSON, HAR, CSV, Summary) work correctly'); console.log('- Statistics show accurate counts and averages'); console.log('- Filtering by domain, method, status works'); console.log('- Enhanced network tool shows rich data'); console.log(''); console.log('๐ **Key Metrics to Verify:**'); console.log('- Total requests > 10 (from page interactions)'); console.log('- Some requests > 1000ms (slow requests)'); console.log('- Some 4xx/5xx status codes (failed requests)'); console.log('- JSON response bodies properly parsed'); console.log('- Request headers include User-Agent, etc.'); console.log('- Response headers include Content-Type'); console.log(''); console.log('๐ **Security Testing Use Case:**'); console.log('This system now enables:'); console.log('- Complete API traffic analysis'); console.log('- Authentication token capture'); console.log('- CORS and security header analysis'); console.log('- Performance bottleneck identification'); console.log('- Failed request debugging'); console.log('- Export to security tools (HAR format)'); return testFile; } testRequestMonitoring().catch(console.error);