-
Notifications
You must be signed in to change notification settings - Fork 14
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:
void enablePerformanceMonitoring(String timeDomain) - enables collecting and reporting performance metrics with timeDomain explicitly specified; void enablePerformanceMonitoring() - enables collecting and reporting performance metrics with timeDomain set by default; void disablePerformanceMonitoring() - disables collecting and reporting performance metrics; Map<String, Number> getPerformanceMetrics() - returns the current values of performance metrics as a Map, where the key is the name of the metric, Number is its current value The getAndCloseDevToolsSessionTest test of the PerformanceMetricsTest class demonstrates the above methods. Performance metrics gathering is activated using enablePerformanceMonitoring() method (by default metrics gathering is disabled), then some metrics are gathered using getPerformanceMetrics() method and it is checked that metrics were actually gathered. Then the metrics gathering is disabled using disablePerformanceMonitoring() method and it is checked that an empty metrics object is now returned when getPerformanceMetrics() method is called. Then metrics are enabled again using enablePerformanceMonitoring(String timeDomain) method and the above checks are repeated.
The following methods have been added to Aquality Selenium to handle the methods of the DevTools class instance directly:
boolean hasActiveDevToolsSession() - checks if there is an active CDP session for this browser; DevTools getDevToolsSession(String windowHandle) - returns the current CDP session for the specified window (windowHandle), or creates a new one if no session exists; DevTools getDevToolsSession() - returns the current CDP session for the first of the browser windows, or creates a new one if there is no session; void closeDevToolsSession() - closes the current CDP session. The getAndCloseDevToolsSessionTest test demonstrates how the above methods work.
In Aquality Selenium, as in Selenium 4, not all the functionality of the Chrome DevTools Protocol is implemented. To use an arbitrary CDP method, the following methods are implemented in the framework:
X sendCommand(Command command) - sends a command, returns the result of its execution (if any). Selenium 4 implements quite a few CDP commands as static methods that return Command, for example V108Log. Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> commandParameters) - this method can be used if Selenium 4 does not implement a suitable Command. Returns result of CDP method execution, if any, commandName - method name (e.g. Network.emulateNetworkConditions), commandParameters - CDP method parameters as Map, where key is parameter name, value - value of given parameter An example of a CDP method description with possible parameters is shown below. An example of how to use the above methods can be found in the OverrideUserAgentTest class and in this section.