Book Image

Selenium Testing Tools Cookbook

By : UNMESH GUNDECHA
Book Image

Selenium Testing Tools Cookbook

By: UNMESH GUNDECHA

Overview of this book

Web technologies are becoming increasingly complex and there is a need to test your web applications against a vast number of browsers and platforms, so you need to build highly reliable and maintainable test automation. This book will help you test your web applications effectively and efficiently with Selenium WebDriver."Selenium Testing Tools Cookbook" is an incremental guide that will help you learn and use advanced features of Selenium WebDriver API in various situations for building reliable test automation. You will learn how to effectively use features of Selenium using simple and detailed examples. This book will also teach you best practices, design patterns, and how to extend Selenium."Selenium Testing Tools Cookbook" shows developers and testers who already use Selenium, how to go to the next step and build a highly maintainable and reliable test framework using advanced features of the tool.The book starts with tips on advanced location strategy and effective use of Selenium WebDriver API. Then it demonstrates the use of design patterns such as Data Driven Tests and PageFactory for building maintainable test automation. It also explains extending Selenium WebDriver API along with implementing custom tasks and setting up your own distributed environment to run tests in parallel.It concludes with tips on integrating Selenium WebDriver with other popular tools, testing mobile web applications, and capturing videos of test runs. This books provides examples in Java, C#, Ruby, and Python."Selenium Testing Tools Cookbook" will help you in building a highly robust and maintainable test automation framework from start to finish.
Table of Contents (18 chapters)
Selenium Testing Tools Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

This book will help you in learning advanced techniques for testing web applications with 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.

This book covers design patterns such as data-driven testing, page objects, and object map for designing a highly maintainable and reliable test automation framework. You will also learn how to integrate Selenium WebDriver with Behavior-driven Development frameworks such as Cucumber-JVM, SpecFlow.NET, and Capybara.

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

What this book covers

Chapter 1, Locating Elements, introduces you to locator techniques supported by Selenium WebDriver, for locating elements on pages in your web applications. Selenium WebDriver provides one of the advanced techniques for locating elements on web pages with multiple locator strategies such as XPath, CSS, and DOM. We can also implement custom locator strategies for locating elements. This chapter will also help you in getting started with Selenium WebDriver locator API.

Chapter 2, Working with Selenium API, demonstrates how to use Selenium WebDriver API for building tests. We will explore API and investigate advanced user interactions for performing complex mouse and keyboard operations, working with various types of UI elements used in web applications.

Chapter 3, Controlling the Test Flow, demonstrates how to use Selenium WebDriver API for building a reliable test automation framework. The tenants of good test automation are robustness, reliability, recovery from unexpected events, and unhandled execution. This chapter covers recipes on handling synchronization with implicit and explicit waits, multiple windows, and pop-ups and alerts that are displayed during the test execution.

Chapter 4, 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 Selenium WebDriver API to support data-driven testing. This chapter covers recipes to support data-driven testing using JUnit/Apache POI and JDBC technologies.

Chapter 5, Using the Page Object Model, introduces the Page Object model pattern, which is widely used for structuring Selenium WebDriver tests. This chapter provides tips on building testing frameworks using Page Object model.

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

Chapter 7, Testing on Mobile Browsers, introduces you to testing mobile web applications with the Apple iOS and Android platform. This chapter covers recipes for configuring and using Selenium WebDriver to test a mobile application on the iPhone and Android based devices/simulators.

Chapter 8, Client-side Performance Testing, demonstrates how to measure client-side performance with Selenium WebDriver. Client-side performance can be measured in different ways with Selenium WebDriver. We can use tools such as dynaTrace and HttpWatch, along with Selenium WebDriver to collect, measure, and monitor client-side performance of web applications.

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

Chapter 10, Recording Videos of Tests, briefly describes how to record videos of test runs using tools such as Monte Media Library in Java, Microsoft Expression Encode SDK in .NET, and Castro in Python.

Chapter 11, Behavior-driven Development, introduces Behavior-driven Development with Selenium WebDriver using tools such as Cucumber-JVM, JBehave for Java, SpecFlow.NET for .NET, and Capybara for Ruby.

Integration with Other Tools, demonstrates how to set up Selenium WebDriver with Eclipse and IntelliJ IDEA. We will also set up Maven and ANT along with Selenium WebDriver and Jenkins for running tests in Continuous Integration. This chapter also covers recipes for using tools such as AutoIt and Sikuli for testing non-web UI.

This chapter is not present in the book but is available as a free download from http://www.packtpub.com/sites/default/files/downloads/Integration_with_Other_Tools.pdf.

Distributed Testing with Selenium Grid, demonstrates how to set up a distributed test environment with Selenium Grid. We will add nodes with various browser and operating system combinations. We will run tests in parallel using TestNG, which helps in reducing the time of test execution and increases the test coverage.

This chapter is not present in the book but is available as a free download from http://www.packtpub.com/sites/default/files/downloads/Distributed_Testing_with_Selenium_Grid.pdf.

What you need for this book

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

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

  • Selenium browser drivers: Chrome Driver, InternetExplorer Driver

  • Selenium tools: 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, JBehave (for Java), SpecFlow.NET (for .NET), and Capybara (for Ruby)

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

  • Performance tools: dynaTrace AJAX Edition, HttpWatch, and BrowserMob Proxy

  • Other tools: AutoIt and Sikuli

  • Video capture tools: Monte Media Library (for Java), Microsoft Expression Encoder SDK (for .NET), and Castro (for Python)

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

  • Language runtimes: JDK 1.6 (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, or software developers with prior experience in using Selenium and Java for testing web-based applications. This book also provides examples for C#, Python, and Ruby users.

Conventions

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

Code words in text are shown as follows: "The WebElement class also supports find methods to find child elements."

A block of code is set as follows:

<form name="loginForm">
    <label for="username">UserName: </label> <input type="text" class="username" /></br>
    <label for="password">Password: </label> <input type="password" class="password" /></br>
    <input name="login" type="submit" value="Login" />
</form>

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

//Locate all the Checkbox which are checked by calling jQuery //find() method. 
//find() method returns elements in array
List<WebElement> elements = (List<WebElement>) js.executeScript("return jQuery.find(':checked')");

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

mvn clean test

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Right-click to open the pop-up menu and select the Inspect element option."

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 may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through 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 on 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 for all Packt books you have purchased from your account at http://www.packtpub.com. 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.

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 would 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/support, 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.

Piracy

Piracy of copyright 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

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.