Selenium WebDriver Recipes in Ruby
Selenium WebDriver Recipes in Ruby
The problem solving guide to Selenium WebDriver in Ruby
About the Book
Selenium WebDriver is a popular browser automation framework, testers or developers with Selenium skills are in high demand. It is easy to get started with Selenium, but do you use effectively for testing real-world test scenarios? Such as data driving test from an Excel spreadsheet and handling pop up dialogs.
Selenium WebDriver Recipes will show you solutions to your problems from the experts who have already solved them. All recipe test scripts (~200 in Ruby language) are ready-to-run, i.e., I created the target web pages and test sites, so that you can simply find the recipes and run, in a matter of seconds. Owning this book is like having a test automation coach sitting next to you.
Bundles that include this book
Table of Contents
-
Preface
- Who should read this book
- How to read this book
- Recipe test scripts
- Send me feedback
-
1. Introduction
- 1.1 Selenium language bindings: Java, C#, JavaScript, Python and Ruby
- 1.2 Cross-browser testing
- 1.3 RSpec
- 1.4 Run recipe scripts
-
2. Locating web elements
- 2.1 Start browser
- 2.2 Inspect Web Element in Browser
- 2.3 Find element by ID
- 2.4 Find element by Name
- 2.5 Find element by Link Text
- 2.6 Find element by Partial Link Text
- 2.7 Find element by XPath
- 2.8 Find element by Tag Name
- 2.9 Find element by Class
- 2.10 Find element by CSS Selector
- 2.11 Find element by Relative locators
- 2.12 Chain find_element to find child elements
- 2.13 Find multiple elements
- 2.14 Locate a Web Element that disappears after Inspect
-
3. Hyperlink
- 3.1 Click a link by text
- 3.2 Click a link by ID
- 3.3 Click a link by partial text
- 3.4 Click a link by XPath
- 3.5 Click Nth link with exact same label
- 3.6 Verify a link is present or not?
- 3.7 Getting link data attributes
- 3.8 Test links open a new browser window
-
4. Button
- 4.1 Click a button by text
- 4.2 Click a form button by text
- 4.3 Submit a form
- 4.4 Click a button by ID
- 4.5 Click a button by name
- 4.6 Click an image button
- 4.7 Click a button via JavaScript
- 4.8 Assert a button present
- 4.9 Assert a button enabled or disabled?
-
5. TextField and TextArea
- 5.1 Enter text into a text field by name
- 5.2 Enter text into a text field by ID
- 5.3 Enter text into a password field
- 5.4 Clear a text field
- 5.5 Enter text into a multi-line text area
- 5.6 Assert value
- 5.7 Focus on a control
- 5.8 Set a value to a read-only or disabled text field
- 5.9 Set and assert the value of a hidden field
-
6. Radio button
- 6.1 Select a radio button
- 6.2 Clear radio option selection
- 6.3 Assert a radio option is selected
- 6.4 Iterate radio buttons in a radio group
- 6.5 Click Nth radio button in a group
- 6.6 Click radio button by the following label
- 6.7 Customized Radio buttons - iCheck
-
7. CheckBox
- 7.1 Select by name
- 7.2 Uncheck a checkbox
- 7.3 Assert a checkbox is checked (or not)
- 7.4 Customized Checkboxes - iCheck
-
8. Select List
- 8.1 Select an option by text
- 8.2 Select an option by value
- 8.3 Select an option by index
- 8.4 Send keys to the select element
- 8.5 Select an option by iterating all options
- 8.6 Select multiple options
- 8.7 Clear one selection
- 8.8 Clear all selections
- 8.9 Assert a label or value in a select list
- 8.10 Assert selected option label
- 8.11 Assert the value of a select list
- 8.12 Assert multiple selections
-
9. Navigation and Browser
- 9.1 Go to a URL
- 9.2 Visit pages within a site
- 9.3 Perform actions from right mouse click context menu such as ‘Back’, ‘Forward’ or ‘Refresh’
- 9.4 Open browser in a certain size
- 9.5 Maximize browser window
- 9.6 Move browser window
- 9.7 Minimize browser window
- 9.8 Scroll focus to control vis JS
- 9.9 Scroll with Scroll Wheel Actions
- 9.10 Switch between browser windows or tabs
- 9.11 New Browser Window or Tab
- 9.12 Open new and close browser Tabs using JavaScript
- 9.13 Remember current web page URL, then come back to it later
-
10. Assertion
- 10.1 Assert page title
- 10.2 Assert Page Text
- 10.3 Assert Page Source
- 10.4 Assert Label Text
- 10.5 Assert Span text
- 10.6 Assert Div text or HTML
- 10.7 Assert Table text
- 10.8 Assert text in a table cell
- 10.9 Assert text in a table row
- 10.10 Assert image present
- 10.11 Assert element location and width
- 10.12 Assert element CSS style
- 10.13 Assert JS errors on a web page
-
11. Frames
- 11.1 Testing Frames
- 11.2 Find frames with find_element
- 11.3 Testing IFrame
- 11.4 Test multiple iframes
-
12. Testing AJAX
- 12.1 Wait within a time frame
- 12.2 Explicit Waits until Time out
- 12.3 Implicit Waits until Time out
- 12.4 Create your own polling check function
- 12.5 Wait AJAX Call to complete using JQuery
-
13. File Upload and Popup dialogs
- 13.1 File upload
- 13.2 JavaScript pop-ups
- 13.3 Modal style dialogs
- 13.4 Bypass basic authentication by embedding username and password in URL
- 13.5 Timeout on an operation
- 13.6 Internet Explorer modal dialog
-
14. Debugging Test Scripts
- 14.1 Print text for debugging
- 14.2 Write text to IDE output
- 14.3 Write page source or element HTML into a file
- 14.4 Take screenshots
- 14.5 Save the screenshot of a specific web element
- 14.6 Using IRB
- 14.7 Leave browser open after test finishes
- 14.8 Pause/Stop test execution at a certain step
- 14.9 Run selected test steps against current browser
-
15. Test Data
- 15.1 Get date dynamically
- 15.2 Get a random boolean value
- 15.3 Generate a number within a range
- 15.4 Get a random character
- 15.5 Get a random string at a fixed length
- 15.6 Get a random string in a collection
- 15.7 Generate random person names, emails, addresses with Faker
- 15.8 Generate a test file at fixed sizes
- 15.9 Retrieve data from Database
-
16. Browser Profile and Capabilities
- 16.1 Get browser type and version
- 16.2 Set HTTP Proxy for Browser
- 16.3 Verify file download in Chrome
- 16.4 Load Chrome extensions
- 16.5 Test downloading PDF in Firefox
- 16.6 Bypass basic authentication with Firefox AutoAuth plugin
- 16.7 Manage Cookies
- 16.8 Headless Chrome
- 16.9 Headless Firefox
- 16.10 Test responsive websites
- 16.11 Device emulation on Chrome
- 16.12 Set page load timeout
- 16.13 Testing slow pages that exceed default 60-second timeout
-
17. Advanced User Interactions
- 17.1 Double click a control
- 17.2 Move the mouse to a control - Mouse Over
- 17.3 Click and hold - select multiple items
- 17.4 Context Click - right click a control
- 17.5 Drag and drop
- 17.6 Drag slider
- 17.7 Send key sequences - Select All and Delete
- 17.8 Click a specific part of an image
- 17.9 Mouse move to coordinates
-
18. HTML 5 and JavaScript
- 18.1 HTML5 Email type field
- 18.2 HTML5 Time Field
- 18.3 Invoke ‘onclick’ JavaScript event
- 18.4 Invoke JavaScript events such as ‘onchange’
- 18.5 Scroll to the bottom of a page
- 18.6 Select2 - Single Select
- 18.7 Select2 - Multiple Select
- 18.8 AngularJS web pages
- 18.9 Ember JS web pages
- 18.10 “Share Location” with Firefox
- 18.11 Faking Geolocation with JavaScript
- 18.12 Save a canvas to PNG image
- 18.13 Verify dynamic charts
- 18.14 TinyMCE
- 18.15 CKEditor
- 18.16 SummerNote
- 18.17 CodeMirror
-
19. Leverage Programming
- 19.1 Raise exceptions to fail a test
- 19.2 Ignorable test statement error
- 19.3 Read external file
- 19.4 Data-Driven Tests with Excel
- 19.5 Data-Driven Tests with CSV
- 19.6 Identify element IDs with dynamically generated long prefixes
- 19.7 Sending special keys to an element or browser
- 19.8 Use of Unicode in test scripts
- 19.9 Extract a group of dynamic data : verify search results in order
- 19.10 Verify the uniqueness of a set of data
- 19.11 Extract dynamic visible data rows from a table
- 19.12 Extract dynamic text following a pattern using Regex
- 19.13 Quick extract pattern text in comments with Regex
-
20. Optimization
- 20.1 Assert text in page_source is faster than the text
- 20.2 Getting the text from a more specific element is faster
- 20.3 Avoid programming if-else block code if possible
- 20.4 Use variable to cache not-changed data
- 20.5 Enter large text into a text box
- 20.6 Use Environment Variables to change test behaviors dynamically
- 20.7 Test website in two languages
- 20.8 Multi-language testing with lookups
-
21. Gotchas
- 21.1 Test starts browser but no execution with a blank screen
- 21.2 Failed to assert copied text in the browser
- 21.3 The same test works for Chrome, but not IE
- 21.4 “unexpected tag name ‘input’”
- 21.5 Element is not clickable or not visible
- 21.6 Lack of knowledge of the programming language
-
22. Extend Selenium
- 22.1 Watir
- 22.2 RWebSpec
- 22.3 Capybara
-
23. Selenium with Cucumber
- 23.1 How Selenium-WebDriver is integrated with Cucumber?
- 23.2 Execute Cucumber tests
- 23.3 Cucumber or RSpec?
-
24. Material Design Web App
- 24.1 Select List (dropdown)
- 24.2 Checkbox
- 24.3 Drag range (noUiSlider)
- 24.4 Verify Toast message
- 24.5 Modal
-
25. Selenium Grid
- 25.1 Selenium Server Standalone
- 25.2 Execute tests on a remote machine
- 25.3 Set up Selenium Grid
- 25.4 Using Selenium Grid to run tests
- 25.5 Issues with Selenium Grid
-
26. Selenium 4
- 26.1 New Browser Window or Tab
- 26.2 Basic Authentication via register
- 26.3 Print to PDF
- 26.4 Save element screenshot
- 26.5 Relative Locators
- 26.6 Scroll Wheel Actions
-
27. Selenium DevTools
- 27.1 General
- 27.2 Event
- 27.3 Network
- 27.4 Emulate
- 27.5 Page
-
28. Quiz
- 28.1 Answers
- Afterword
-
Resources
- Books
- websites
- Blog
- Tools
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,820,291writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
Stratospheric
Tom Hombergs, Björn Wilmsmann, and Philip RiecksFrom Zero to Production with Spring Boot and AWS. All you need to know to get a Spring Boot application into production with AWS. No previous AWS knowledge required.
Go to stratospheric.dev for a tour of the contents.
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
node-opcua by example
Etienne RossignonGet the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
Advanced Web Application Architecture
Matthias NobackThe missing manual for making your web applications future-proof
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Thinking with Types
Sandy MaguireThis book aims to be the comprehensive manual for type-level programming. It's about getting you from here to there---from a competent Haskell programmer to one who convinces the compiler to do their work for them.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
D3 Start to Finish
Peter CookD3 Start to Finish shows you how to build a custom, interactive and beautiful data visualisation using the JavaScript library D3.js (versions 6 & 7).
The book covers D3.js concepts such as selections, joins, requests, scale functions, events & transitions. You'll put these concepts into practice by building a custom, interactive data visualisation.
Top Bundles
- #1
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #4
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #5
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #6
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!?