34,79 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 352
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2015
Production reference: 1261015
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-251-2
www.packtpub.com
Author
Unmesh Gundecha
Reviewers
Alexander Afanasyev
Anuj Chaudhary
Oliver Gondža
Vatsala Dorairajan
Acquisition Editor
Tushar Gupta
Content Development Editor
Kirti Patil
Technical Editor
Rupali R. Shrawane
Copy Editor
Vatsal Surti
Project Coordinator
Nidhi Joshi
Proofreader
Safis Editing
Indexer
Tejal Daruwale Soni
Graphics
Jason Monteiro
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
Unmesh Gundecha has a master's degree in software engineering and over 13 years of experience in software development and testing. He has architected functional test automation projects using industry-standard, in-house, and custom test automation frameworks, along with leading commercial and open source test automation tools. Presently, he is working as a test architect for a multinational company in Pune, India. Unmesh has also authored a book called Learning Selenium Testing Tools with Python, Packt Publishing.
Alexander Afanasyev is currently a Python developer and architect and a QA automation lead at Avenues International Inc. This is a data and analytics company that provides consulting solutions. He has completed his master's of science degree in electronics engineering. He has several years of experience in development and testing at various companies across different sectors, both in Russia and the United States. Alexander has always had a passion for testing, code quality, and web technologies. In his free time, he is likely to be found contributing to StackOverflow or GitHub, reading, or playing the guitar.
I would like to thank Daniel Lyakovetsky for "opening doors," for guidance, and for the confidence that he has shown in me. A huge thank you to my wonderful wife, Anna, and my little daughter, Kate, who have all been a constant source of support.
Anuj Chaudhary is a software engineer who enjoys working on software testing and automation. He has vast experience in different testing methodologies such as manual, automated, performance, and security testing. He has worked as an individual contributor and a technical lead on various software projects dealing with all stages of the application development life cycle.
Anuj has been awarded a Microsoft MVP two times in a row. He posts blogs at www.anujchaudhary.com. He has also reviewed the following books on Selenium:
I would like to thank my wife Renu and son Arjun for always supporting me and letting me spend extra time on reviewing this book.
Oliver Gondža is a Java enthusiast, extreme programmer, OSS contributor, and Red Hatter.
Vatsala Dorairajan is a budding software technologist. She has mostly worked with "ideasmiths," transforming on-paper/in-concept ideas into working prototypes, which in turn have evolved into products. Her technical experience so far has been in Java, Flex, Python, PHP, and Ruby on Rails. She currently works with Jombay, an award-winning talent measurement and analytics company that helps companies hire, promote, and retain the right talent.
Vatsala has also reviewed the book Selenium Testing Tools Starter, Packt Publishing.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
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.
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.
You will need the following software to follow the recipes in this book:
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.
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:
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.
This section contains the steps required to follow the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
This section provides helpful links to other useful information for the recipe.
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:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
Any command-line input or output is written as follows:
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."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
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 <[email protected]>, 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.
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.
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.
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.
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 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 <[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.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In this chapter, we will see how to set up the Selenium WebDriver test development environment. We will also see some basic settings to help get started with Selenium WebDriver. You will learn the following:
Selenium WebDriver has been widely used for automating web browsers in combination with various tools due to its neat and clean object-oriented design. We can integrate Selenium WebDriver with other tools to develop automated tests.
The initial sections of this chapter explore Selenium WebDriver's integration with development and build tools such as Eclipse, Maven, and Microsoft Visual Studio. These tools provide an easy way to develop test automation frameworks and extend the capabilities of Selenium WebDriver API. The following recipes will explain how to set up and configure these tools with Selenium.
Lastly, we will explore how to set up various browser drivers and initial settings for WebDriver.
Apache Ant is a popular build tool available for Java developers. It is similar to Apache Maven, but does not support project management and dependency management features like Maven. It's a pure build tool.
You can run Selenium WebDriver tests using Ant via command line or through continuous integration (CI) tools such as Jenkins.
In this recipe, we will add Ant support to the SeleniumCookbook project created in the Configuring Selenium WebDriver test development environment for Java with Eclipse and Maven recipe.
You can also download and configure Ant from http://ant.apache.org/bindownload.cgi for other OS platforms.
Windows users can download and install WinAnt on Windows. WinAnt comes with an installer that will configure Ant through the installer. The WinAnt installer is available at http://code.google.com/p/winant/.
This recipe uses WinAnt on the Windows OS.
You will also need Selenium WebDriver and JUnit JAR files. You can download Selenium JAR file from http://selenium-release.storage.googleapis.com/ and JUnit JAR file from https://github.com/junit-team/junit/wiki/Download-and-Install.
Let's set up the SeleniumCookbook created in the previous recipe project for Ant with the following steps:
This will trigger the build process. You will see the test running. At the end, Ant will create a report folder in the project folder. Navigate to the html subfolder in the report folder and open the index.html file to view the results.
Ant needs a build.xml file with all the configurations and steps required to build the project. We can add steps for report generation, sending e-mail notification, and so on to build.xml. Ant provides a very dynamic framework for defining steps in the build process.
Ant also needs the necessary library/JAR files to be copied in the lib folder, which are needed for building the project.
Ant scans for the complete set of tests in the project and executes these tests in a way similar to Maven.
Selenium WebDriver provides .NET bindings to develop Selenium tests with the .NET platform. To use the Selenium WebDriver API along with .NET, you need to refer the Selenium WebDriver libraries to the project. Microsoft Visual Studio being the major IDE used in the .NET world, setting up the Selenium WebDriver support has become easier withNuGet Package Manager (http://nuget.org/).
This recipe explains the process of setting up Selenium WebDriver in Microsoft Visual Studio 2013 using NuGet.
NuGet comes bundled with Microsoft Visual Studio 2012 onwards. However, for Microsoft Visual Studio 2010, you will need to download and install NuGet from http://nuget.codeplex.com.
Let's configure Microsoft Visual Studio 2013 to develop Selenium WebDriver tests using the following steps:
