Desired Capabilities are used in selenium to set the properties of specific browsers at the time of execution. There are multiple capabilities which we can set for browser like browser name , version , operating system , etc. These properties are in key value pairs. To declare Desired Capabilities in Selenium automation testing using Grid, we can use the
setCapability method from the DesiredCapabilities class to set the different types of capabilities of the browser (Ex. Chrome, IE, Firefox, Edge) platform name (Ex. Windows, macOS, etc.).
Few important methods of Desired capability :
getCapability():This method getCapability() from the class Desired Capabilities, which can be used to get the capabilities of the current system which we are using.
setCapability(): This method setCapability() from the class Desired Capabilities, can be used to set the name of device, name of platform, version of platform, absolute path of the application which is under test, application activity (in Mobile automation), application Package (in Java) and etc.
getBrowserName(): This method getBrowserName() from the class Desired Capabilities, can be used to get the name of the Browser.
setBrowserName(): This method setBrowserName() from the class Desired Capabilities, can be used to set the name of the Browser.
getVersion() : This method getVersion() from the class Desired Capabilities, can be used to get the version of the browser or platform.
setVersion() : This method setVersion() from the class Desired Capabilities, can be used to set the version of the browser or platform.
getPlatform() : This method getPlatform() from the class Desired Capabilities, can be used to get the details of the platform.
setPlatform(): This method setPlatform() from the class Desired Capabilities, can be used to set the details of the platform.
There are generic methods provided by DesiredCapabilities. Apart from these capabilities there are other options too which can be provided specifically by browsers . For Chrome browser we have ChromeOptions , for firefox Browser we have FirefoxOptions and so on.
These browser specific classes also gives some additional option to be done with desired capabilities.Let's see some additional options of ChromeOptions class :
Disable-infobars: It is used to prevent chrome browser from displaying notifications like “Chrome is being controlled by automated software”.
Make-default-browser: It is used to make the chrome browser as default browser.
Disable-popup-blocking: It is used to disable the pop-ups which are displayed on chrome browser.
Incognito: It opens chrome browser in incognito mode
start -maximized: It opens chrome browser in maximized mode
Headless: It is used to open the chrome browser in headless mode.