Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of DesiredCapabilities in Selenium WebDriver?

What is the use of DesiredCapabilities in Selenium WebDriver?

When we want to use this and how?

Answer with example would be appreciated.

like image 346
bugCracker Avatar asked Jul 08 '13 13:07

bugCracker


People also ask

How do you use DesiredCapabilities?

DesiredCapabilities capabilities = new DesiredCapabilities(); // Set android deviceName desired capability. Set your device name. capabilities. setCapability("deviceName", "your Device Name"); // Set BROWSER_NAME desired capability.

What is difference between DesiredCapabilities and ChromeOptions?

ChromeOptions class has introduced in the latest/updated version of Selenium. It is helpful to make changes in the Chrome browser whereas, DesiredCapabilities is an old concept (its usage in Java is deprecated.) to configure or make changes in the browser. Save this answer.

What is Chromeoption class and DesiredCapabilities?

The Chromeoptions Class is a concept in Selenium WebDriver for manipulating various properties of the Chrome driver. The Chrome options class is generally used in conjunction with Desired Capabilities for customizing Chrome driver sessions.

What is the use of desired capabilities?

Desired Capabilities are keys and values encoded in a JSON object, sent by Appium clients to the server when a new automation session is requested. They tell the Appium drivers all kinds of important things about how you want your test to work.


2 Answers

You should read the documentation about DesiredCapabilities. There is also a different page for the ChromeDriver. Javadoc from Capabilities:

Capabilities: Describes a series of key/value pairs that encapsulate aspects of a browser.

Basically, the DesiredCapabilities help to set properties for the WebDriver. A typical usecase would be to set the path for the FirefoxDriver if your local installation doesn't correspond to the default settings.

like image 63
LaurentG Avatar answered Sep 23 '22 20:09

LaurentG


  1. It is a class in org.openqa.selenium.remote.DesiredCapabilities package.
  2. It gives facility to set the properties of browser. Such as to set BrowserName, Platform, Version of Browser.
  3. Mostly DesiredCapabilities class used when do we used Selenium Grid.
  4. We have to execute mutiple TestCases on multiple Systems with different browser with Different version and Different Operating System.

Example:

WebDriver driver; String baseUrl , nodeUrl; baseUrl = "https://www.facebook.com"; nodeUrl = "http://192.168.10.21:5568/wd/hub";  DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setBrowserName("firefox"); capability.setPlatform(Platform.WIN8_1);  driver = new RemoteWebDriver(new URL(nodeUrl),capability); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES); 
like image 36
Avinash Pande Avatar answered Sep 22 '22 20:09

Avinash Pande