Desired Capabilities in selenium


DesiredCapabilities describe a series of key/value pairs that encapsulate aspects of a browser, 
  Basically this is used to set certain properties of browser for the WebDriver.
Properties such as:
  • set the path of the browser if not installed in default location.
  • set the browser Version, Browser Name, platform (Normally we use in selenium GRID)
  • to set the firefox profile
  • configurations related to browser cookies, SSL security popups,
Let's see some of the implementation of DesiredCapabilities in selenium:
A part of the code to set browser, platform and version
String NodeUrl = "http://10.112.76.224:4444/wd/hub"; //Node URL
String BaseUrl = "http://www.google.com"; //Web App under test
DesiredCapabilities cap = new DesiredCapabilities();
cap = DesiredCapabilities.firefox();
/*cap = DesiredCapabilities.internetExplorer();
*cap = DesiredCapabilities.chrome(); */
cap.setPlatform(Platform.WINDOWS);
WebDriver driver = new RemoteWebDriver(new URL(NodeUrl), cap);
driver.get(BaseUrl);
/*Rest of the code goes on from here*/
.......
//To disable application cache
cap.setCapability("applicationCacheEnabled", "false");
WebDriver driver= new FirefoxDriver(cap);
......
//A way to set fireFox profile through DesiredCapabilities
FirefoxProfile fp = new FirefoxProfile();
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(FirefoxDriver.PROFILE, fp);
WebDriver driver = new RemoteWebDriver(cap);
.....
//To set firefox path, if not in default location
cap.setCapability("firefox_binary", "Path of FireFox browser installation");  
 //path is like "C:\\FirefoxPortable\\App\\Firefox\\firefox.exe"
WebDriver driver = new FirefoxDriver(cap);

Through DesiredCapabilities, we can set ChromeOptions (setting ChromeDriver-specific capabilities)
Example of setting ChromeOptions,
Some times we get certificate error while launching Chrome browser using selenium webDriver
error:You are using unsupported command-line flag..
To get rid of the error banner in Chrome-
DesiredCapabilities cap = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
capabilities.setCapability("chrome.binary", "");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(cap);

1 comment:

  1. The other way to business Forex dealing working is to research market, MockingBird Method System find out all the appropriate important info, take quite a an extensive time duration of a few a few several weeks to a very extensive period to understand something,

    ReplyDelete