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

Preface

The Selenium WebDriver API is based on the JSON wire over the HTTP protocol. It is currently the industry gold standard for test automation. Selenium Framework design in data-driven testing is a comprehensive approach to designing data-driven test frameworks using the Selenium 3 WebDriver API, Java bindings, and TestNG technologies. This book will guide users through a series of design paradigms in building the Selenium WebDriver Framework for both browser and mobile applications. The user will be able to take sample framework code and apply it directly to their own application framework.

The technology discussed in this book is based on the Selenium 3 WebDriver API, Java bindings, and TestNG Framework components. The book will explain the practical use of the Selenium page object design pattern in data-driven testing, the Selenium WebDriver Framework components such as the driver class to support local, remote, and third-party grid architectures, building page object classes in Java, building data-driven test classes using the TestNG Framework, and a sample DataProvider using the JSON protocol to encapsulate data for testing.

Other important areas it will cover include support for concurrent multiple drivers, parallel/distributed testing, utilities, test reporter classes, test listener classes, and third-party plugins to the Selenium WebDriver.

Who this book is for

There are many "getting started" Selenium manuals in the market today, such as Selenium Testing Tools Cookbook by Packt Publishing. These types of book are great introductions to the Selenium WebDriver technologies, where concepts are broken down into simple steps to allow the user to understand each concept that Selenium, Java, and TestNG bring to the testing world.

Selenium Framework Design in Data-Driven Testing takes those concepts to the next level, assumes that the user has working knowledge of Java, TestNG, and Selenium, and teaches them how to design and build a scalable, efficient, object-oriented, data-driven test framework. In that respect, this manual is geared toward the quality assurance and development professionals responsible for designing and building enterprise-based testing frameworks.

What this book covers

Chapter 1Building a Scalable Selenium Test Driver Class for Web and Mobile Applications, shows users how to get started with designing and building the Selenium Framework driver class. This class is the engine that drives the browser and mobile applications. With Selenium WebDriver technology, users can test all the popular browsers and mobile devices using the same driver class and programming language. The Selenium WebDriver technology is platform independent and has various language bindings to support cross-browser and device testing in a single code base.

Chapter 2Selenium Framework Utility Classes, describes how to design Java utility classes to support the framework components that are non-specific to any of the applications under test. Users will learn how to build classes to perform file I/O operations, data extraction, logging, synchronization, result processing, reporting, global variables, and many more.

Chapter 3Best Practices for Building Selenium Page Object Classes, introduces users to designing and building application-specific classes following the Selenium Page Object Model. Users will be guided through designing abstract base classes, deriving subclasses, and structuring classes to use common inheritance methods to ensure that page elements and methods are stored in central locations. In following these design principles, users will create an abstract separation layer between the page object and test classes in the framework.

Chapter 4Defining WebDriver and AppiumDriver Page Object Elements, presents users with design techniques to ensure that elements are defined using best practices for locators, minimum number of elements defined in page object classes, how to build locators on the fly, and when to use static verses dynamic locators to test page object elements.

Chapter 5Building a JSON Data Provider, explains how to design and build a TestNG DataProvider class using the JSON protocol to store data. The concept of data-driven test frameworks is introduced, and how to use a DataProvider to extract data on the fly to ensure that standards for data encapsulation and DRY approaches are being followed is covered.

Chapter 6Developing Data-Driven Test Classes, explores how to design data-driven test classes using the TestNG technologies. This includes TestNG features such as annotations, parameters, attributes, use of DataProviders in test classes, data extraction, exception handling, and setup/teardown techniques.

Chapter 7Encapsulating Data in Data-Driven Testing, describes the use of encapsulation in data-driven testing. This will include JSON data manipulation, use of property files, processing JVM arguments, casting JSON data to Java objects, supporting multiple drivers, and parallel testing.

Chapter 8Designing a Selenium Grid, presents the Selenium Grid Architecture, including designing a virtual grid in the Cloud, how to build the grid hub, browser nodes, and Appium mobile nodes, using the grid console, how to cast tests to the RemoteWebDriver, and supporting third-party grids.

Chapter 9Third-Party Tools and Plugins, details methodologies in using third-party tools and plugins in the Selenium Framework design. This will include the IntelliJ IDEA Selenium plugin, TestNG for results processing, the HTML Publisher Plugin, BrowserMob, ExtentReports, and Sauce Labs.

Chapter 10Working Selenium WebDriver Framework Samples, provides users with a real working sample framework including Selenium driver and utility classes, page object base and subclasses, DataProvider class, data-driven test class, JSON data file, TestNG test IListener class, and ExtentReports IReporter classes. Users will be able to install the files in their own project, use the supplied Maven pom.xml file to pull down the required JAR files, and run the sample data-driven tests against a real practice website across multiple browser types.

To get the most out of this book

To get up and running, users will need to have the following technologies installed:

  • Java JDK 1.8
  • IntelliJ IDEA 2017.3+
  • Selenium WebDriver 3.7.1+ JAR
  • Selenium Stand-alone Server 3.7.1+ JAR
  • Appium Java Client 5.0.4+ JAR
  • Appium Server 1.7.1 JAR for iOS or Linux
  • TestNG 6.11 JAR
  • ExtentReports 3.1.0 JAR
  • Browsers: Google Chrome 62.0, Mozilla Firefox 57.0, Microsoft Internet Explorer 11.0
  • Drivers: chromedriver.exe 2.33, geckodriver.exe 0.19.1, IEDriverServer.exe 3.7.1+
  • Apple Xcode and iPhone Simulators for iOS
  • Google Android SDK and Samsung Galaxy emulators for Linux
  • VMware virtual machines

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Selenium-Framework-Design-in-Data-Driven-Testing. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

 

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Create a separate module called something like Selenium3 with the same folder structures."

A block of code is set as follows:

public abstract class BrowserBasePO <M extends WebElement> {
    public int elementWait = Global_VARS.TIMEOUT_ELEMENT;
    public String pageTitle = "";
    WebDriver driver = CreateDriver.getInstance().getDriver();

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public abstract class MobileBasePO <M extends MobileElement> {
    public int elementWait = Global_VARS.TIMEOUT_ELEMENT;
    public String pageTitle = "";
    AppiumDriver<MobileElement> driver =

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "This is a basic concept in Java called encapsulation."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.