How can DesiredCapabilities be utilized to customize the behaviour of the browser driver?

How can DesiredCapabilities be utilized to customize the behavior of the browser driver, such as setting timeouts or enabling/disabling features?

Hey Saanvi,

DesiredCapabilities in Selenium WebDriver are key/value pairs that configure browser behavior. They enable users to customize WebDriver instances, such as setting the FirefoxDriver path for non-default installations. Detailed documentation is available for DesiredCapabilities and specific drivers like ChromeDriver.

Hey Saanvi,

Here you must remember some pointers , below i am sharing you the example along with the pointers to consider when adding desired capabilities.

  • It is a class in org.openqa.selenium.remote.DesiredCapabilities package

  • It gives the facility to set the properties of the browser. Such as to set BrowserName, Platform, and Version of Browser.

  • Mostly, the DesiredCapabilities class is used when we use Selenium Grid.

  • 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);

I hope you understood the concept.