20,56 €
Selenium is a suite of tools to automate web application testing across many platforms. A strong understanding of using Selenium will get you developing tests to ensure the quality of your applications.
This book helps you understand and use Selenium to create tests and make sure that what your user expects to do can be done. It will guide you to successfully implement Selenium tests to ensure the quality of your applications.
The Selenium Testing Tools Beginner's guide shows developers and testers how to create automated tests using a browser. You'll be able to create tests using Selenium IDE, Selenium Remote Control and Selenium 2 as well. A chapter is completely dedicated to Selenium 2. We will then see how our tests use element locators such as css, xpath, DOM to find elements on the page.
Once all the tests have been created we will have a look at how we can speed up the execution of our tests using Selenium Grid.
A beginner's guide to writing Selenium tests using different aspects of the Framework to give you confidence in your web application
Written with a fast-paced but friendly and engaging approach, this Packt Beginner's Guide is designed to be placed alongside the computer as your guide and mentor. Step-by-step tutorials are bolstered by explanations of the reasoning behind what you are doing. You will quickly pick up the necessary skills, tips, and tricks for creating successful tests for your web applications with practical examples that help you to learn by experiment and play.
If you are a Software quality assurance professional, software project manager, or software developer interested in developing automated testing in web based applications, then this book is definitely for you.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 268
Veröffentlichungsjahr: 2010
Copyright © 2010 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: November 2010
Production Reference: 1171110
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849510-26-4
www.packtpub.com
Cover Image by Duraid Fatouhi (<[email protected]>)
Author
David Burns
Reviewers
Tarun Kumar Bhadauria
Sameer Borate
Acquisition Editor
Usha Iyer
Development Editors
Neha Mallik
Rakesh Shejwal
Technical Editor
Aaron Rosario
Copy Editor
Lakshmi Menon
Indexer
Tejal Daruwale
Editorial Team Leader
Aanchal Kumar
Project Team Leader
Priya Mukherji
Project Coordinator
Zainab Bagasrawala
Proofreader
Mario Cecere
Graphics
Nilesh Mohite
Geetanjali Sawant
Production Coordinator
Melwyn D'sa
Cover Work
Melwyn D'sa
David Burns is a Senior Developer in Test having worked with Selenium for quite a few years. David is a Selenium Core Committer, so he knows and understands what users and developers want from the framework.
I would like to thank my wife for supporting me while I was writing my book and making sure I did things on time.
I would also like to thank the other Selenium Committers for answering my questions and cheering me on to finish the book.
Tarun Kumar Bhadauria is an Electronics Engineer and hails from Gwalior. He has been involved with software testing for over five years. He spent most of his career with QA practices for the Indian division of CIBER. He is currently associated with Tavant Technologies Bangalore. He has worked on a gamut of testing fields that encompasses Manual Testing, Performance Testing and Functional Test Automation using both commercial and open source tools. His primary inclination has been towards functional test automation using Selenium.
Tarun has been key contributor to Official Selenium Documentation and was recognized as co-author for Selenium documentation release 1.0 by Selenium Head Quarters.
His spare moments are spent in exercise and blogging.
Sameer Borate is an independent web developer based in Pune, India. He has been developing web applications using PHP and MySQL since 2000, when PHP was just a blip on the web radar, and now spends most of his time working with XHTML, PHP, XML, MySQL, and JavaScript. For the last few years he has been helping small companies design web application architectures for their clients. In his free time he likes to peruse non-fiction books.
He regularly blogs about web development at www.codediesel.com.
I would like to thank my wife for her support in all of my different endeavors, even at times when they were impractical. Also thanks to Packt Publishing for providing me with this great learning opportunity. And finally thanks to the Open Source community for making all of this possible.
The Selenium 1.0 Testing Tools Beginner's guide shows developers and testers how to create automated tests using a browser. You'll be able to create tests using Selenium IDE, Selenium Remote Control and Selenium 2 as well. A chapter is completely dedicated to Selenium 2. We will then see how our tests use element locators such as CSS, XPath, and DOM to find elements on the page.
Once all the tests have been created we will have a look at how we can speed up the execution of our tests using Selenium Grid.
Chapter 1, Getting started with Selenium IDE: In this chapter we will have a look at installing Selenium IDE and recording our first tests. We will see what is needed to work against AJAX applications.
Chapter 2, Locators: In this chapter we will see how we can find elements on the page to be used in our tests. We will use XPath, CSS, Link Text, and ID to find elements on the page so that we can interact with them.
Chapter 3, Pattern Matching: In this chapter we will have a look at using regular expressions, globbing, and then using the exact text to find elements or test text on the page.
Chapter 4, Using JavaScript: Sometimes it is good to inject JavaScript into the page to improve its testability. There are frameworks that people are using within web applications that don't allow Selenium direct access, so this chapter will explain what we need to do in such cases.
Chapter 5, User-Extensions and Add-ons: This chapter will show us how we can create our own Selenium commands that can be used within Selenium IDE. We will also have a look at creating Add-ons for Selenium IDE to expand the functionality of the Selenium IDE.
Chapter 6, First Steps with Selenium RC: In this chapter we will see how we can set up Selenium Remote Control. We can start running our Selenium IDE tests against browsers that we haven't used yet.
Chapter 7, Creating Selenium Remote Control Tests: In the previous chapter we had a look at getting our tests running against different browsers. This chapter goes one step further so we can convert our IDE tests to use a programming language. We also have a look at some good practices and how to integrate with a CI Server.
Chapter 8, Advanced Selenium Techniques: In this chapter we will have a look at how we can do cookie handling within our tests. We will also have a look at how we can create our own locator strategies for find elements on the page. We then move to capturing network traffic between the browser and the web server. We finish off capturing screenshots and video.
Chapter 9, Getting started with Selenium Grid: This chapter shows us how we can set up our Selenium Grid. Selenium Grid is a very good infrastructural tool for managing Selenium Remote Control instances so we run tests against it.
Chapter 10, Running Selenium Tests in parallel: Selenium tests generally run sequentially. This chapter demonstrates how we can use TestNG to run our tests in parallel to take full advantage of Selenium Grid.
Chapter 11, Getting started with Selenium 2: This chapter will help explain the merger of Selenium and WebDriver to create Selenium 2. It explains how the interaction with the browser has changed and how we can convert our Selenium 1 tests to Selenium 2 in order to take advantage of these changes. Finally, we have a look at how executing JavaScript has changed.
If you are a software quality assurance professional, software project manager, or software developer interested in developing automated testing in web-based applications, then this book is definitely for you.
In this book, you will find several headings appearing frequently.
To give clear instructions of how to complete a procedure or task, we use:
Instructions often need some extra explanation so that they make sense, so they are followed with:
This heading explains the working of tasks or instructions that you have just completed.
You will also find some other learning aids in the book, including:
These are short multiple choice questions intended to help you test your own understanding.
These set practical challenges and give you ideas for experimenting with what you have learned.
You will also 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: "We can include other contexts through the use of the include directive."
A block of code is set 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, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".
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 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 via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.
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.
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 erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
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.
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.
Test automation has grown in popularity over the years because teams do not have the time or money to invest in large test teams to make sure that applications work as they are expected to. Developers also want to make sure that the code they have created works as they expect it to.
Developers use a multitude of different testing frameworks to test different aspects of the system. Selenium is one of the most well-known testing frameworks in the world that is in use. It is an open source project that allows testers and developers alike to develop functional tests to drive the browser. It can be used to record workflows so that developers can prevent future regressions of code. Selenium can work on any browser that supports JavaScript since Selenium has been built using JavaScript.
In this chapter, we will cover the following topics:
So let's get on with it...
Before we start working through this chapter you need to make sure that Mozilla Firefox is installed on your machine. If you do not have Mozilla Firefox installed, you will need to download it from http://www.getfirefox.com/.
Selenium IDE is a Firefox add-on developed originally by Shinya Kasatani as a way to use the original Selenium Core without having to copy Selenium Core onto the server. It has been developed using JavaScript so that it can interact with DOM (Document Object Model) using native JavaScript calls.
Selenium IDE was developed to allow testers and developers to record their actions as they follow the workflow that they need to test.
Now that we understand what Selenium IDE is, it is a good time to install the Selenium IDE. By the end of these steps, you will have successfully installed the Selenium IDE on your computer.
You have successfully installed Selenium IDE, and we can now start thinking about writing our first test.
Selenium IDE has been installed, so let's take some time to familiarize ourselves with it. This will give us the foundation that we can use in later chapters.
Open up Selenium IDE by going through the Tools menu in Mozilla Firefox. The steps are Tools | Selenium IDE. The window that will appear should be similar to the next screenshot.
Starting from the top, I will explain what each of the items is:
Now that we have installed Selenium IDE and understood what it is, we can think about working through our first tests. There are a few things that you need to consider when creating your first test. These rules apply to any form of test automation but need to be adhered to especially when creating tests against a User Interface.
These rules, like most rules, can be broken. However, breaking them can mean that you may run into issues later on, and when you have hundreds or even thousands of tests, these small issues can mean that large parts of a test suite are red.
With these rules in mind, let us create our first Selenium IDE test.
We are going to record our first test using Selenium IDE. To start recording the tests, we will need to start Mozilla Firefox. Once it has been loaded, you will need to start the Selenium IDE. You will find it under the Tools menu in Mozilla Firefox. Note that the record button is engaged when you first load the IDE.
To start recording your tests:
