Leanpub Header

Skip to main content

Selenium WebDriver Recipes in Ruby

The problem solving guide to Selenium WebDriver in Ruby

The Selenium WebDriver Recipes book is a quick problem-solving guide to automated testing web applications with Selenium WebDriver. It contains hundreds of solutions to real-world problems, with clear explanations and ready-to-run test scripts you can use in your own projects.

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
208
Pages
30,702Words
About

About

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.

Share this book

Categories

Price

Pick Your Price...

Minimum price

$15.00

$25.00

You pay

$25.00

Author earns

$20.00
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 1)

1
The author will earn $12.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Zhimin Zhan

Zhimin Zhan is the founder and principal agile testing coach of AgileWay Pty Ltd, Australia. As an advisor and coach, he helps organisations implement test automation using Continuous Testing with open technologies, such as Selenium WebDriver / Appium. Zhimin is the creator of TestWise, the next-generation functional testing tool that supports functional test refactorings, and BuildWise, an international award-winning Continuous Testing Server. Zhimin is a frequent speaker and author of 14 books on software testing and programming. He shares his test automation and CI experience on Substack and Medium.

Contents

Table of Contents

Preface

  1. Who should read this book
  2. How to read this book
  3. Recipe test scripts
  4. Send me feedback

1.Introduction

  1. 1.1Selenium language bindings: Java, C#, JavaScript, Python and Ruby
  2. 1.2Cross-browser testing
  3. 1.3RSpec
  4. 1.4Run recipe scripts

2.Locating web elements

  1. 2.1Start browser
  2. 2.2Inspect Web Element in Browser
  3. 2.3Find element by ID
  4. 2.4Find element by Name
  5. 2.5Find element by Link Text
  6. 2.6Find element by Partial Link Text
  7. 2.7Find element by XPath
  8. 2.8Find element by Tag Name
  9. 2.9Find element by Class
  10. 2.10Find element by CSS Selector
  11. 2.11Find element by Relative locators
  12. 2.12Chain find_element to find child elements
  13. 2.13Find multiple elements
  14. 2.14Locate a Web Element that disappears after Inspect

3.Hyperlink

  1. 3.1Click a link by text
  2. 3.2Click a link by ID
  3. 3.3Click a link by partial text
  4. 3.4Click a link by XPath
  5. 3.5Click Nth link with exact same label
  6. 3.6Verify a link is present or not?
  7. 3.7Getting link data attributes
  8. 3.8Test links open a new browser window

4.Button

  1. 4.1Click a button by text
  2. 4.2Click a form button by text
  3. 4.3Submit a form
  4. 4.4Click a button by ID
  5. 4.5Click a button by name
  6. 4.6Click an image button
  7. 4.7Click a button via JavaScript
  8. 4.8Assert a button present
  9. 4.9Assert a button enabled or disabled?

5.TextField and TextArea

  1. 5.1Enter text into a text field by name
  2. 5.2Enter text into a text field by ID
  3. 5.3Enter text into a password field
  4. 5.4Clear a text field
  5. 5.5Enter text into a multi-line text area
  6. 5.6Assert value
  7. 5.7Focus on a control
  8. 5.8Set a value to a read-only or disabled text field
  9. 5.9Set and assert the value of a hidden field

6.Radio button

  1. 6.1Select a radio button
  2. 6.2Clear radio option selection
  3. 6.3Assert a radio option is selected
  4. 6.4Iterate radio buttons in a radio group
  5. 6.5Click Nth radio button in a group
  6. 6.6Click radio button by the following label
  7. 6.7Customized Radio buttons - iCheck

7.CheckBox

  1. 7.1Select by name
  2. 7.2Uncheck a checkbox
  3. 7.3Assert a checkbox is checked (or not)
  4. 7.4Customized Checkboxes - iCheck

