Skip to content

CDP Network Domain

aqualityAutomation edited this page Apr 9, 2023 · 6 revisions

The CDP Network domain allows tracking the network activity of a page. It provides information about different HTTP requests/responses, their headers, body, etc. The NetworkHandling class of the Aquality Selenium framework is largely based on the methods of the mentioned domain. This class also implements various listeners and interceptors which allow intercepting and modifying request (HttpRequest) and response (HttpResponse) objects. Examples of using methods of NetworkHandling class can be found in NetworkHandlingTests, ) tests.

Thу BrowserNetworkExtensions

Class defines a set of extension methods for the Browser class that help to register authentication handlers, enable HTTP request/response logging, and start network monitoring. Let's take a closer look at each method:

RegisterBasicAuthenticationAndStartMonitoring: This method registers a basic authentication handler and starts network monitoring. It takes in the Browser instance, a hostPart string that is used to match the URI of the request, and the username and password for authentication. It creates a new NetworkAuthenticationHandler with the UriMatcher set to match the host name that contains the specified hostPart, and sets the credentials using the specified username and password. Then it calls the RegisterBasicAuthenticationAndStartMonitoring method with the Browser instance and the created authentication handler.

RegisterBasicAuthenticationAndStartMonitoring: This method registers an authentication handler and starts network monitoring. It takes in the Browser instance and the NetworkAuthenticationHandler instance that contains the authentication parameters such as URI matcher and credentials. It adds the authentication handler to the network handling object of the Browser instance and starts network monitoring.

EnableHttpExchangeLoggingAndStartMonitoring: This method enables HTTP request/response logging and starts network monitoring. It takes in the Browser instance and an optional HttpExchangeLoggingOptions object that contains logging preferences. It calls the EnableHttpExchangeLogging method with the Browser instance and the specified logging options, and then starts network monitoring.

EnableHttpExchangeLogging: This method enables HTTP request/response logging. It takes in the Browser instance and an optional HttpExchangeLoggingOptions object that contains logging preferences. If the logging options are not specified, it creates a new instance of HttpExchangeLoggingOptions. Then it adds event handlers for the NetworkRequestSent and NetworkResponseReceived events of the Browser network handling object using the GetRequestEventHandler and GetResponseEventHandler methods.

GetResponseEventHandler: This method returns an event handler for the NetworkResponseReceived event that logs information about the received response according to the specified logging options.

GetRequestEventHandler: This method returns an event handler for the NetworkRequestSent event that logs information about the sent request according to the specified logging options.

These methods can be useful for debugging network-related issues during automated web testing or any other application that relies on web communication. The logging can help to understand what requests and responses were made and received, and the authentication handler can be used to pass authentication information to a server during requests.

The NetworkHandlingTests

This is a test class that verifies the network handling functionality of an application. The class has several test methods that check if different operations related to network handling work correctly. These operations include setting and clearing basic authentication, adding and clearing request and response handlers, and subscribing and unsubscribing from request sent and response received events. Additionally, the class tests the enabling and disabling of HTTP exchange logging. The tests are conducted using a browser instance initialized with the Aquality services library.