Skip to content

Lupa API Reference / commands / Cookies

Class: Cookies ​

Defined in: src/commands/cookies.ts:16

Class to manipulate browser context cookies.

Use ​

when

  • Authenticating your tests by injecting session cookies dynamically. (e.g., bypass login flows by adding a predefined authentication cookie).
  • Verifying cookie behavior under different scenarios (e.g., verifying that a cookie gets correctly cleared or set by client-side operations).

Dont ​

use when

  • Mocking HTTP requests or response headers; use the network fixture instead.

Constructors ​

Constructor ​

new Cookies(): Cookies

Returns ​

Cookies

Methods ​

add() ​

add(cookies): Promise<void>

Defined in: src/commands/cookies.ts:32

Adds cookies to the browser context.

Parameters ​

cookies ​

Cookie | Cookie[]

Returns ​

Promise<void>

Example ​

typescript
import { cookies } from '@pawel-up/lupa/commands'

await cookies.add({
  name: 'session_id',
  value: 'abc123xyz',
  domain: 'localhost',
  path: '/'
})

clear() ​

clear(options?): Promise<void>

Defined in: src/commands/cookies.ts:67

Clears cookies matching the options. If no options are specified, clears all cookies.

Parameters ​

options? ​

ClearCookiesOptions

Returns ​

Promise<void>

Example ​

typescript
import { cookies } from '@pawel-up/lupa/commands'

// Clear all cookies
await cookies.clear()

// Clear a specific cookie by name
await cookies.clear({ name: 'session_id' })

getAll() ​

getAll(urls?): Promise<Cookie[]>

Defined in: src/commands/cookies.ts:48

Gets all cookies from the browser context. Optionally filters by URLs.

Parameters ​

urls? ​

string | string[]

Returns ​

Promise<Cookie[]>

Example ​

typescript
import { cookies } from '@pawel-up/lupa/commands'

const allCookies = await cookies.getAll()
const siteCookies = await cookies.getAll('https://example.com')