Some notes about Desired Capability vs ChromeOptions

What is “Capability”

Capabilities are options that you can use to customize and configure a browser’s driver session.

The WebDriver language APIs provides ways to pass capabilities to browser’s driver. The exact mechanism differs by the language, but most languages use one or both of the following mechanisms:

  1. Use the chromeOptions class. In this post, I will only mention ChromeOptions but idea is the same for FirefoxOptions, SafariOptions, EdgeOptions…
  2. Use the DesiredCapabilities class.
  • Desired Capability, ChromeOptions are both extended from MutableCapabilities class which has method setCapability() and merge().
  • Desired capability is a series of key/value pairs that stores browser properties and environment properties.
  • Desired capability can also be used to configure the driver instance but Selenium suggests we should use ChromeOptions.
  • Usually, we use Desired Capability when working with Selenium Grid or Appium server where we need to specify browser name like Chrome, Firefox, Safari, iPhone, iPad or platform such as Windows, linux, macOS.
  • we also can use both DesiredCapabilities (set browser, platform, …)and Chromeoptions (set Chrome settings) class via merge method.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName(“chrome”);
cap.setPlatform(Platform.WINDOWS);
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.merge(cap);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);

To Sum up, We should use ChromeOptions() when set capability for a local browser session and use Desired Capability when working with Selenium Grid or Appium server.

Reference links:

https://chromedriver.chromium.org/capabilities

https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities

Leave a comment