Book Image

Selenium Testing Tools Cookbook

By : UNMESH GUNDECHA
5 (1)
Book Image

Selenium Testing Tools Cookbook

5 (1)
By: UNMESH GUNDECHA

Overview of this book

This book is an incremental guide that will help you learn and use the advanced features of the Selenium toolset including the WebDriver API in various situations to build a reliable test automation. You start off by setting up the test development environment and gain tips on the advanced locater strategy and the effective use of the Selenium WebDriver API. After that, the use of design patterns such as data - driven tests and PageFactory are demonstrated. You will then be familiarised with extending Selenium WebDriver API by implementing custom tasks and setting up your own distributed environment to run tests in parallel for cross-browser testing. Finally, we give you some tips on integrating Selenium WebDriver with other popular tools and testing mobile applications. By the end of this book, you will have learned enough to solve complex testing issues on your own.
Table of Contents (21 chapters)
Selenium Testing Tools Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Selenium is a set of tools used to automate browsers. It is largely used to test applications, but its usages are not limited to testing. It can also be used to perform screen scraping and automate repetitive tasks in a browser window. Selenium supports automation on all the major browsers, including Firefox, Internet Explorer, Google Chrome, Safari, and Opera. Selenium WebDriver is now a part of W3C standards and is supported by major browser vendors.

This book will help you learn advanced techniques to test web applications using the Selenium WebDriver API and related tools. In this book, you will learn how to test web applications effectively and efficiently with Selenium WebDriver on desktops, mobile web browsers, and in a distributed environment.

Along with the core features of Selenium WebDriver, this book also covers design patterns such as data-driven testing, page objects, and object maps, to design a highly maintainable and reliable test automation framework. You will also learn how to integrate Selenium WebDriver with ATDD/BDD, build and continuous integration tools, and perform mobile web testing with Appium.

This book also covers techniques to extend Selenium for your specific needs. There are more than 80 recipes that you can use to build or extend your existing test automation framework.

What this book covers

Chapter 1, Getting Started, demonstrates how to set up Selenium WebDriver with Eclipse, Maven, or ANT for test development on a Java platform. Then it shows how to set up Visual Studio, Ruby, and Python for test development. This chapter also shows how to set up various browsers for testing.

Chapter 2, Finding Elements, introduces you to the locator techniques supported by Selenium WebDriver to find elements on pages in your web applications. Selenium WebDriver provides a number of techniques to find elements on web pages with multiple locator strategies such as XPath, CSS, and DOM. We can also implement custom locator strategies to locate elements. This chapter will also help you get started with the Selenium WebDriver locator API.

Chapter 3, Working with Elements, demonstrates how to use the Selenium WebDriver API to automate interaction with various types of UI elements used in web applications, including textboxes, buttons, dropdowns, radio buttons, checkboxes, and tables.

Chapter 4, Working with Selenium API, demonstrates how to use the Selenium WebDriver API to build tests. We will explore the API and investigate advanced user interactions to perform complex mouse and keyboard operations and work with various types of UI elements used in web applications.

Chapter 5, Synchronizing Tests, demonstrates how to use the Selenium WebDriver API to handle synchronization with implicit and explicit waits to implement robust and reliable tests.

Chapter 6, Working with Alerts, Frames and Windows, demonstrates how to handle multiple windows, pop-ups, and alerts that are displayed during test execution.

Chapter 7, Data-Driven Testing, introduces the data-driven testing approach—a widely used methodology in test automation. Selenium WebDriver does not have built-in features to support data-driven testing. However, we can extend the Selenium WebDriver API to support data-driven testing. This chapter covers recipes to support data-driven testing using JUnit, TestNG, and Apache POI to read data from spreadsheets.

Chapter 8, Using the Page Object Model, introduces the Page Object model pattern, which is widely used for structuring Selenium WebDriver tests. This chapter provides examples and tips on how to build testing frameworks using the Page Object model pattern.

Chapter 9, Extending Selenium, demonstrates how to extend the Selenium WebDriver API and add features to build a scalable test automation framework. This chapter covers some of the important recipes in extending Selenium WebDriver for various practical scenarios such as to support custom UI controls, capture images of elements, and perform image-based verifications.

Chapter 10, Testing HTML5 Web Applications, introduces you to using Selenium WebDriver to test web applications using the HTML5 standard. This chapter explains how to test video and canvas elements and the web storage API of HTML5.

Chapter 11, Behavior-Driven Development, introduces behavior-driven development with Selenium WebDriver, using tools such as Cucumber-JVM, SpecFlow.NET for .NET, Behave for Python, and Capybara for Ruby.

Chapter 12, Integration with Other Tools, demonstrates how to set up Selenium WebDriver with Jenkins to run tests in Continuous Integration using Maven and ANR. This chapter also covers recipes to use tools such as AutoIt and Sikuli to test non-web UI.

Chapter 13, Cross-Browser Testing, demonstrates how to set up a distributed test environment with Selenium Grid for cross-browser testing. We will add nodes with various browser and operating system combinations. We will run tests in parallel using TestNG, which helps to reduce the time of test execution and increases test coverage. This chapter also covers how to use cloud-based services, such as Sauce Labs and BrowserStack, for cross browser testing.

Chapter 14, Testing Applications on Mobile Browsers, introduces you to testing mobile web applications with the Apple iOS and Android platforms using Appium. This chapter covers recipes to configure and use Selenium WebDriver to test a mobile web application on iPhone and Android-based devices/simulators.

What you need for this book

You will need the following software to follow the recipes in this book:

  • Browsers: Mozilla Firefox, Google Chrome, or Microsoft Internet Explorer

  • Selenium browser drivers: Chrome Driver and InternetExplorerDriver

  • Selenium tools: The Selenium WebDriver client driver (based on your preference of programming language) and Selenium Standalone Server

  • IDE: Eclipse, IntelliJ IDEA, and Microsoft Visual Studio (for .NET)

  • BDD framework tools: Cucumber-JVM, SpecFlow.NET (for .NET), and Capybara (for Ruby)

  • Build and integration tools: Maven, ANT, and Jenkins

  • Other GUI automations tools: AutoIt and Sikuli

  • Mobile tools: Apple Xcode (for iOS mobile browser testing), Android SDK, Android Server APK, and Appium

  • Language runtimes: JDK 1.7 or JDK 1.8 (for Java), Ruby 1.9+ (for Ruby), and Python 2.7+ (for Python)

Who this book is for

This book is for software quality assurance/testing professionals, test managers, and software developers with prior experience in using Selenium and Java to test web-based applications.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning:

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "This will open the pom.xml file in the editor area."

A block of code is written as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

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

  <artifactId>SeleniumCookbook</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>

Any command-line input or output is written as follows:

gem install selenium-webdriver

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Select the Create a simple project (skip archetype selection) checkbox."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/SeleniumTestingToolsCookbookSecondEdition_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.