8.Select List

  1. 8.1Select an option by text
  2. 8.2Select an option by value
  3. 8.3Select an option by index
  4. 8.4Send keys to the select element
  5. 8.5Select an option by iterating all options
  6. 8.6Select multiple options
  7. 8.7Clear one selection
  8. 8.8Clear all selections
  9. 8.9Assert a label or value in a select list
  10. 8.10Assert selected option label
  11. 8.11Assert the value of a select list
  12. 8.12Assert multiple selections

9.Navigation and Browser

  1. 9.1Go to a URL
  2. 9.2Visit pages within a site
  3. 9.3Perform actions from right mouse click context menu such as ‘Back’, ‘Forward’ or ‘Refresh’
  4. 9.4Open browser in a certain size
  5. 9.5Maximize browser window
  6. 9.6Move browser window
  7. 9.7Minimize browser window
  8. 9.8Scroll focus to control vis JS
  9. 9.9Scroll with Scroll Wheel Actions
  10. 9.10Switch between browser windows or tabs
  11. 9.11New Browser Window or Tab
  12. 9.12Open new and close browser Tabs using JavaScript
  13. 9.13Remember current web page URL, then come back to it later

10.Assertion

  1. 10.1Assert page title
  2. 10.2Assert Page Text
  3. 10.3Assert Page Source
  4. 10.4Assert Label Text
  5. 10.5Assert Span text
  6. 10.6Assert Div text or HTML
  7. 10.7Assert Table text
  8. 10.8Assert text in a table cell
  9. 10.9Assert text in a table row
  10. 10.10Assert image present
  11. 10.11Assert element location and width
  12. 10.12Assert element CSS style
  13. 10.13Assert JS errors on a web page

11.Frames

  1. 11.1Testing Frames
  2. 11.2Find a frame with find_element
  3. 11.3Testing IFrame
  4. 11.4Test multiple iframes

12.Testing AJAX

  1. 12.1Wait within a time frame
  2. 12.2Explicit Waits until Time out
  3. 12.3Implicit Waits until Time out
  4. 12.4Create your own polling check function
  5. 12.5Wait AJAX Call to complete using JQuery

13.File Upload and Popup dialogs

  1. 13.1File upload
  2. 13.2JavaScript pop-ups
  3. 13.3Modal style dialogs
  4. 13.4Bypass basic authentication by embedding username and password in URL
  5. 13.5Timeout on an operation
  6. 13.6Internet Explorer modal dialog

14.Debugging Test Scripts

  1. 14.1Print text for debugging
  2. 14.2Write text to IDE output
  3. 14.3Write page source or element HTML into a file
  4. 14.4Take screenshots
  5. 14.5Save the screenshot of a specific web element
  6. 14.6Using IRB
  7. 14.7Leave browser open after test finishes
  8. 14.8Pause/Stop test execution at a certain step
  9. 14.9Run selected test steps against current browser

15.Test Data

  1. 15.1Get date dynamically
  2. 15.2Get a random boolean value
  3. 15.3Generate a number within a range
  4. 15.4Get a random character
  5. 15.5Get a random string at a fixed length
  6. 15.6Get a random string in a collection
  7. 15.7Generate random person names, emails, addresses with Faker
  8. 15.8Generate a test file at fixed sizes
  9. 15.9Retrieve data from Database

16.Browser Profile and Capabilities

  1. 16.1Get browser type and version
  2. 16.2Set HTTP Proxy for Browser
  3. 16.3Verify file download in Chrome
  4. 16.4Load Chrome extensions
  5. 16.5Test downloading PDF in Firefox
  6. 16.6Bypass basic authentication with Firefox AutoAuth plugin
  7. 16.7Manage Cookies
  8. 16.8Headless Chrome
  9. 16.9Headless Firefox
  10. 16.10Test responsive websites
  11. 16.11Device emulation on Chrome
  12. 16.12Set page load timeout
  13. 16.13Testing slow pages that exceed default 60-second timeout

17.Advanced User Interactions

  1. 17.1Double click a control
  2. 17.2Move the mouse to a control - Mouse Over
  3. 17.3Click and hold - select multiple items
  4. 17.4Context Click - right click a control
  5. 17.5Drag and drop
  6. 17.6Drag slider
  7. 17.7Send key sequences - Select All and Delete
  8. 17.8Click a specific part of an image
  9. 17.9Mouse move to coordinates
  10. 17.10Shadow DOM

