Hello friends! in this post we will be studying about Desired Capabilities. Many a times during automation we may need to work on a particular session of browser or work with a browser having some specific configurable properties set or unset. Selenium web driver provides certain browser specific properties known as Desired Capabilities.
What are Desired Capabilities?
Desired Capabilities are a set of properties used to configure a particular instance of browser. We have both browser independent capabilties like browserName, version, acceptSslCerts etc as well browser specific capabilities like firefox_binary for Mozilla Firefox, chromeOptions for setting Chrome specific desired capabilties.
Setting Desired Capabilities in Selenium
Code snippet to set a capability to a browser instance -
//Specifying desired capabilities for Chrome browser
DesiredCapabilities acceptSSLCertificate = DesiredCapabilities.chrome();
//Setting capability to accept SSL certificates
//Binding the capabilities to a new instance of chrome browser
WebDriver driver = new ChromeDriver(acceptSSLCertificate);
Some of the capabilities common to all browsers are -
Constant Field - CapabilityType.ACCEPT_SSL_CERTS
For enabling or a disabling a browser session to accept the SSL certificates by default.
Constant Field - CapabilityType.SUPPORTS_APPLICATION_CACHE
For checking if the browser instance is capable of interacting with application cache.
Constant Field - CapabilityType.SUPPORTS_FINDING_BY_CSS
For checking if the use of CSS selector for locating web elements is enabled or not.
Constant Field - CapabilityType.TAKES_SCREENSHOT
For checking if the take screenshot ability is enabled or not.
Constant Field - CapabilityType.SUPPORTS_WEB_STORAGE
For checking if the browser instance is capable of interacting with storage objects.
Constant Field - CapabilityType.SUPPORTS_ALERTS
For checking if the browser instance is capable of handling window pop-ups.