Learning Selenium Testing Tools with Python

Browsing the Selenium WebDriver Python documentation

A practical guide on automated web testing with Selenium using Python

Unmesh Gundecha


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 2.00 USD
 Pages
 216 p
 File Size
 4,113 KB
 File Type
 PDF format
 ISBN
 978-1-78398-350-6
 Copyright   
 2014 Packt Publishing 

About the Author
Unmesh Gundecha has a Master's degree in Software Engineering and over 12 years of experience in software development and testing. Unmesh has architected functional test automation solutions using industry standards, in-house and custom test automation frameworks along with leading commercial and open source test automation tools.
He has development experience in Microsoft technologies and Java. He is presently working as a test solution architect with a multinational company in Pune, India.
His experience includes support to Ruby, Java, iOS, Android, and PHP projects as an automated tester and software developer.
He authored Selenium Testing Tools Cookbook, Packt Publishing in November 2012.
_____________________________________
I would like to thank Neha Nagwekar, acquisition editor, for giving me an opportunity to write this book; Athira Laji, content development editor; Harshal Ved, project coordinator, for constantly supporting and encouraging me in completing this book; and the entire team at Packt Publishing.
This book has benefited a lot from a great team of technical reviewers. I'd like to thank each of them for volunteering their time reviewing the drafts of this book and providing valuable feedback. I would also like to thank my mentor and friend, Yuri Weinstein, for his support and help during this project. Thanks to my friends and colleagues at work for their constant encouragement and support in writing this book.
_____________________________________

About the Reviewers
Adil Imroz is a Python enthusiast who loves the simplicity of this beautiful language. He is a software developer in testing by profession and a mobile automation expert. He likes playing around with open source software and believes in being agile. When not working, he can be found biking, reading a book, or sleeping. He believes that there is a lot of scope around; all you have to do is hit the right chords. You can get in touch with him via e-mail at alam.adil12@gmail.com. You can also follow him on Twitter at @adilimroz.

Dr. Philip Polstra (known to his friends as Dr. Phil) is an internationally recognized hardware hacker. His work has been presented at numerous conferences around the globe, including repeat performances at DEFCON, Black Hat, 44CON, Maker Faire, and other top conferences. Dr. Polstra is a well-known expert on USB forensics and has published several articles on this topic.

Recently, Dr. Polstra has developed a penetration testing Linux distribution, known as The Deck, for the BeagleBone and BeagleBoard family of small computer boards. He has also developed a new way of performing penetration testing with multiple low-power devices, including an aerial hacking drone. This work is described in his book Hacking and Penetration Testing with Low Power Devices, Syngress Media (2014). Dr. Polstra has also been a technical reviewer on several books, including BeagleBone Home Automation by Juha Lumme and BeagleBone for Secret Agents by Josh Datko, both published in 2014 by Packt Publishing.

