Desired Capabilities & Chrome Options in Selenium WebDriver - H Y R Tutorials

Desired Capabilities & Chrome Options in Selenium WebDriver

Share This
hyrtutorials


Selenium WebDriver is an open-source tool for automated testing of web apps across many browsers.

DesiredCapabilities are a set of key-value pairs encoded as a JSON object. It helps QAs define basic test requirements such as operating systems, browser combinations, browser versions, etc. within Selenium test scripts. The DesiredCapabilities class has multiple methods that let QAs specify the required properties regarding the desired test environments.

Not all server implementations will support every WebDriver feature. Therefore, the client and server should use JSON objects with the properties listed below when describing which features user requests that session support. If a session cannot support a capability that is requested in the desired capabilities, no error is thrown; a read-only capabilities object is returned that indicates the capabilities the session actually supports.

Below three are the capabilities used by the selenium server for browser selection:
  • browserName
  • version
  • platform

There are some read-only and red-write capabilities available in WebDriver, Apart from these capabilities, browser-specific capabilities are also available.

Chrome-Specific:
The WebDriver language APIs provide ways to pass capabilities to ChromeDriver. The exact mechanism differs by the language, but most languages use one or both of the following mechanisms:
-- Use the ChromeOptions class. This is supported by Java, Python, etc.
-- Use the DesiredCapabilities class. This is supported by Python, Ruby, etc. While it is also available in Java, its usage in Java is deprecated.

You can create an instance of ChromeOptions, which has convenient methods for setting ChromeDriver-specific capabilities. You can then pass the ChromeOptions object into the ChromeDriver constructor

Since Selenium version 3.6.0, the ChromeOptions class in Java also implements the Capabilities interface, allowing you to specify other WebDriver capabilities not specific to ChromeDriver.

To use DesiredCapabilities, you need to know the name of the capability and the type of value it takes.

Syntax:
<< Start Chrome maximized >>
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
ChromeDriver driver = new ChromeDriver(options);

IE specific:
-- ignoreProtectedModeSettings
-- ignoreZoomSetting
-- initialBrowserUrl
etc..