What is the use of DesiredCapabilities in Selenium WebDriver?
When we want to use this and how?
Answer with example would be appreciated.
DesiredCapabilities capabilities = new DesiredCapabilities(); // Set android deviceName desired capability. Set your device name. capabilities. setCapability("deviceName", "your Device Name"); // Set BROWSER_NAME desired capability.
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.
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.
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.
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.
org.openqa.selenium.remote.DesiredCapabilities
package.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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With