Desired Capability in Selenium:

 

What is Desired Capability?

  • The desired capability is a series of key / value pairs that stores browser properties such as browser names, browser versions, paths of browser driver in the system, etc. so that browser behavior can be set at scheduled time.
  • The desired capability can also be used to configure the example of the driver of Selenium WebDriver.

 

Use of Desired Capability:

  • This is used to configure the driver instance of Selenium WebDriver.
  • We can configure all driver examples such as FirefoxDriver, ChromeDriver, InternetExplorerDriver, using the desired capabilities.
  • It allows setting browser properties such as browser name, platform, browser version setting.
  • Mostly, the class of desired capabilities was used when we used the Selenium grid.
  • On many systems with different versions and different operating systems, we have to execute several test cases.
  • Each test scenario should be executed on some specific testing environment. The test environment can be a web browser, mobile device, mobile emulator, mobile simulator, etc.
  • The desired capabilities category helps us tell the WebDriver, which is going to be used in our test scripts.
  • The set up capacity method of the desired capabilities category, which is explained in the later part of the tutorial, can be used in the Selenium Grid. It is used to perform parallel execution on various machine configurations.

 

Package:

 

Create Object / Instance of DesiredCapabilities class:

 

Set android deviceName desired capability. Set your device name:

 

Set BROWSER_NAME desired capability:

 

Set android VERSION desired capability. Set your mobile device’s OS version:

 

Set android platformName desired capability. It’s Android in our case here:

 

Create Firefox Driver with Marionette capabilities:

 

Different types of Desired Capabilities Methods in Selenium:

 

  • getBrowserName(): Using this Method getBrowserName.

 

  • setBrowserName(): Using this Method Set browserName.

 

  • getVersion(): Using this Method getVersion.

 

  • setVersion(): Using this Method setVersion.

 

  • getPlatform(): Using this Method getPlatform Details.

 

  • setPlatform(): Using this Method setPlatform Details.

 

Example of Desired Capability in Selenium: 

What are the use of DesiredCapabilities in Selenium WebDriver and desired capabilities in selenium webdriver for chrome