-
Notifications
You must be signed in to change notification settings - Fork 15
DevTools handling
The DevToolsHandling class contains a set of general methods for handling the Chrome DevTools Protocol (CDP).
Selenium 4 implements methods to collect performance metrics based on CDP Performance methods (e.g. Nodes - number of DOM nodes on a page, ScriptDuration - total execution of all JS scripts). The following wrapper methods were created in Aquality Selenium to collect performance metrics:
The DevToolsHandling class implements the IDevTools interface and provides methods to interact with the browser using the Chromium Developer Tools debugging protocol.
Constructors DevToolsHandling(IDevTools devToolsProvider) - Initializes an instance of DevToolsHandling with a devToolsProvider instance which supports the CDP protocol. Properties HasActiveDevToolsSession - Gets a value indicating whether a DevTools session is active. Methods CloseDevToolsSession() - Closes a DevTools session. GetDevToolsSession() - Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol. This method calls the GetDevToolsSession(int) overload, where the parameter protocolVersion defaults to autodetect the protocol version for Chromium and V85 for Firefox. GetDevToolsSession(int protocolVersion) - Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol. ExecuteCdpCommand(string commandName, Dictionary<string, object> commandParameters) - Executes a custom Chromium Dev Tools Protocol command. This method works only if the current driver is an instance of ChromiumDriver. SendCommand(string commandName, JToken commandParameters = null, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) - Sends the specified command and returns the associated command response. This method is used to send a command that is not supported by the ExecuteCdpCommand method. Properties HasActiveDevToolsSession csharp Copy code public bool HasActiveDevToolsSession { get; } Gets a value indicating whether a DevTools session is active. The backing field for this property is not set to null in Selenium CloseDevToolsSession implementations ChromiumDriver and FirefoxDriver, so a new backing field wasDevToolsSessionClosed is used.
Methods CloseDevToolsSession csharp Copy code public void CloseDevToolsSession() Closes a DevTools session.
GetDevToolsSession csharp Copy code public DevToolsSession GetDevToolsSession() Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol. This method calls the GetDevToolsSession(int) overload, where the parameter protocolVersion defaults to autodetect the protocol version for Chromium and V85 for Firefox.
Returns The active session to use to communicate with the Chromium Developer Tools debugging protocol.
GetDevToolsSession(int protocolVersion) csharp Copy code public DevToolsSession GetDevToolsSession(int protocolVersion) Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
Parameters protocolVersion - The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version for ChromiumDriver, V85 for FirefoxDriver. Returns The active session to use to communicate with the Chromium Developer Tools debugging protocol.
ExecuteCdpCommand csharp Copy code public object ExecuteCdpCommand(string commandName, Dictionary<string, object> commandParameters) Executes a custom Chromium Dev Tools Protocol command.
Parameters commandName - The name of the command to execute. commandParameters - The parameters of the command to execute. Returns An object representing the result of the command, if applicable.
Exceptions NotSupportedException - If the current driver is not an instance of ChromiumDriver. SendCommand csharp Copy code public async Task SendCommand(string commandName, JToken commandParameters