Desired Capabilities in Selenium WebDriver

Desired Capabilities in Selenium WebDriver

Hello friends! in this post we will be studying about Desired Capabilities. Many 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 the Desired Capabilities?

Desired Capabilities are a set of properties used to configure a particular instance of the browser. We have both browser-independent capabilities like browserName, version, acceptSslCerts, etc as well as browser-specific capabilities like firefox_binary for Mozilla Firefox, chromeOptions for setting Chrome specific desired capabilities.

Setting Desired Capabilities in Selenium

The Desired Capabilities class provides a setCapabilityMethod() to set the different capabilities in a browser like accepting SSL certificates, enabling javascript, querying the browser location is allowed or not, etc.
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
acceptSSLCertificate.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
//Binding the capabilities to a new instance of chrome browser
WebDriver driver = new ChromeDriver(acceptSSLCertificate);

Capabilities

Some of the capabilities common to all browsers are –

  • acceptSslCerts-
    Constant Field – CapabilityType.ACCEPT_SSL_CERTS
    For enabling or disabling a browser session to accept the SSL certificates by default.
  • applicationCacheEnabled-
    Constant Field – CapabilityType.SUPPORTS_APPLICATION_CACHE
    For checking if the browser instance is capable of interacting with the application cache.
  • cssSelectorsEnabled-
    Constant Field – CapabilityType.SUPPORTS_FINDING_BY_CSS
    For checking if the use of CSS selector for locating web elements is enabled or not.
  • javascriptEnabled-
    Constant Field – CapabilityType.SUPPORTS_JAVASCRIPT
    For checking if javascript execution is enabled or not in the browser instance.
  • takesScreenshot-
    Constant Field – CapabilityType.TAKES_SCREENSHOT
    For checking if the take screenshot ability is enabled or not.
  • webStorageEnabled-
    Constant Field – CapabilityType.SUPPORTS_WEB_STORAGE
    For checking if the browser instance is capable of interacting with storage objects.
  • handlesAlert-
    Constant Field – CapabilityType.SUPPORTS_ALERTS
    For checking if the browser instance is capable of handling window pop-ups.

That’s all we have in this section. Please comment below to share your views or ask any questions and don’t forget to check our complete selenium tutorial here.

Selenium Webdriver with Java Tutorial

От QA genius

Adblock
detector