mock
Mock the response of a request. You can define a mock based on a matching glob and corresponding header and status code. Calling the mock method returns a stub object that you can use to modify the response of the web resource.
With the stub object you can then either return a custom response or have the request fail.
There are 3 ways to modify the response:
- return a custom JSON object (for stubbing API request)
- replace web resource with a local file (service a modified JavaScript file) or
- redirect resource to a different url
info
Note that using the mock
command requires support for Chrome DevTools protocol and e.g.
can not be used when running automated tests in the cloud. Find out more in the
Automation Protocols section.
#
Usage#
ParametersName | Type | Details |
---|---|---|
url | String | url to mock |
filterOptions optional | MockFilterOptions | filter mock resource by additional options |
filterOptions.method optional | String , Function | filter resource by HTTP method |
filterOptions.headers optional | Object , Function | filter resource by specific request headers |
filterOptions.responseHeaders optional | Object , Function | filter resource by specific response headers |
filterOptions.postData optional | String , Function | filter resource by request postData |
filterOptions.statusCode optional | Number , Function | filter resource by response statusCode |
#
Examplemock.js