Dr. Polstra is an Associate Professor at Bloomsburg University of Pennsylvania (http://bloomu.edu/digital_forensics), where he teaches digital forensics among other topics. In addition to teaching, he provides training and performs penetration tests on a consulting basis. When not working, he is known to fly, build aircraft, and tinker with electronics. His latest happenings can be found on his blog at http://philpolstra.com. You can also follow him on Twitter at @ppolstra.
Walt Stoneburner is a software architect with over 25 years of commercial application development and consulting experience. His fringe passions involve quality assurance, configuration management, and security. If cornered, he may actually admit to liking statistics and authoring documentation as well.
He's easily amused by programming language design, collaborative applications, big data, knowledge management, data visualization, and ASCII art. A self-proclaimed closet geek, Walt also evaluates software products and consumer electronics, draws cartoons, runs a freelance photography studio specializing in portraits and art (http://charismaticmoments.com/), writes humor pieces, performs sleight of hand, enjoys game designing, and can occasionally be found on ham radio.
Walt can be reached directly via e-mail at wls@wwco.com or Walt.Stoneburner@gmail.com. He publishes a tech and humor blog called Walt-O-Matic at
His other book reviews and contributions include the following:
•AntiPatterns and Patterns in Software Configuration Management, John Wiley & Sons (ISBN 978-0471329299, p. xi)
•Exploiting Software: How to Break Code, Pearson Education (ISBN 978-0-201-78695-8, p. xxxiii)
•Ruby on Rails Web Mashup Projects, Packt Publishing (ISBN 978-1847193933)
•Building Dynamic Web 2.0 Websites with Ruby on Rails, Packt Publishing (ISBN 978-1-847193-41-4)
•Instant Sinatra Starter, Packt Publishing (ISBN 978-1782168218)
•C++ Multithreading Cookbook, Packt Publishing (ISBN 978-1-78328-979-0)
•Trapped in Whittier (A Trent Walker Thriller Book 1), Amazon Digital South Asia Services, Inc. (ASIN B00GTD1RBS)
•South Mouth: Hillbilly Wisdom, Redneck Observations & Good Ol' Boy Logic, CreateSpace Independent Publishing Platform (ISBN 978-1-482340-99-0)

Yuri Weinstein lives in San Francisco, CA with his family. He has spent over two decades working for top technology companies in the Silicon Valley, focusing on software testing with a special passion for test automation techniques. He currently works at Red Hat, ensuring the quality of the Ceph open source storage project.

Table of Contents
Preface 1
Chapter 1: Getting Started with Selenium WebDriver and Python 7
Preparing your machine 8
Installing Python 8
Installing the Selenium package 8
Browsing the Selenium WebDriver Python documentation 9
Selecting an IDE 10
PyCharm 10
The PyDev Eclipse plugin 12
PyScripter 13
Setting up PyCharm 15
Taking your first steps with Selenium and Python 18
Cross-browser support 23
Setting up Internet Explorer 23
Setting up Google Chrome 26
Summary 27
Chapter 2: Writing Tests Using unittest 29
The unittest library 29
The TestCase class 31
The setUp() method 32
Writing tests 32
Cleaning up the code 33
Running the test 34
Adding another test 36
Class-level setUp() and tearDown() methods 37
Assertions 38
Test suites 40
Generating the HTML test report 43
Summary 44
Chapter 3: Finding Elements 45
Using developer tools to find locators 47
Inspecting pages and elements with Firefox using the Firebug add-in 47
Inspecting pages and elements with Google Chrome 49
Inspecting pages and elements with Internet Explorer 50
Finding elements with Selenium WebDriver 51
Using the find methods 52
Finding elements using the ID attribute 54
Finding elements using the name attribute 55
Finding elements using the class name 56
Finding elements using the tag name 57
Finding elements using XPath 58
Finding elements using CSS selectors 60
Finding links 61
Finding links with partial text 62
Putting all the tests together using find methods 63
Summary 66
Chapter 4: Using the Selenium Python API for Element
Interaction 67
Elements of HTML forms 68
Understanding the WebDriver class 68
Properties of the WebDriver class 69
Methods of the WebDriver class 69
Understanding the WebElement class 71
Properties of the WebElement class 72
Methods of the WebElement class 72
Working with forms, textboxes, checkboxes, and radio buttons 73
Checking whether the element is displayed and enabled 74
Finding the element attribute value 75
Using the is_selected() method 76
Using the clear() and send_keys() methods 76
Working with dropdowns and lists 79
Understanding the Select class 80
Properties of the Select class 81
Methods of the Select class 81
Working with alerts and pop-up windows 84
Understanding the Alert class 84
Properties of the Alert class 84
Methods of the Alert class 84
Automating browser navigation 87
Summary 89
Chapter 5: Synchronizing Tests 91
Using implicit wait 91
Using explicit wait 93
The expected condition class 94
Waiting for an element to be enabled 97
Waiting for alerts 98
Implementing custom wait conditions 99
Summary 100
Chapter 6: Cross-browser Testing 101
The Selenium standalone server 102
Downloading the Selenium standalone server 103
Launching the Selenium standalone server 103
Running a test on the Selenium standalone server 105
Adding support for Internet Explorer 108
Adding support for Chrome 108
Selenium Grid 108
Launching Selenium server as a hub 109
Adding nodes 111
Adding an IE node 111
Adding a Firefox node 112
Adding a Chrome node 113
Mac OS X with Safari 113
Running tests in Grid 114
Running tests in a cloud 116
Using Sauce Labs 117
Summary 120
Chapter 7: Testing on Mobile 121
Introducing Appium 121
Prerequisites for Appium 122
Setting up Xcode for iOS 123
Setting up Android SDK 124
Setting up the Appium Python client package 125
Installing Appium 125
Appium Inspector 128
Testing on iOS 128
Writing a test for iOS 129
Testing on Android 131
Writing a test for Android 132
Using Sauce Labs 135
Summary 137
Chapter 8: Page Objects and Data-driven Testing 139
Data-driven testing 140
Using ddt for data-driven tests 140
Installing ddt 141
Creating a simple data-driven test with ddt in unittest 141
Using external data sources for data-driven tests 143
Reading values from CSV 143
Reading values from Excel 145
The page objects pattern 148
Organizing tests 149
The BasePage object 150
Implementing page objects 151
Creating a test with page objects 155
Summary 156
Chapter 9: Advanced Techniques of Selenium WebDriver 157
Methods for performing keyboard and mouse actions 157
Keyboard actions 160
The mouse movement 162
The double_click method 163
The drag_and_drop method 164
Executing JavaScript 164
Capturing screenshots of failures 167
Recording a video of the test run 169
Handling pop-up windows 171
Managing cookies 174
Summary 176
Chapter 10: Integration with Other Tools and Frameworks 177
Behavior-Driven Development 178
Installing Behave 178
Writing the first feature in Behave 178
Implementing a step definition file for the feature 179
Creating environment configurations 181
Running features 181
Using a scenario outline 182
CI with Jenkins 184
Preparing for Jenkins 184
Setting up Jenkins 185
Summary 192
Index 193

Bookscreen
e-books shop

Introduction
What this book covers
Chapter 1, Getting Started with Selenium WebDriver and Python, starts with installing
Python and the Selenium WebDriver client library. We will select a Python editor
or IDE for Selenium script development. We will then create our first automation
script for a simple search workflow from the application under test. At the end of this
chapter, we will run the Selenium script on various browsers supported by Selenium.
Chapter 2, Writing Tests Using unittest, shows you how to use Selenium and the
unittest library to test web applications. We will convert the script into a unittest test
case. We will create few more tests using Selenium and unittest. We will create a
TestSuite for a group of tests. We will run these tests and analyze the results. At the
end of this chapter, you will learn how to produce test reports in the HTML format
that you can distribute to various stakeholders of the project.
Chapter 3, Finding Elements, introduces you to locators that are the keys to automate
different types of User Interface (UI) elements displayed on the web pages in the
browser window. Selenium uses locators to find elements on a page and then
performs actions or retrieves their properties for testing. You will learn various
methods to locate elements, including XPath and CSS. We will show you how to
use these methods with examples on the application under test.
Chapter 4, Using the Selenium Python API for Element Interaction, shows you how to use
the Selenium WebDriver client library to interact with different types of elements,
JavaScript alerts, frames, and windows in Python. You will learn how to perform
actions such as sending values to elements, performing clicks, and selecting
options from dropdowns. You will also see how to handle frames, different types
of JavaScript alerts, and switch between child browser windows.
Chapter 5, Synchronizing Tests, introduces you to various wait methods provided by
Selenium to synchronize tests for reliable and robust execution. You will learn how
to use the implicit and explicit wait to implement synchronization in Selenium tests.
You will learn various methods to implement explicit wait in our test scripts.
Chapter 6, Cross-browser Testing, dives into using RemoteWebDriver to run
cross-browser tests on remote machines or through the Selenium Grid. You
will learn how to use RemoteWebDriver to run tests on remote machines.
We will also set up a Selenium Grid to run tests on various combinations of
browsers and operating systems. You will also see how to execute tests on headless
browsers such as PhantomJS. At the end of the chapter, we will see how to use
cloud testing tools such as Sauce Labs and BrowserStack to run tests in cloud using
RemoteWebDriver.
Chapter 7, Testing on Mobile, shows you how to test applications on mobile devices
using Selenium WebDriver and Appium. We will set up Appium to test our sample
application on iOS and on an Android emulator and device. You will also learn how
to run native mobile applications using Appium.
Chapter 8, Page Objects and Data-driven Testing, introduces you to two important
design patterns to implement a maintainable and efficient testing framework. You
will learn how to use page objects to hide the technical details of locators, and divide
operations on pages into separate classes and create test cases that are more readable
and easy to maintain. You will then learn how to create data-driven tests using the unittest library.
Chapter 9, Advanced Techniques of Selenium WebDriver, dives into some of the
advanced techniques of using Selenium for automating browsers for testing. You
will learn how to use various action methods for simulating complex mouse and
keyboard operations using Selenium. You will see how to handle session cookies,
capture screenshots during a test run, and create a movie of the entire test run.
Chapter 10, Integration with Other Tools and Frameworks, shows you how to use
Selenium WebDriver with automated acceptance testing frameworks such as Behave
and Continuous Integration tools. You will first learn how to integrate Selenium with
Behave to create automated acceptance tests. We will implement a sample feature
and acceptance tests on UI using the Selenium WebDriver. At end of the chapter, we
will set up running the tests that we created as part of Continuous Integration using
Jenkins. We will set up a schedule to run the tests on a daily frequency.
By the end of this book, you will have learned all the essential features of Selenium
WebDriver to create your own web testing framework in Python.

What you need for this book
To get started with this book, you will need basic programming skills in Python as well
as knowledge of web technologies such as HTML, JavaScript, CSS, and XML. If you are
able to write a simple Python script, use loops and conditions, define classes, then you
should be able to keep up with every example in this book. We will take the time to
explain every line of code written in this book so that you are able to create the desired
outcome in any situation you find yourself in. There are some software prerequisites
that are needed, which are explained in the first chapter. You will need to have access
to the command-line interface terminal, Python interpreter, and web browsers such
as Firefox and Google Chrome on your machine. You can download and install
Firefox from https://www.mozilla.org/en-US/firefox/ and Google Chrome
from https://www.google.com/chrome/. If you're a Windows user, you might be
interested in testing Internet Explorer, which is installed by default with Windows.

Who this book is for
If you are a quality assurance/testing professional, software developer, or web
application developer using Python and want to learn Selenium WebDriver to
automate browsers for testing your web applications, this is the perfect guide for you
to get started! As a prerequisite, this book expects you to have a basic understanding
of the Python programming language, although any previous knowledge of
Selenium WebDriver is not needed. By the end of this book, you will have acquired
a comprehensive knowledge of Selenium WebDriver, which will help you in writing
your automation tests.
Loading...
DMCA.com Protection Status