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 <[email protected]>
, 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 <[email protected]>
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 <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.