Skip to content

Supported Selenium 4 features.

aqualityAutomation edited this page Mar 17, 2023 · 12 revisions

One of the main innovations of Selenium 4 is support for the Chrome DevTools Protocol (CDP), which allows to simulate the work of the browser Developer Tools (for example, slowing down the Internet connection, getting logs from the browser console, etc.). These tools can greatly simplify test development and allow you to test previously inaccessible or hard-to-reach functionality of a web application. In Aqality Selenium, Selenium 4 DevTools functionality is implemented in the following classes: DevToolsHandling, EmulationHandling, JavaScriptHandling, NetworkHandling.

CDP Emulation Domain

Geolocation emulation

In Aquality Selenium, arbitrary geolocation is emulated using the following methods:

void setGeolocationOverride(Optional latitude, Optional longitude, Optional accuracy) - sets the current latitude, longitude, and geolocation accuracy. Omitting any of the parameters emulates position unavailable; void setGeolocationOverride(double latitude, double longitude, double accuracy) - has almost the same functionality as the previous method, the only difference is the use of primitives as parameters; void setGeolocationOverride(double latitude, double longitude) - a wrapper over the previous method, setting accuracy = 1. That is 100% geolocation accuracy. void clearGeolocationOverride() - resets the overridden geolocation set by the setGeolocationOverride() method. Geolocation override is demonstrated in the OverrideGeolocationTest class.

image

In the overrideGeolocationTest test, using the setGeolocationOverride() method, a new geolocation is set (LAT_FOR_OVERRIDE, LNG_FOR_OVERRIDE coordinates) and checks that the coordinates have been changed. Next, the geolocation is reset using the clearGeolocationOverride() method to the default value and it is checked that the coordinate values have returned to their original values.

Device Emulation

Using the DevTools commands, it is possible to emulate various devices by overriding the screen size (width, height), device type (desktop or mobile) and orientation (portrait or landscape). In Aquality Selenium, work with this functionality is carried out using the following methods:

void setDeviceMetricsOverride(Integer width, Integer height, Number deviceScaleFactor, Boolean mobile, Optional screenOrientationType, Optional screenOrientationAngle) - sets the width, height, scale, device type, orientation type, and angle at which the device is located; void setDeviceMetricsOverride(Integer width, Integer height, Number deviceScaleFactor, Boolean mobile) - overloaded version of the previous method with default values for screenOrientationType and screenOrientationAngle; void setDeviceMetricsOverride(Map<String, Object> params) - in this method, the device is configured using the Map<String, Object> params object, where the key is the name of the parameter (for example, the screen width), the value is the value of this parameter. These parameters are directly used in DevTools method Emulation.setDeviceMetricsOverride; void clearDeviceMetricsOverride() - resets overridden device metrics. The DeviceEmulationTest test class demonstrates how these methods work. image