Selenium WebDriver Practical Guide Interactively automate web applications using Selenium WebDriver Satya Avasarala BIRMINGHAM - MUMBAI Selenium WebDriver Practical Guide Copyright © 2014 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: January 2014 Production Reference: 1170114 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78216-885-0 www.packtpub.com Cover Image by Prashant Timappa Shetty ([email protected]) Credits Author Project Coordinator Satya Avasarala Amey Sawant Reviewers Proofreader Anuj Chaudhary Clyde Jenkins David Askirk Fotel Daniel Lam Indexers Hemangini Bari Ripon Al Wasim Monica Ajmera Mehta Rekha Nair Acquisition Editors Anthony Albuquerque Priya Subramani Richard Harvey Graphics Yuvraj Mannari Lead Technical Editor Priya Singh Abhinash Sahu Technical Editors Production Coordinator Dennis John Aparna Bhagat Venu Manthena Gaurav Thingalaya Cover Work Aparna Bhagat Copy Editors Tanvi Gaitonde Kirti Pai Adithi Shetty About the Author Satya Avasarala has rich experience in Java development and automation testing. He is an engineer in computer science. He has used WebDriver for many years now and has created several good automation frameworks. He has worked at various large software enterprises such as Oracle Corp, Yahoo! Inc., VMware Inc., and the REA Group. In addition, he is also interested in Service Oriented Architectural design and Business Intelligence. He is an Oracle-certified Service Oriented Architecture Infrastructure Implementation Expert and a Business Intelligence Foundation Suite Implementation Specialist. I would like to thank all my acquisition editors, technical editors, and project coordinators for constantly supporting me in completing this book. I should also thank my colleagues, Pratik Patil and Kerri Rusnak, for their constant encouragement and support in writing this book. Last but not least, I would like to thank my wife, Swathi Vennelaganti, for sacrificing many weekends while I was busy writing this book. Without all these people, this book wouldn't have been a reality. About the Reviewers Anuj Chaudhary is a software engineer who enjoys working on software testing and automation. He has a vast experience with various testing methodologies such as manual testing, automated testing, performance testing, and security testing. He has worked as an individual contributor and technical lead on various software projects dealing with all of the stages in the application development life cycle. He has been awarded the title of Microsoft MVP twice in a row. He writes a blog that you can visit at www.anujchaudhary.com. I would like to thank and congratulate the Packt Publishing team for publishing this awesome book. David Askirk Fotel has worked with computers since his parents brought home an old, used IBM PS/2. He started his development career writing simple programs in QBasic and later in Pascal. From there, he moved on to writing programs in C. Later on, he moved on to Java and other languages. His greatest experience so far was with Lisp, which had a great impact on his programming style and approach to code. David has worked on test-driven development and as a test manager, implementing Selenium tests on an e-learning system. This book is the first on which David has worked, but will not be the last! Daniel Lam is an Agile Test Developer with experience in open and closed source test tools. He specializes in Java, Selenium WebDriver, Continuous Integration, and BDD test frameworks. Ripon Al Wasim is a software engineer living in Dhaka, Bangladesh. He has 12 years' experience in the software industry, three years in software development, and nine years in software testing (both manual and automated). He has also been involved in conducting software testing courses in various companies. He has worked for clients in various countries such as Japan, USA, Finland, Norway, and Bangladesh. Ripon started participating in posting professional questions and answers on Stack Overflow in the year 2011 at http://stackoverflow.com/users/617450/ripon- al-wasim. Ripon is a Sun Certified Java Programmer (SCJP). He is Japanese Language Proficiency Test (JLPT) Level 3 certified, and is a little familiar with Japanese culture, as he stayed in Japan for one year as an IT professional. This book is Ripon's first official effort. I would like to thank my mother and wife for fostering a helping and inspiring environment at home so I could study and review. I am also deeply thankful and grateful to Cefalo Amravi Ltd. (http://cefalo.com/en), my current company, for providing me a good opportunity to work with automated testing using Selenium WebDriver. I would like to thank Yves Hwang, Product Manager at Varnish Software (https://www.varnish-software.com/) and Partha Guha Roy, CTO of Cefalo Amravi Ltd. for providing technical assistance during my project work. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. 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. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Introducing WebDriver and WebElements 9 Understanding the history of Selenium 9 Selenium 1 or Selenium Remote Control or Selenium RC 9 Selenium 2 or Selenium WebDriver or WebDriver 12 Differences between Selenium 1 and Selenium 2 13 Handling the browser 14 Having better APIs 14 Testing mobile apps 14 Having developer support and advanced functionalities 14 Setting up a project in Eclipse 15 WebElements 20 Locating WebElements using WebDriver 21 The findElement() method 21 The findElements() method 22 Firebug 22 Using the By locating mechanism 23 Actions on WebElements 32 The getAttribute() method 32 The sendKeys() method 33 The clear() method 34 The submit() method 35 The getCssValue() method 36 The getLocation() method 37 The getSize() method 38 The getText() method 38 The getTagName() method 39 The isDisplayed() method 40 The isEnabled() method 41 The isSelected() method 41 Summary 42
Description: