Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Selenium Framework Design in Data-Driven Testing
Selenium Framework Design in Data-Driven Testing

Selenium Framework Design in Data-Driven Testing: Build data-driven test frameworks using Selenium WebDriver, AppiumDriver, Java, and TestNG

eBook
zł59.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Selenium Framework Design in Data-Driven Testing

Selenium Framework Utility Classes

This chapter will introduce users to designing and building the Java utility classes that are required to support the Selenium framework. This includes classes for global variables, synchronization, alternative JavaScript methods, results processing, and mail retrieval. The following topics will be covered:

  • Introduction
  • Global variables
  • Synchronization utility class
  • The JavascriptExecutor class
  • The TestNG Listener class
  • File I/O class
  • Image capture class
  • The reporter class
  • The JavaMail class

Introduction

Java classes that are not Selenium page object classes, test classes, or data files, but support testing browser or mobile applications, can be considered utility classes. Most utility classes are static in nature, and use Java API methods that are not specific to any feature or test. They can include methods that operate on the browser or mobile device itself, but are not specific to the application running on them.

For example, the Selenium ExpectedConditions class has common methods to synchronize tests against actions occurring on a page, but it doesn't matter what the pages are, browser or mobile. Utilities can be built for file operations in reading, writing, or deleting files during tests. Test listener classes can be built, leveraging the TestNG TestListenerAdapter class, to log output to files and/or the console during test runs.

Other types of utilities...

Global variables

Global variables are generally static in nature, can be initialized at the start of a test, and remain available throughout the entire test run. Variables for application defaults, timeouts, property file locations, paths, and so on can be stored in this class. To be clear, test data is not stored in this class. Test data will be encapsulated in a different file format, and will be discussed in later chapters. Here is an example of some default global variables:

/**
* Global Variable Class
*
* @author Author
*
*/
public class Global_VARS {
// target app defaults
public static final String BROWSER = "firefox";
public static final String PLATFORM = "Windows 10";
public static final String ENVIRONMENT = "local";
public static String DEF_BROWSER = null;
public static String DEF_PLATFORM = null;
public static String...

Synchronization utility classes

One of the most important classes in the Selenium framework is the library containing all the test "synchronization" methods. In test automation, it is always necessary to "wait" for something to happen on a page after sending an event. That would include such actions as waiting for the page to render, waiting for an Ajax control to complete, waiting for a different page to appear, waiting for an item in a table, and so on. If test scripts are not synchronized, they will randomly fail when applications run faster or slower during execution, throwing exceptions that specific elements are not found. Selenium has introduced a set of classes that accommodate all of the types of synchronization that are required in browser and mobile testing.

...

The JavascriptExecutor class

The Selenium JavascriptExecutor class allows users to inject JavaScript commands directly into the context of the active browser frame or window. The use of this method is required in cases where the standard WebDriver class's methods fail to find or act upon an element on the browser page. JavaScript commands can be executed synchronously or asynchronously on the page. The class is an interface, and has been implemented for all the current driver classes. When designing a class to utilize this interface, users can pass commands directly to a WebElement by using the static locator, or one of the common locator methods available to WebDriver. Some of the more common methods will be outlined here:

The TestNG Listener class

In order to provide test results to the IDE console, or to a log file, users must build a test listener class into their framework. There are many open source classes available for use, as well as a TestNG class called TestListenerAdapter, which can be extended to provide custom logging information in real time. In other words, users can get results while the tests are running by logging them to the console, or by logging the data to a file.

How do you use it? How does it keep track of all the test results while the suite of tests are running? How does it get automatically called in a Selenium Framework Test Suite run? These questions will be answered in this section...

File I/O class

Another utility class that users will need to build is the file I/O class. This is a static Java class that contains all the methods for reading, writing, and deleting files, copying files, renaming files, accessing property files, finding files, setting file paths, extracting data, looking up messages, and many more. Storing all these similar methods in one central location for all CRUD operations (create, read, update, and delete) allows users to call these static methods from any page object or test class. Some of the more common methods will be outlined in this section.

Property files

Property files are common in testing, and are usually used for storing test environment data. There are various formats for...

The image capture class

Another important library to include in the framework is the image capture class. It is used by the test listener, reporter, and test classes to take screenshots of the browser or mobile screens when exceptions occur. There are various methods that can be built to capture the image of the entire screen, an individual WebElement or MobileElement, or to compare the images. Each method will be outlined here:

The image capture methods were developed by Unmesh Gundecha, and published by Packt Publishing in the reference book Selenium Testing Tools Cookbook - Second Edition. The book is available at https://www.packtpub.com/web-development/selenium-testing-tools-cookbook-second-edition.
/**
* Image Capture and Compare Class
*
* @author Name
*
*/
public class ImageCapture {
// constructor
public ImageCapture() throws Exception {
}

...
...

Introduction


Java classes that are not Selenium page object classes, test classes, or data files, but support testing browser or mobile applications, can be considered utility classes. Most utility classes are static in nature, and use Java API methods that are not specific to any feature or test. They can include methods that operate on the browser or mobile device itself, but are not specific to the application running on them.

For example, the Selenium ExpectedConditions class has common methods to synchronize tests against actions occurring on a page, but it doesn't matter what the pages are, browser or mobile. Utilities can be built for file operations in reading, writing, or deleting files during tests. Test listener classes can be built, leveraging the TestNG TestListenerAdapter class, to log output to files and/or the console during test runs.

Other types of utilities that can be leveraged include image capture, JavaMail, third-party test listener and reporters, and JavaScript Executor...

Global variables


Global variables are generally static in nature, can be initialized at the start of a test, and remain available throughout the entire test run. Variables for application defaults, timeouts, property file locations, paths, and so on can be stored in this class. To be clear, test data is not stored in this class. Test data will be encapsulated in a different file format, and will be discussed in later chapters. Here is an example of some default global variables:

/**
 * Global Variable Class
 * 
 * @author Author
 * 
 */
public class Global_VARS {
    // target app defaults
    public static final String BROWSER = "firefox";
    public static final String PLATFORM = "Windows 10";
    public static final String ENVIRONMENT = "local";
    public static String DEF_BROWSER = null;
    public static String DEF_PLATFORM = null;
    public static String DEF_ENVIRONMENT = null;
    public static String PROPS_PATH = null;

    // driver class defaults
    public static String propFile...

Synchronization utility classes


One of the most important classes in the Selenium framework is the library containing all the test "synchronization" methods. In test automation, it is always necessary to "wait" for something to happen on a page after sending an event. That would include such actions as waiting for the page to render, waiting for an Ajax control to complete, waiting for a different page to appear, waiting for an item in a table, and so on. If test scripts are not synchronized, they will randomly fail when applications run faster or slower during execution, throwing exceptions that specific elements are not found. Selenium has introduced a set of classes that accommodate all of the types of synchronization that are required in browser and mobile testing.

Selenium synchronization classes

Some of the highlights of the synchronization classes that will be covered include:

  • The ExpectedConditions class
  • The WebDriverWait/FluentWait classes
  • Custom synchronization class: wrapping ExpectedConditions...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • 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

Description

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.

Who is this book 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 23, 2018
Length: 354 pages
Edition : 1st
Language : English
ISBN-13 : 9781788473576
Vendor :
Selenium
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jan 23, 2018
Length: 354 pages
Edition : 1st
Language : English
ISBN-13 : 9781788473576
Vendor :
Selenium
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 573.97
Selenium Framework Design in Data-Driven Testing
zł197.99
Selenium WebDriver 3 Practical Guide
zł177.99
Mastering Selenium WebDriver 3.0
zł197.99
Total $ 573.97 Stars icon

Table of Contents

10 Chapters
Building a Scalable Selenium Test Driver Class for Web and Mobile Applications Chevron down icon Chevron up icon
Selenium Framework Utility Classes Chevron down icon Chevron up icon
Best Practices for Building Selenium Page Object Classes Chevron down icon Chevron up icon
Defining WebDriver and AppiumDriver Page Object Elements Chevron down icon Chevron up icon
Building a JSON Data Provider Chevron down icon Chevron up icon
Developing Data-Driven Test Classes Chevron down icon Chevron up icon
Encapsulating Data in Data-Driven Testing Chevron down icon Chevron up icon
Designing a Selenium Grid Chevron down icon Chevron up icon
Third-Party Tools and Plugins Chevron down icon Chevron up icon
Working Selenium WebDriver Framework Samples Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(13 Ratings)
5 star 69.2%
4 star 7.7%
3 star 15.4%
2 star 7.7%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Susheel Gawande Feb 22, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very well written for someone who is beginning to learn working on Selenium as well as advancing to refining and enhancing knowledge. It presents a good information recipe to accomplish the Selenium Framework Design in Data-Driven Testing. I am highly recommending this book.
Amazon Verified review Amazon
MobileMojo Feb 17, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Fantastic technical resource by an industry expert in building Web and mobile test automation frameworks! The book takes a logical approach to designing Selenium frameworks and covers every aspect along the way. The code samples are essential! No other book offers the coverage this one does, just buy it!
Amazon Verified review Amazon
KT Feb 16, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is really helpful. Data driven testing model makes more sense to me. I like the DRY (Don't Repeat Yourself) approach. The downloadable code samples as well as those in print are clearly commented/documented, which is a big help.
Amazon Verified review Amazon
RAJ Jun 14, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is for someone who actually knows webdriver and java and who wish to develop a framework, this is not for beginners
Amazon Verified review Amazon
Alexey Solovyev Aug 29, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
For me, this book turned out to be a logical and expected continuation of another book "Learning Selenium" from the same publisher. In the same book, information is presented in a clear and understandable form. Everything is described: from creating the first classes to set up a ready-made data-driven test framework. Everything is in demand, everything is needed and everything is on business. I am happy to apply the knowledge from the book in my work! Thank's to the author!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.

Modal Close icon
Modal Close icon