import { Page } from '@playwright/test'; /** * Options accepted by the session-aware request family. A pass-through subset of * Playwright's `APIRequestContext` request options — see the Playwright docs for * the exact semantics of each field. */ export interface BrowserRequestOptions { /** Maximum number of redirects to follow. `0` disables following — useful for asserting a 30x `location` header. */ maxRedirects?: number; /** Extra request headers. */ headers?: Record; /** Query parameters appended to the URL. */ params?: Record; /** Raw request body (string, Buffer, or a JSON-serialisable object — Playwright sets `content-type` accordingly). */ data?: string | Buffer | object; /** `application/x-www-form-urlencoded` form body. */ form?: Record; /** * Whether Playwright throws on a non-2xx/3xx response. Defaults to `false` * here (the package default) so status assertions can run against 4xx/5xx * responses instead of throwing before the assertion. */ failOnStatusCode?: boolean; /** Per-request timeout in ms (0 = no timeout). Defaults to Playwright's request timeout. */ timeout?: number; } /** * A typed, framework-owned wrapper over Playwright's `APIResponse`. Exposes the * status line, headers, and the lazy body accessors (`json` / `text` / `body`) * without leaking the raw Playwright type into user test files. */ export interface BrowserResponse { /** HTTP status code (e.g. `200`, `404`). */ readonly status: number; /** `true` when the status is in the 2xx range. */ readonly ok: boolean; /** The final request URL (after any followed redirects). */ readonly url: string; /** Response headers, lower-cased keys (Playwright's `headers()` contract). */ readonly headers: Record; /** HTTP status text (e.g. `OK`, `Not Found`). */ readonly statusText: string; /** Parse the body as JSON. */ json(): Promise; /** Read the body as text. */ text(): Promise; /** Read the body as a Buffer. */ body(): Promise; } /** * Session-aware HTTP request family, backed by Playwright's `page.request` * (`APIRequestContext`). Unlike the wasapi `api*` external-service client, these * requests SHARE the browser context's cookies/session — making them the right * tool for authenticated redirect / protected-route contract checks (e.g. * "hitting `/account` while logged out 30x-redirects to `/login`"). * * Every verb returns a typed {@link BrowserResponse}. `failOnStatusCode` * defaults to `false` so status assertions work on 4xx/5xx responses. */ export declare class BrowserRequest { private page; constructor(page: Page); private toPlaywrightOptions; /** Session-aware `GET`. */ get(url: string, opts?: BrowserRequestOptions): Promise; /** Session-aware `POST`. */ post(url: string, opts?: BrowserRequestOptions): Promise; /** Session-aware `PUT`. */ put(url: string, opts?: BrowserRequestOptions): Promise; /** Session-aware `PATCH`. */ patch(url: string, opts?: BrowserRequestOptions): Promise; /** Session-aware `DELETE`. */ delete(url: string, opts?: BrowserRequestOptions): Promise; /** Session-aware `HEAD`. */ head(url: string, opts?: BrowserRequestOptions): Promise; }