Book Image

Selenium Framework Design in Data-Driven Testing

By : Carl Cocchiaro
Book Image

Selenium Framework Design in Data-Driven Testing

By: Carl Cocchiaro

Overview of this book

The Selenium WebDriver 3.x Technology is an open source API available to test both Browser and Mobile applications. It is completely platform independent in that tests built for one browser or mobile device, will also work on all other browsers and mobile devices. Selenium supports all major development languages which allow it to be tied directly into the technology used to develop the applications. This guide will provide a step-by-step approach to designing and building a data-driven test framework using Selenium WebDriver, Java, and TestNG. The book starts off by introducing users to the Selenium Page Object Design Patterns and D.R.Y Approaches to Software Development. In doing so, it covers designing and building a Selenium WebDriver framework that supports both Browser and Mobile Devices. It will lead the user through a journey of architecting their own framework with a scalable driver class, Java utility classes, JSON Data Provider, Data-Driven Test Classes, and support for third party tools and plugins. Users will learn how to design and build a Selenium Grid from scratch to allow the framework to scale and support different browsers, mobile devices, versions, and platforms, and how they can leverage third party grids in the Cloud like SauceLabs. Other topics covered include designing abstract base and sub-classes, inheritance, dual-driver support, parallel testing, testing multi-branded applications, best practices for using locators, and data encapsulation. Finally, you will be presented with a sample fully-functional framework to get them up and running with the Selenium WebDriver for browser testing. By the end of the book, you will be able to design your own automation testing framework and perform data-driven testing with Selenium WebDriver.
Table of Contents (15 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface

Third-party grid architecture support including the Sauce Labs Test Cloud


When adding support to the driver class for third-party grids such as Sauce Labs or Perfecto Mobile, users must add conditions in the driver class that set specific preferences, credentials, URLs, and so on, to direct traffic to that test platform. They are really just other Selenium grids to run against in the cloud, which free up the tester from all the maintenance requirements of an in-house grid. The condition to run on one of these third-party platforms can be passed as a parameter to the test, specifically environment. For instance, here is an example of a TestNG XML file using parameters to set up the driver:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="My Test Suite" preserve-order="true" parallel="false" thread-count="1" verbose="2">

<!-- suite parameters -->
    <!-- "local", "remote", "saucelabs" -->
    <parameter name="environment" value="saucelabs" />

    <test name="My Feature Test">
        <!-- test parameters -->
        <parameter name="browser" value="chrome" />
        <parameter name="platform" value="Windows 10" />

        or

        <parameter name="browser" value="iphone"/>
        <parameter name="platform" value="iphone"/>

        <classes>
            <class name="com.myproject.MyTest" />
        </classes>
    </test>
</suite>

Each provider will require a different RemoteWebDriver URL, credentials to access their test cloud, preferences, and various other features that would allow access to a DMZ inside a corporate Firewall. Here are some examples of specific Sauce Labs Cloud platform requirements:

  • Tunnel: If the web server, or any other servers, are behind a corporate Firewall and not open to the internet, then a unique tunnel will have to be set up and passed to the driver class as a Desired Capability.
  • Remote URL: Sauce Labs has its own RemoteWebDriver URL for accessing its server at http://SAUCE_USERNAME:[email protected]:80/wd/hub.
  • Preferences: Sauce Labs has a set of unique capabilities that allow the passing of when creating the driver for the test. Examples include screen resolution, browser versions (including latest and beta versions), mobile device types (including physical and simulator/emulator devices), Selenium versions, driver versions, session parameters, results processing, and so on.

Note

The Sauce Labs Wiki documentation, which includes Desired Capabilities and Platform Configurator, is located at https://wiki.saucelabs.com/.

// third party preferences for SauceLabs...

if ( environment.equalsIgnoreCase("saucelabs") ) {
    // setup the Selenium Grid capabilities...
    String remoteHubURL =  
           "http://SAUCE_USERNAME:SAUCE_ACCESS_KEY
           @ondemand.saucelabs.com:80/wd/hub";

    caps.setCapability("screenResolution",
                       "1920x1080");
    caps.setCapability("recordVideo",
                        false);
    caps.setCapability("tunnelIdentifier",
                        System.getProperty("TUNNEL_IDENTIFIER"));
   ...
}