/** * QA360 Network Manager * * P0 Features: Advanced network control for testing * - Block routes: Prevent specific requests from completing * - Mock routes: Return custom responses for specific requests * - Wait for request: Wait until a specific request is made * - Wait for response: Wait until a specific response is received * * Uses Playwright's page.route(), page.waitForRequest(), page.waitForResponse() */ import type { Page, Request, Response } from '@playwright/test'; /** * Route blocking configuration */ export interface BlockRouteConfig { /** * URL pattern to block (regex, string, or function) */ urlPattern: string | RegExp | ((url: string) => boolean); /** * Optional HTTP methods to block * If not specified, blocks all methods */ methods?: string[]; } /** * Route mocking configuration */ export interface MockRouteConfig { /** * URL pattern to mock (regex, string, or function) */ urlPattern: string | RegExp | ((url: string) => boolean); /** * HTTP status to return */ status: number; /** * Response headers */ headers?: Record; /** * Response body (string or JSON) */ body?: string | Record; /** * Content type */ contentType?: string; /** * Optional HTTP methods to mock */ methods?: string[]; } /** * Wait for request configuration */ export interface WaitForRequestOptions { /** * URL pattern to wait for */ urlPattern?: string | RegExp | ((url: string) => boolean); /** * HTTP method to wait for */ method?: string; /** * Timeout in milliseconds */ timeout?: number; } /** * Wait for response configuration */ export interface WaitForResponseOptions { /** * URL pattern to wait for */ urlPattern?: string | RegExp | ((url: string) => boolean); /** * HTTP status to wait for */ status?: number; /** * Timeout in milliseconds */ timeout?: number; } /** * Network Manager class * Provides advanced network control capabilities */ export declare class NetworkManager { private page; private blockedRoutes; private mockedRoutes; constructor(page: Page); /** * Block routes matching the given pattern * P0: Block specific requests (analytics, trackers, etc.) */ blockRoute(config: BlockRouteConfig): Promise; /** * Mock routes with custom responses * P0: Return fake responses for testing */ mockRoute(config: MockRouteConfig): Promise; /** * Wait for a request matching the given pattern * P0: Wait for specific API calls */ waitForRequest(options?: WaitForRequestOptions): Promise; /** * Wait for a response matching the given pattern * P0: Wait for specific API responses */ waitForResponse(options?: WaitForResponseOptions): Promise; /** * Unblock all blocked routes */ unblockRoutes(): Promise; /** * Unmock all mocked routes */ unmockRoutes(): Promise; /** * Get all blocked routes */ getBlockedRoutes(): BlockRouteConfig[]; /** * Get all mocked routes */ getMockedRoutes(): MockRouteConfig[]; /** * Check if a URL matches a pattern */ private matchPattern; /** * Get content type based on body */ private getContentType; } /** * Convenience function to create a network manager */ export declare function createNetworkManager(page: Page): NetworkManager; /** * Predefined common blocking patterns */ export declare const BlockPatterns: { /** * Block Google Analytics */ googleAnalytics: string; /** * Block Google Tag Manager */ googleTagManager: string; /** * Block Facebook Pixel */ facebookPixel: string; /** * Block DoubleClick */ doubleClick: string; /** * Block all analytics */ allAnalytics: string[]; /** * Block images */ images: string; /** * Block fonts */ fonts: string; /** * Block CSS */ css: string; /** * Block JavaScript */ javascript: string; }; /** * Predefined common mock responses */ export declare const MockResponses: { /** * Mock successful API response */ successResponse: (data?: Record) => MockRouteConfig; /** * Mock error API response */ errorResponse: (message?: string) => MockRouteConfig; /** * Mock empty list response */ emptyList: () => MockRouteConfig; /** * Mock 404 Not Found */ notFound: () => MockRouteConfig; /** * Mock 401 Unauthorized */ unauthorized: () => MockRouteConfig; /** * Mock slow response (with latency) * Note: This doesn't add actual delay, use NetworkSimulator for that */ slowResponse: (data?: Record) => MockRouteConfig; }; /** * Convenience functions for common operations */ /** * Block all analytics and tracking scripts */ export declare function blockAnalytics(page: Page): Promise; /** * Mock all API responses */ export declare function mockAllAPI(page: Page, response: MockRouteConfig): Promise; /** * Wait for API request */ export declare function waitForAPIRequest(page: Page, urlPattern: string | RegExp, timeout?: number): Promise; /** * Wait for API response */ export declare function waitForAPIResponse(page: Page, urlPattern: string | RegExp, timeout?: number): Promise;