Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

What is the use of DesiredCapabilities in Selenium WebDriver?

When we want to use this and how?

Answer with an example would be appreciated.

1 Answer

0 votes
by (62.9k points)
  1. It is a class in org.openqa.selenium.remote.DesiredCapabilities package.
  2. It gives the facility to set the properties of the browser. Such as to set BrowserName, Platform, Version of Browser.
  3. Mostly DesiredCapabilities class used when do we use Selenium Grid.
  4. We have to execute multiple TestCases on multiple Systems with a 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);

Browse Categories

...