/** * QA360 Playwright Native API Adapter * * Uses Playwright's native APIRequestContext for HTTP testing. * No browser launch required - lighter and faster than browser-based approach. * * @see https://playwright.dev/docs/api/class-apirequestcontext * * Benefits over browser-based approach: * - No browser overhead (faster startup, lower memory) * - Direct HTTP requests * - Same API testing capabilities * - Better for CI/CD environments */ import { ApiTarget, PackBudgets } from '../types/pack-v1.js'; import { AuthCredentials } from '../auth/index.js'; export interface NativeApiTestConfig { target: ApiTarget; budgets?: PackBudgets; timeout?: number; retries?: number; auth?: AuthCredentials; /** * Basic auth credentials (username/password) */ basicAuth?: { username: string; password: string; }; /** * Request body for POST/PUT/PATCH */ body?: Record | string; /** * Storage state to persist cookies/auth between requests */ storageState?: Record | string; /** * Cache configuration for HTTP responses */ cache?: { /** Enable caching (default: false) */ enabled?: boolean; /** TTL in milliseconds (default: 300000 = 5 minutes) */ ttl?: number; /** Maximum cache size in bytes (default: 10MB) */ maxSizeBytes?: number; /** Maximum number of entries (default: 100) */ maxSize?: number; }; } export interface ApiTestResult { endpoint: string; method: string; status: number; responseTime: number; success: boolean; error?: string; headers?: Record; body?: any; attempts?: number; } export interface NativeApiSmokeResult { success: boolean; results: ApiTestResult[]; summary: { total: number; passed: number; failed: number; avgResponseTime: number; totalAttempts: number; }; junit?: string; error?: string; } /** * Playwright Native API Adapter * * Uses playwright.request.newContext() for direct HTTP requests * without launching a browser. */ export declare class PlaywrightNativeApiAdapter { private requestContext?; private redactor; private auth?; private cache?; constructor(); /** * Set authentication credentials for requests */ setAuth(credentials?: AuthCredentials): void; /** * Execute API smoke tests using Playwright's native API */ runSmokeTests(config: NativeApiTestConfig): Promise; /** * Setup Playwright APIRequestContext for HTTP requests */ private setupRequestContext; /** * Execute single API test with retry logic using native API */ private executeApiTest; /** * Parse test specification string * Format: "GET /path -> 200" or "POST /api/users -> 201" * * Handles AI-generated YAML with quotes: '"GET /path -> 200"' -> 'GET /path -> 200' */ private parseTestSpec; /** * Check if error is retryable */ private isRetryableError; /** * Calculate test summary */ private calculateSummary; /** * Generate JUnit XML fragment */ private generateJUnit; /** * Escape XML special characters */ private escapeXml; /** * Cleanup request context */ private cleanup; /** * Validate API target configuration */ static validateConfig(target: ApiTarget): { valid: boolean; errors: string[]; }; /** * Health check using native API * Quick check if the API is accessible without running full tests */ healthCheck(baseUrl: string, path?: string, timeout?: number): Promise; /** * Get API info (useful for debugging) * Returns version and capabilities */ static getCapabilities(): { adapter: string; browserless: boolean; features: string[]; }; /** * Get cache statistics if cache is enabled */ getCacheStats(): { enabled: boolean; stats?: { hits: number; misses: number; additions: number; evictions: number; size: number; sizeBytes: number; hitRate: number; avgEntrySize: number; }; }; /** * Clear the cache if enabled */ clearCache(): void; } /** * Factory function to create a native API adapter */ export declare function createPlaywrightNativeApiAdapter(): PlaywrightNativeApiAdapter; /** * Error class for native API adapter */ export declare class PlaywrightNativeApiError extends Error { code: string; endpoint?: string; method?: string; constructor(message: string, endpoint?: string, method?: string); }