Skip to content

Lupa API Reference / commands / Emulation

Class: Emulation ​

Defined in: src/commands/emulation.ts:45

Class to emulate different environment features like viewport size, media, geolocation, permissions, and offline mode.

Use ​

when

  • Overriding device settings dynamically during a test (e.g. testing responsive layout breakpoint transitions, dark mode switching, geolocation updates, or offline network behaviors).

Dont ​

use when

  • Setting static configuration options that are best configured via the main Lupa config file.

Constructors ​

Constructor ​

new Emulation(): Emulation

Returns ​

Emulation

Methods ​

clearPermissions() ​

clearPermissions(): Promise<void>

Defined in: src/commands/emulation.ts:112

Clears all permissions granted dynamically.

Returns ​

Promise<void>

Example ​

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

await emulation.clearPermissions()

emulateMedia() ​

emulateMedia(media): Promise<void>

Defined in: src/commands/emulation.ts:70

Emulates media features.

Parameters ​

media ​

Media

Returns ​

Promise<void>

Example ​

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

await emulation.emulateMedia({ colorScheme: 'dark' })

grantPermissions() ​

grantPermissions(permissions, options?): Promise<void>

Defined in: src/commands/emulation.ts:98

Grants permissions to the browser context dynamically.

Parameters ​

permissions ​

string[]

options? ​

GrantPermissionsOptions

Returns ​

Promise<void>

Example ​

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

await emulation.grantPermissions(['geolocation'])

setGeolocation() ​

setGeolocation(geolocation?): Promise<void>

Defined in: src/commands/emulation.ts:84

Sets the geolocation for the browser context dynamically.

Parameters ​

geolocation? ​

Geolocation

Returns ​

Promise<void>

Example ​

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

await emulation.setGeolocation({ latitude: 48.8584, longitude: 2.2944 })

setOffline() ​

setOffline(offline): Promise<void>

Defined in: src/commands/emulation.ts:131

Toggles the offline state of the browser context.

IMPORTANT

Persistence Notice: Unlike network.setOffline(...), this method changes the global context state. The context will remain offline until it is explicitly set back to online (i.e. it does not automatically revert at the end of the test).

Parameters ​

offline ​

boolean

Returns ​

Promise<void>

Example ​

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

await emulation.setOffline(true)

setViewport() ​

setViewport(viewport): Promise<void>

Defined in: src/commands/emulation.ts:56

Changes the size of the viewport.

Parameters ​

viewport ​

Viewport

Returns ​

Promise<void>

Example ​

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

await emulation.setViewport({ width: 375, height: 667 })