- Jun 20, 2019
- admin
- 0
- Home
- ChromeOptions
- Desired Capabilities in Selenium Webdriver
Ware are Desired Capabilities?
The Desired Capabilities in Selenium help set the browser properties for automating web application testing. The capabilities are stored as key-value pairs encoded in a JSON object. The browser properties include the browser name, settings, version, and platform to customize the test environment.
In Selenium 4 and the latest versions, the desired capabilities class is deprecated. It is replaced with the Options class. You can use the Options class alone or combine the Desired Capabilities with Options.
FirefoxOptions options = new FirefoxOptions();
//Accept all the certificate
options.setAcceptInsecureCerts(true);
FirefoxDriver driver = new FirefoxDriver(options);
//Initiate the URL
driver.get(“https://www.google.com”);
Why do QA’s need Desired Capabilities?
Quality Assurance professionals use Desired Capabilities in Selenium to ensure that their automated tests are running properly. Desired Capabilities allow QA teams to customize the behavior of their automated tests, specify the browser type, set timeouts, and more.
This is especially important for web applications, as the browser and environment used can have a significant impact on the results of the test. By setting up desired capabilities, QA engineers can make sure that their tests are running in the exact environment they need them to be.
This helps them save time and resources while ensuring that their automated tests are running as expected. Furthermore, they can identify any potential issues or bugs in the application quickly and accurately.
Methods in Desired Capabilities for Selenium
The Desired Capabilities Class has various methods that allow QA to specify the required properties regarding the desired test environments. Now let’s look at all the methods available in the Desired Capabilities Class.
The getCapability() method helps retrieve the current system’s capabilities on which the tests are being executed.
public java.lang.Object getCapability(java.lang.String capabilityName)
The setCapability() method helps declare the test environments’ properties like device name, name of the operating system, operating system versions, browser name, and browser versions.
public java.lang.Object setCapability(java.lang.String capabilityName)
The getBrowserName() method helps retrieve the name of the browser of the current system.
public java.lang.String getBrowserName()
The setBrowserName() method helps set the browser name over which the tests will be performed.
public void setBrowserName(java.lang.String browserName)
The getVersion() method helps retrieve the browser or operating system version of the current system used for executing the tests.
public java.lang.String getVersion()
The setVersion() method helps define the browser version or the operating system for executing the tests.
public void setVersion(java.lang.String version)
The getPlatform() method helps retrieve the platform details.
public Platform getPlatform()
The setPlatform() method helps define the details of the platform.
public Platform setPlatform()
WebDriver driver;
String baseUrl , nodeUrl;
baseUrl = “https://www.facebook.com”;
nodeUrl = “http://192.168.10.21:5568/wd/hub”;
DesiredCapabilities capability = DesiredCapabilities.Chrome();
capability.setBrowserName(“chrome”);
capability.setPlatform(Platform.WIN8_1);
driver = new RemoteWebDriver(new URL(nodeUrl),capability);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
ChromeDriver is a standalone server used by the Selenium WebDriver to control the Chrome browser. Now we will discuss the desired capabilities the ChromeDriver supports and how to use them for the Chrome browser.
You can set the desired capabilities for ChromeDriver using these two methods,
ChromeOptions is a class that you can use in conjunction with the desired capabilities class in order to customize the different properties of the Chrome browser.
These are some of the common arguments from ChromeOptions class,
Chrome Options for Adblocker
You can handle the Chrome extension using Desired Capabilities class and ChromeDriver Options. Follow the below steps to do so,
Code Snippet
The below code depicts the above steps for activating Adblocker
//Setting up capabilities to run our test script
ChromeOptions options = new ChromeOptions();
//Add Adblocker extension to Chrome
options.addExtensions(new File(“C:\Users\Downloads\adblocker.crx”));
DesiredCapabilities capabilities = new DesiredCapabilities();
//Using Chrome Options with Desired Capabilities Class
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
Desired Capabilities in Appium Desired capabilities are a set of keys and values (ex. hash…
What is Selenium? Selenium is a portable software testing framework for web applications. Selenium provides a playback…
Desired Capabilities in Appium Desired capabilities are a set of keys and values (ex. hash…
Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!