Skip to main content

The Mock Object

The mock object is an object that represents a network mock and contains information about requests that were matching given url and filterOptions. It can be received using the mock command.


Note that using the mock command requires support for Chrome DevTools protocol. That support is given if you run tests locally in Chromium based browser or if you use a Selenium Grid v4 or higher. This command can not be used when running automated tests in the cloud. Find out more in the Automation Protocols section.

You can read more about mocking requests and responses in WebdriverIO in our Mocks and Spies guide.


A mock object contains the following properties:

urlStringThe url passed into the mock command
filterOptionsObjectThe resource filter options passed into the mock command
browserObjectThe Browser Object used to get the mock object.
matchesObject[]Information about matching browser requests, containing properties such as url, method, headers, initialPriority, referrerPolic, statusCode, responseHeaders and body


Mock objects provide various commands, listed in the mock section, that allow users to modify the behavior of the request or response.