.network.mockResponse() Suggest edits
Since: 2.2.0Intercept the request made on a particular URL and mock the response.
Usage
.mockNetworkResponse(urlToIntercept, {status, headers, body}, [callback])
.network.mockResponse(urlToIntercept, {status, headers, body}, [callback])
Example
describe('mock network response', function() {
it('intercepts the request made to Google search and mocks its response', function() {
browser
.network.mockResponse('https://www.google.com/', {
status: 200,
headers: {
'Content-Type': 'UTF-8'
},
body: 'Hello there!'
})
.navigateTo('https://www.google.com/')
.pause(2000);
});
});
Parameters
Name | Type | description |
---|---|---|
urlToIntercept |
string | URL to intercept and mock the response from. |
response |
object | Response to return. Defaults: |
callback Optional |
function | Callback function to be called when the command finishes. |