Intercept the request made on a particular URL and mock the response.

network.mockResponse() is only available when using Chrome or Edge drivers.

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: {status: 200, headers: {}, body: ''}.

callback
Optional
function

Callback function to be called when the command finishes.