TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium

Selenium Tutorial: DesiredCapabilities

Introduction

In real-time automation using selenium webdriver, it is often required to run our tests on a various combinations of ( OS , Browser and Versions ). So, this is required for the compatibility of the application in different environments. In this tutorial, we see how we can achieve this using the DesiredCapabilities class.

DesiredCapabilities

It is a class in WebDriver API. First of all, it provides support for setting the capability to run tests.DesiredCapabilities are a series of key-value pairs (KV ) that allow customization of testing. Also, note that if a session cannot support a capability that is requested in the desired capabilities, no error is thrown. Instead, a read-only capabilities object is returned that indicates the capabilities the session actually supports.

 

 

In the below example I would take BrowserStack as an example and for running a sample test customized to run on Mozilla Firefox with version 45 and on Windows 10 OS .

For example some are listed below:

Capability Value
os

OS you want to test.

WINDOWS
os_version

OS version you want to test.

 10
browser

Browser you want to test.

Firefox
browser_version

Browser version you want to test.

45

Code snippet

To get the above capability configuration we can use the below sample code snippet:

caps.setCapability("browser", "Firefox");
caps.setCapability("browser_version", "45.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("resolution", "1024x768");

 

Choosing  mobile browsers for running tests :

If we want to run your Selenium test scripts on iOS by specifying the version and device in the input capabilities. These capabilities are browserName and device.

The following example code snippet for running on iPhone device:

Listing

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "iPhone");
caps.setPlatform(Platform.MAC);
caps.setCapability("device", "iPhone 5");

 

Example code snippet to open Twitter on Windows 10 operating system on Mozilla Firefox with version 45 on BrowserStack using desired capabilities is shown below:

DesiredCapabilities caps = new DesiredCapabilities();
 caps.setCapability("browser", "Firefox");
 caps.setCapability("browser_version", "45");
 caps.setCapability("os", "Windows");
 caps.setCapability("os_version", "10");
 caps.setCapability("browserstack.debug", "true");
 WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
 driver.get("https://www.twitter.com");
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

 

Conclusion

Using desired capabilities with cloud, we get the freedom to run our selenium webdriver test on countless number of device combinations. Also, check out the Webdriver API desired capabilities class which has a lot of constructors and explore news of instantiating desired capabilities class with ease.

 

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Related Posts

Windows 10 Settings

Selenium /

Add Microsoft Webdriver on Windows OS

Download Selenium Components

Selenium /

Getting Started with Selenium Webdriver

LambdaTest Testing Cloud SaaS Platform

Selenium /

LambdaTest – Testing Cloud SaaS Platform

Selenium /

Selenium 3.0 and Mozilla GeckoDriver

SauceLabs Website

Selenium /

Run an Example Test on SauceLabs

‹ Common Exceptions in Webdriver Tests› Page Navigation in WebDriver

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version