Skip to main content

emulate

WebdriverIO allows you to emulate Web APIs using the emulate command. These Web APIs can then behave exactly as you specify it. The following scopes are supported:

  • geolocation: Emulate the geolocation API
  • userAgent: Emulate the user agent
  • colorScheme: Emulate the color scheme
  • onLine: Emulate the online status
  • device: Emulate a specific mobile or desktop device
  • clock: Emulate the system clock

The emulate command returns a function that can be called to reset the emulation. This is useful when you want to reset the emulation after a test or a suite of tests.

Read more on this in the Emulation guidelines.

info

Except for the clock scope it is not possible to change the emulated value without reloading the page.

info

This feature requires WebDriver Bidi support for the browser. While recent versions of Chrome, Edge and Firefox have such support, Safari does not. For updates follow wpt.fyi. Furthermore if you use a cloud vendor for spawning browsers, make sure your vendor also supports WebDriver Bidi.

The EmulationOptions object can have the following properties based on the scope:

ScopeOptions
geolocation{ latitude: number, longitude: number }
userAgentstring
colorScheme'light' | 'dark'
onLineboolean
clockFakeTimerInstallOpts
Usage
browser.emulate(scope, options)
Parameters
NameTypeDetails
scopestringfeature of the browser you like to emulate, can be either clock, geolocation, userAgent, colorScheme or onLine
optionsEmulationOptionsemulation option for specific scope
Examples
example.js
loading...
example.js
loading...

Welcome! How can I help?

WebdriverIO AI Copilot