Desired Capabilities: Introduction and Implementation in Selenium

Every testing starts in some test environments like Local environment, Release environment, production environment, BAU environment, etc. Like these environments, test devices also create a kind of environments and we record the behavior of Application under test in these environments. Test device environment would be like testing in Android device, iOS device, Tablet, and Desktop device. We discussed earlier that test distribution on different devices is done with the help of Selenium Grid. In the same way, we can set properties of the browsers in such environments through Desired Capabilities. Hence, the agenda of this tutorial is about the use of Desired capabilities in Selenium WebDriver.

What are the Desired Capabilities in Selenium?

The desired capability is the collection of some attributes and their values which is used to configure browser properties like browser name, version, platform and much more. It even helps to configure the driver instances, ChromeDriver, FirefoxDriver, etc through Desired capabilities.

Significances of Desired Capabilities

Desired capabilities have a great significance with Selenium Grid configuration. Let’s have a quick look over some of the benefits of it with respect to the Selenium project configuration:

  • It helps in mobility testing to set the properties of the browser and device as well
  • The desired capability has very much importance in setting the browser’s properties during test distribution through Selenium Grid
  • It is the best way to work with Cross browser testing

DesiredCapabilities class is basically used to configure browser properties remotely. We need to import the following file from Selenium remote library before we proceed to the implementation part:

Desired Capabilities Inviul

Some of the Desired Capabilities method

Here is the list of some of the methods which we use while implementing Desired capabilities in Selenium. These methods are like getters and setters, they simply used to set the properties and their value and to get their values as well.

  • getBrowserName()
  • setBrowserName()
  • getPlatform()
  • setPlatform()
  • getVersion()
  • setVersion()
  • getCapability()
  • setCapability()
  • acceptInsecureCerts()
  • setJavaScriptEnabled()
  • setAcceptInsecureCerts()

You first need to create an instance of the class then you can use the above methods either to set the property or to get the properties. Here is the generic class instance declaration.

DesiredCapabilities with respect to a browser/platform

We can instantiate DesiredCapabilities class directly with respect to specific browser without using setBrowserName() method or setCapability() method.

Here is a list of browsers and platform supported by DesiredCapabilities class.

Desired capabilities browserCapability Type Arguments

There are some capability types which is used to pass as arguments inside setCapability() method to perform some quick actions. Here is the sample implementation then we will see the list of some capability types.

List of Capability Types


These are some of the capability types which we can use whenever required. Click here to know more.

How to implement Desired capabilities in the Selenium project?

After all the theoretical discussion, let’s have a look over the implementation of the Desired capabilities in our Selenium WebDriver project. Here is the sample program:

Note: I would like to tell you that the above technique to implement DesiredCapabilities is not practiced these days. A new alternative technique has come which we will discuss separately in the next tutorial.

Join Inviul fb group

Leave a Reply