18.HTML 5 and JavaScript

  1. 18.1HTML5 Email type field
  2. 18.2HTML5 Time Field
  3. 18.3HTML5 Range Element
  4. 18.4Invoke ‘onclick’ JavaScript event
  5. 18.5Invoke JavaScript events such as ‘onchange’
  6. 18.6Scroll to the bottom of a page
  7. 18.7Select2 - Single Select
  8. 18.8Select2 - Multiple Select
  9. 18.9AngularJS web pages
  10. 18.10Ember JS web pages
  11. 18.11“Share Location” with Firefox
  12. 18.12Faking Geolocation with JavaScript
  13. 18.13Save a canvas to PNG image
  14. 18.14Verify dynamic charts
  15. 18.15TinyMCE
  16. 18.16CKEditor
  17. 18.17SummerNote
  18. 18.18CodeMirror

19.Leverage Programming

  1. 19.1Raise exceptions to fail a test
  2. 19.2Ignorable test statement error
  3. 19.3Read external file
  4. 19.4Data-Driven Tests with Excel
  5. 19.5Data-Driven Tests with CSV
  6. 19.6Identify element IDs with dynamically generated long prefixes
  7. 19.7Sending special keys to an element or browser
  8. 19.8Use of Unicode in test scripts
  9. 19.9Extract a group of dynamic data : verify search results in order
  10. 19.10Verify the uniqueness of a set of data
  11. 19.11Extract dynamic visible data rows from a table
  12. 19.12Extract dynamic text following a pattern using Regex
  13. 19.13Quick extract pattern text in comments with Regex

20.Optimization

  1. 20.1Assert text in page_source is faster than the text
  2. 20.2Getting the text from a more specific element is faster
  3. 20.3Avoid programming if-else block code if possible
  4. 20.4Use variable to cache not-changed data
  5. 20.5Enter large text into a text box
  6. 20.6Use Environment Variables to change test behaviors dynamically
  7. 20.7Test website in two languages
  8. 20.8Multi-language testing with lookups

21.Gotchas

  1. 21.1Test starts browser but no execution with a blank screen
  2. Be aware of browser and driver changes
  3. 21.2Failed to assert copied text in the browser
  4. 21.3The same test works for Chrome, but not IE
  5. 21.4“unexpected tag name ‘input’”
  6. 21.5Element is not clickable or not visible
  7. 21.6Lack of knowledge of the programming language

22.Extend Selenium

  1. 22.1Watir
  2. 22.2RWebSpec
  3. 22.3Capybara

23.Selenium with Cucumber

  1. 23.1How Selenium-WebDriver is integrated with Cucumber?
  2. 23.2Execute Cucumber tests
  3. 23.3Cucumber or RSpec?

24.Material Design Web App

  1. 24.1Select List (dropdown)
  2. 24.2Checkbox
  3. 24.3Drag range (noUiSlider)
  4. 24.4Verify Toast message
  5. 24.5Modal

25.Selenium Grid

  1. 25.1Selenium Server Standalone
  2. 25.2Execute tests on a remote machine
  3. 25.3Set up Selenium Grid
  4. 25.4Using Selenium Grid to run tests
  5. 25.5Issues with Selenium Grid

26.Selenium 4

  1. 26.1New Browser Window or Tab
  2. 26.2Basic Authentication via register
  3. 26.3Print to PDF
  4. 26.4Save element screenshot
  5. 26.5Relative Locators
  6. 26.6Scroll Wheel Actions

27.Selenium DevTools

  1. 27.1General
  2. 27.2Event
  3. 27.3Network
  4. 27.4Emulate
  5. 27.5Page

28.Quiz

  1. 28.1Answers

Afterword

Resources

  1. Books
  2. websites
  3. Blog
  4. Tools

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

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.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub