Selenium Framework Design in Data-Driven Testing

Book description

Take a deep dive into building data-driven test frameworks using Selenium WebDriver

About This Book

  • A comprehensive guide to designing data-driven test frameworks using the Selenium 3 WebDriver API, AppiumDriver API, Java-Bindings, and TestNG
  • Learn how to use Selenium Page Object Design Patterns and D.R.Y. (Don't Repeat Yourself) Approaches to software development in automated testing
  • Discover the Selenium Grid Architecture and build your own grid for browser and mobile devices
  • Use third party tools and services like ExtentReports for results processing, reporting, and SauceLabs for cloud-based test services

Who This Book Is For

This book is intended for software quality assurance/testing professionals, software project managers, or software developers with prior experience in using Selenium and Java to test web-based applications.This book is geared towards the quality assurance and development professionals responsible for designing and building enterprise-based testing frameworks.The user should have a working knowledge of the Java, TestNG, and Selenium technologies

What You Will Learn

  • Design the Selenium Driver Class for local, remote, and third party grid support
  • Build Page Object Classes using the Selenium Page Object Model
  • Develop Data-Driven Test Classes using the TestNG framework
  • Encapsulate Data using the JSON Protocol
  • Build a Selenium Grid for RemoteWebDriver Testing
  • Construct Utility Classes for use in Synchronization, File I/O, Reporting and Test Listener Classes
  • Run the sample framework and see the benefits of a live data-driven framework in real-time

In Detail

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.

Style and approach

A comprehensive approach to designing data-driven test frameworks using the Selenium 3 WebDriver API, Java-Bindings, and TestNG Technologies

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  2. Building a Scalable Selenium Test Driver Class for Web and Mobile Applications
    1. Introduction
      1. Data-driven testing
      2. Selenium Page Object Model
      3. DRY 
      4. What you will learn
    2. The singleton driver class
      1. Requirements
      2. The class signature
      3. Class variables
      4. JavaDoc
      5. Parameters
      6. Class methods
    3. Using preferences to support browsers and platforms
      1. Browser preferences
      2. Platforms
    4. Using preferences to support mobile device simulators, emulators, and real devices
      1. iOS preferences
      2. Android preferences
    5. Multithreading support for parallel and distributed testing
    6. Passing optional arguments and parameters to the driver
      1. varargs
      2. The parameter for setDriver
      3. JVM argument – -Dswitch
      4. Parameter processing methods
    7. Selenium Grid Architecture support using the RemoteWebDriver and AppiumDriver classes
    8. Third-party grid architecture support including the Sauce Labs Test Cloud
    9. Using property files to select browsers, devices, versions, platforms, languages, and many more
    10. Summary
  3. Selenium Framework Utility Classes
    1. Introduction
    2. Global variables
    3. Synchronization utility classes
      1. Selenium synchronization classes
        1. The ExpectedConditions class
        2. WebDriverWait/FluentWait classes
        3. Custom synchronization methods
    4. The JavascriptExecutor class
    5. The TestNG Listener class
      1. Building the test listener class
      2. Logging the results to the console or log file
      3. Including the test runner in the test class or suite
    6. File I/O class
      1. Property files
      2. Lookup table files
      3. CSV files
      4. Log files
    7. The image capture class
      1. The capture screen method
      2. The capture image method
      3. The compare image method
    8. The reporter class
    9. The JavaMail class
    10. Summary
  4. Best Practices for Building Selenium Page Object Classes
    1. Introduction
      1. What you will learn
    2. Best practices for naming conventions, comments, and folder structures
      1. Naming conventions
      3. Folder names and structures
    3. Designing and building the abstract base classes for the AUT
      1. The abstract class
      2. Abstract methods
      3. Common locators
      4. Common methods
      5. Wrap up on base classes
    4. Designing and building subclasses for feature-specific pages using inheritance techniques
    5. Encapsulation and using getter/setter methods to retrieve objects from the page object classes
    6. Exception handling and synchronization in page object class methods
      1. Implicit exception handling
        1. TestNG difference viewer
      2. Explicit exception handling
      3. Try...catch exception handling
      4. Synchronizing methods
    7. Table classes
    8. Summary
  5. Defining WebDriver and AppiumDriver Page Object Elements
    1. Introduction
    2. Inspecting page elements on browser applications
      1. Types of locators
      2. Inheriting WebElements
      3. Inspecting WebElements
      4. Third-party plugins/tools
    3. Inspection of page elements on mobile applications
      1. Appium inspector
      2. Inspecting mobile elements
    4. Standards for using static locators
      1. Rules for using standard locators
        1. Simple locators
        2. CSS locators
        3. XPath query locators
      2. Referencing static elements in methods
      3. Retrieving static elements from other classes
    5. Standards for using dynamic locators
      1. Single attribute XPath versus CSS locators
        1. WebElements
        2. MobileElements
      2. Multiple attribute XPath versus CSS locators
      3. Using dynamic locators in methods
    6. Summary
  6. Building a JSON Data Provider
    1. Introduction
      1. What you will learn
    2. The TestNG Data Provider class
      1. The @DataProvider annotation
      2. The @Test annotation
    3. Extracting JSON data into Java objects
    4. Filtering test data
      1. Filtering include and exclude patterns
    5. JSON Data File formats
    6. The JSONObject class
    7. Summary
  7. Developing Data-Driven Test Classes
    1. Introduction
    2. Annotating test class methods using TestNG
      1. TestNG annotations
        1. @Test
    3. TestNG setup/teardown methods
      1. Setup methods
        1. @BeforeSuite, @BeforeTest, @BeforeGroups, @BeforeClass, and @BeforeMethod
      2. Teardown methods
        1. @AfterSuite, @AfterTest, @AfterGroups, @AfterClass, and @AfterMethod
      3. Order of precedence
    4. Naming conventions for test methods
      1. Test classes and data files
      2. Test methods
      3. Test parameters
      4. Test groups
      5. Test setup/teardown methods
    5. Using the TestNG DataProvider
    6. Calling page object methods in test classes
    7. Exception handling in test classes
      1. Test methods
      2. The setup/teardown methods
      3. The ITestResult class
      4. Test listener/reporter classes
    8. Designing base setup classes
    9. TestNG suite file structure
      1. Suite section: <suite>
      2. Groups section: <groups>
      3. Listeners section: <listeners>
      4. Test section: <test>
    10. Suite parameters
      1. @Parameters
    11. Summary
  8. Encapsulating Data in Data-Driven Testing
    1. Introduction
    2. Casting JSON data to Java objects
      1. JSON object
      2. Sequential numbering of row IDs in the data file
      3. Using Java object getter/setter methods
      4. Passing data to page object methods
    3. Building in positive, negative, boundary, and limit testing
      1. Negative testing
    4. Confirmation and exception property files
      1. Property files
      2. Lookup method in DataProvider
      3. JSON data file data
      4. Converting confirmation/error code on the fly
    5. Property files and parsing test data on the fly
      1. Environment property files
      2. System properties
      3. Initializing property file data
    6. Global variables versus dynamic data
    7. Processing JVM args
    8. Retrieving JSON data outside of test methods
    9. Supporting multibranded applications
      1. Multilocators
      2. Conditional code
      3. Runtime flags
    10. Multiple driver support
      1. Dual WebDriver testing
      2. Dual WebDriver and AppiumDriver testing
    11. Parallel testing
      1. Suite XML file
      2. Parallel properties method
      3. Common setup
    12. Summary
  9. Designing a Selenium Grid
    1. Introduction
    2. Virtual grids
      1. Grid structure
      2. Single browser nodes
      3. Multibrowser nodes
      4. Single mobile device nodes
      5. Multimobile/browser nodes
    3. Selenium driver class – WebDriver versus RemoteWebDriver
      1. The setDriver method for browser
      2. The setDriver method for mobile
      3. Overloaded setDriver method for browser
    4. Switching from local to remote driver
      1. Suite parameters
      2. JVM argument
      3. Default global variables
      4. Processing runtime parameters
    5. Selenium standalone server and client drivers
      1. Local use of drivers
      2. Remote use of drivers
    6. Selenium standalone server and browser driver command-line options
      1. Selenium hub
      2. Selenium hub JSON configuration file
      3. Selenium nodes
      4. Selenium node JSON configuration file
    7. Appium server and mobile simulator/emulator command-line options
      1. Appium nodes
      2. Appium node JSON configuration file
    8. Selenium Grid console
    9. Directing traffic to Selenium nodes
      1. Multiple nodes of the same platform and version
      2. Directing traffic using desired capabilities
      3. Maintenance of the Selenium Grid
      4. Summary
  10. Third-Party Tools and Plugins
    1. Introduction
    2. IntelliJ IDEA Selenium plugin
      1. Sample project files
      2. Generating element locators
      3. Wrap-up on Selenium Plugin
    3. TestNG results in IntelliJ and Jenkins
      1. IntelliJ TestNG results
      2. Jenkins TestNG results
    4. HTML Publisher Plugin
      1. Installation
    5. BrowserMob Proxy Plugin
      1. Getting started
    6. ExtentReports Reporter API class
      1. ExtentHTMLReporter
      2. Dashboard page
      3. Categories page
      4. Tests page
      5. Code sample
    7. Sauce Labs Test Cloud services
      1. Sauce Labs Test Cloud features
        1. Browser and mobile platforms
        2. Driver code changes
        3. Dashboard
        4. SauceConnect tunnel
        5. TestObject Real Device Cloud
        6. Jenkins plugin
      2. Advantages and disadvantages of using in-house versus third-party grids
    8. Summary
  11. Working Selenium WebDriver Framework Samples
    1. Introduction
    2. Selenium driver and DataProvider classes
      2. JSONDataProvider class
    3. Selenium utility classes
    4. ExtentReports classes
      2. extent-config.xml
    5. Browser page object base and subclasses
    6. Browser test class and data files
      2. PassionTeaCo.json
    7. Browser Suite XML and Maven Pom XML files
      1. PassionTeaCo.xml
      2. pom.xml file
    8. Summary

Product information

  • Title: Selenium Framework Design in Data-Driven Testing
  • Author(s): Carl Cocchiaro
  • Release date: January 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788473576