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 APIuserAgent
: Emulate the user agentcolorScheme
: Emulate the color schemeonLine
: Emulate the online statusdevice
: Emulate a specific mobile or desktop deviceclock
: 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.
Except for the clock
scope it is not possible to change the emulated value without reloading the page.
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:
Scope | Options |
---|---|
geolocation | { latitude: number, longitude: number } |
userAgent | string |
colorScheme | 'light' | 'dark' |
onLine | boolean |
clock | FakeTimerInstallOpts |
Usage
browser.emulate(scope, options)
Parameters
Name | Type | Details |
---|---|---|
scope | string | feature of the browser you like to emulate, can be either clock , geolocation , userAgent , colorScheme or onLine |
options | EmulationOptions | emulation option for specific scope |
Examples
loading...
loading...