Capture outgoing network calls from the browser.

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

Usage

.captureNetworkRequests(onRequestCallback)

Parameters

Name Type description
onRequestCallback function

Callback function called whenever a new outgoing network request is made.

Example

 describe('capture network requests', function() {
   it('captures and logs network requests as they occur', function(this: ExtendDescribeThis<{requestCount: number}>) {
     this.requestCount = 1;
     browser
       .captureNetworkRequests((requestParams) => {
         console.log('Request Number:', this.requestCount!++);
         console.log('Request URL:', requestParams.request.url);
         console.log('Request method:', requestParams.request.method);
         console.log('Request headers:', requestParams.request.headers);
       })
       .navigateTo('https://www.google.com');
   });
 });

Recommended content