/** * QA360 Network Simulator * * P0 Features: Network simulation for testing edge cases * - Offline mode: Simulate network disconnection * - HTTP errors: Simulate server errors (500, 503, 404, etc.) * - Latency: Simulate slow networks * - Throttling: Simulate bandwidth limitations * * Uses Playwright's page.route() for request interception */ import type { Page } from '@playwright/test'; /** * HTTP error configuration */ export interface HTTPErrorConfig { /** * HTTP status code to simulate * Common values: 404, 500, 502, 503, 504 */ status: number; /** * Optional custom status text */ statusText?: string; /** * Optional response body */ body?: string; /** * URL pattern to apply error to (regex or string) * If not specified, applies to all requests */ urlPattern?: string | RegExp; /** * HTTP methods to apply error to * If not specified, applies to all methods */ methods?: string[]; } /** * Network simulation options */ export interface NetworkSimulationOptions { /** * Simulate offline mode (no network connection) */ offline?: boolean; /** * Simulate HTTP errors */ httpErrors?: HTTPErrorConfig[]; /** * Simulate latency (delay in ms) */ latency?: number; /** * Simulate throttling (max bytes per second) */ throttling?: { downloadKbps?: number; uploadKbps?: number; latency?: number; }; } /** * Network Simulator class */ export declare class NetworkSimulator { private page; private activeRoutes; private isOffline; constructor(page: Page); /** * Apply network simulation settings */ simulate(options: NetworkSimulationOptions): Promise; /** * Set offline mode * P0: Simulate network disconnection */ setOffline(offline: boolean): Promise; /** * Add HTTP error simulation * P0: Simulate server errors (500, 503, 404, etc.) */ addHTTPError(config: HTTPErrorConfig): Promise; /** * Set latency for all requests */ setLatency(delayMs: number): Promise; /** * Set network throttling * Uses Chrome DevTools Protocol for accurate throttling */ setThrottling(config: { downloadKbps?: number; uploadKbps?: number; latency?: number; }): Promise; /** * Clear all network simulations */ clear(): Promise; /** * Get default status text for HTTP status codes */ private getDefaultStatusText; } /** * Predefined network profiles */ export declare const NetworkProfiles: { /** * Offline mode - no network connection */ offline: () => NetworkSimulationOptions; /** * Slow 3G network */ slow3G: () => NetworkSimulationOptions; /** * Fast 3G network */ fast3G: () => NetworkSimulationOptions; /** * Server error simulation (500) */ serverError: (urlPattern?: string | RegExp) => NetworkSimulationOptions; /** * Service unavailable simulation (503) */ serviceUnavailable: (urlPattern?: string | RegExp) => NetworkSimulationOptions; /** * Not found simulation (404) */ notFound: (urlPattern?: string | RegExp) => NetworkSimulationOptions; /** * Multiple server errors for testing resilience */ flakyServer: (urlPattern?: string | RegExp) => NetworkSimulationOptions; }; /** * Convenience function to create a network simulator */ export declare function createNetworkSimulator(page: Page): NetworkSimulator; /** * Convenience function to simulate network conditions */ export declare function simulateNetwork(page: Page, options: NetworkSimulationOptions): Promise; /** * Convenience function to set offline mode */ export declare function setOffline(page: Page, offline: boolean): Promise; /** * Convenience function to simulate HTTP error */ export declare function simulateHTTPError(page: Page, config: HTTPErrorConfig): Promise;