Tutorials Hut

  • Selenium WebDriver

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report



  • Desired Capabilities in Selenium and its usage

    This article will present you with a complete idea about Desired Capabilities in Selenium and how we use it in our automation test scripts.

    Selenium- Desired Capabilities - Chrome Options

    Introduction to Desired Capabilities

    Desired Capabilities is a class which is used to declare a few basic requirements such as browsers, operating systems, browser versions, etc. to perform automated cross browser testing of a web application.

    Every testing scenario should be executed in a specific testing environment. Basically the testing environment can be a web browser, browser versions, OS , mobile devices, mobile emulator, etc. The Desired Capabilities Class helps us to tell the webdriver about the environment which we will use in testing

    Desired Capabilities class is a component of the org.openqa.selenium.remote.DesiredCapabilities package.

    We use capabilities as key-value pairs to set them for browsers or configurations used for building test environments

    We can configure driver instance like FirefoxDriver, ChromeDriver, InternetExplorerDriver by using desired capabilities.

    Desired Capabilities are more useful in cases like:

      • We use browser properties and the device properties in mobile application automation so we use Desired Capabilities  in this case.
      • When we want to run the test cases on a different browser or different platforms using selenium grid then also we use same class

    Methods in DesiredCapabilities for Selenium

    let us discuss different methods available in Desired Capabilities class , which are used to set different properties for building a test environment.

    1) getBrowserName()

    This method is used to help in retrieving the browser name of the current system.

    public java.lang.String getBrowserName()

    2) setBrowserName()

    This method is used to help to set   the browser name for the environment.

    public void setBrowserName(java.lang.String browserName)

    3) getVersion()

     This method is used to retrieve the browser version or OS of the system where we are running our test cases

    public java.lang.String getVersion()

    4) setVersion()

     This method is used to set the  browser version or OS of the system where we will execute our test cases.

    public void setVersion(java.lang.String version)

    5) getPlatform()

    This method helps in retrieving the details of the operating system.

    public Platform getPlatform()

    6) setPlatform()

    This method helps in defining the desired operating system to be used.

    public Platform setPlatform()

    7) getCapability Method

    This method is used to help in retrieving the capabilities of the current system on which the tests are being performed.

    public java.lang.Object getCapability(java.lang.String capabilityName)

    8) setCapability() Method

    The setCapability() method is used to set the property of a test environment like device name, operating system name, operating system versions, browser, and browser versions

    setCapability :public void setCapability(java.lang.String capabilityName,boolean value)

    setCapability :public void setCapability(java.lang.String capabilityName,java.lang.String value)

    setCapability :public void setCapability(java.lang.String capabilityName,Platform value)

    setCapability :public void setCapability(java.lang.String key,java.lang.Object value).

    Desired Capabilities in Selenium testing for different Browsers

    Let us discuss how we can set different capabilities for different browsers.

     1) Desired Capabilities in Selenium WebDriver for Chrome

    There are two ways to set the capabilities for ChromeDriver. 1. Use of ChromeOptions Class (This is supported by Java, Python, etc.) 2. Desired Capabilities (This is supported by Python, Ruby, etc. While it is also available in Java, its usage in Java is deprecated.)

    ChromeOptions is another class which is used manage options specific to Chrome Browser, It can be used in conjunction with Desired Capabilities in Selenium for Chrome to customize or manipulate the various properties of the Chrome browser. The following are the commonly used arguments from the 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 the default browser. Disable-popup-blocking: It is used to disable the pop-ups which are displayed on the chrome browser. Incognito:Opens in incognito mode. Start -maximized: Opens chrome in maximized mode. Headless: It is used to open the chrome browser in headless mode. Now, let us discuss an example how to open chrome browser in maximised mode using selenium web driver

    Now, let us discuss an example how to open chrome browser in maximised mode using selenium web driver

    //Setting up capabilities to run our test script
    ChromeOptions options = new ChromeOptions();
    options.addArgument("start-maximized");
    ChromeDriver driver = new ChromeDriver(options);

    Chrome Options for Adblocker extension

    Below Is the  example of an ad blocker where Chrome Option is used in conjunction with Desired Capabilities class. We will use an adblocker extension for this purpose. We have to download the crx file of the extension first before executing below code (AdBlocker extension through http://crxextractor.com/)

    //Setting up capabilities to run our test script
    ChromeOptions options = new ChromeOptions();
    options.addExtensions(new File("Path to CRX File"));
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    ChromeDriver driver = new ChromeDriver(capabilities);

    2) Desired Capabilities in Selenium WebDriver for IE(Internet Explorer)

    For internet Explorer, we make use of InternetExplorerOptions with Desired Capabilities in Selenium WebDriver.

    Below is the  example of declaring Desired Capabilities in Selenium WebDriver for IE.

    if(driverParameter == null || driverParameter.equalsIgnoreCase(IE))
    {
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    InternetExplorerOptions option = new InternetExplorerOptions();
    option.setHeadless(headless);
    capabilities.merge(option);
    }

    There are few Internet Explorer specific capabilities which we can use, let us discuss some of them one by one.

    a) IgnoreZoomSetting(boolean): sed to ignore checking the browser’s zoom level to 100%. By default, it is set as false. It takes a boolean value as input.

    b) InitialBrowserUrl(string): Using this capability we can decide the initial URL, the website to which it should redirect while internet explorer browser starts. It takes a string as input.

    c) EnableElementCacheCleanup(boolean): This capability provides a check over the obsolete elements from element cache. If they are found then the capability instructs the WebDriver to clean up. It takes a boolean value as input.

    d) RequireWindowFocus(boolean): This capability is used for instructing the driver to check that the internet explorer window has the focus before performing any operations like a mouse or keyboard events etc. It takes a boolean value as input and by default, it is set as false.

    e) IgnoreProtectedModeSettings(boolean): If you wish to skip past the protected mode check while performing Selenium automation testing then you can leverage this capability. It takes a boolean value as input.

    Desired Capabilities for Java in Selenium WebDriver

    //Setting up capabilities to run our test script
    
    @BeforeClass
    
    public void setUp() throws Exception {
    
    DesiredCapabilities capabilities = new DesiredCapabilities();
    
    capabilities.setCapability("browserName", "chrome");
    
    capabilities.setCapability("version", "77.0");
    
    capabilities.setCapability("platform", "win10");
    
    capabilities.setCapability("build", “TestingApplication”);
    
    capabilities.setCapability("name", "TestingJAVAApplication");
    
    capabilities.setCapability("network", true); // To enable network logs
    
    capabilities.setCapability("visual", true); // To enable screenshot
    
    capabilities.setCapability("video", true); // To enable video recording
    
    capabilities.setCapability("console", true); // To capture console logs
    
    capabilities.setCapability("selenium_version","4.0.0-alpha-2");
    
    capabilities.setCapability("timezone","UTC+08:30");
    
    capabilities.setCapability("geoLocation","IN");
    
    capabilities.setCapability("chrome.driver”,”80.0”);
    
    try {
    
    driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
    
    } catch (MalformedURLException e) {
    
    System.out.println("Invalid grid URL");
    
    } catch (Exception e) {
    
    System.out.println(e.getMessage());
    
    }
    
    }
    



  • Selenium WebDriver Tutorials

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report

















  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Scroll to Top