Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Selenium Design Patterns and Best Practices

You're reading from   Selenium Design Patterns and Best Practices Build a powerful, stable, and automated test suite using Selenium WebDriver

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher
ISBN-13 9781783982707
Length 270 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Dima Kovalenko Dima Kovalenko
Author Profile Icon Dima Kovalenko
Dima Kovalenko
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Writing the First Test FREE CHAPTER 2. The Spaghetti Pattern 3. Refactoring Tests 4. Data-driven Testing 5. Stabilizing the Tests 6. Testing the Behavior 7. The Page Objects Pattern 8. Growing the Test Suite A. Getting Started with Selenium Index

Creating generic DRY methods

At this point, our test is no longer recognizable compared to what it was at the beginning of the chapter. Before we wrap it up, let's talk about the generic action used all through our tests. Throughout the test code, we use some common methods to perform actions such as clicking or typing text into a text field. These chained methods look something like this:

Creating generic DRY methods

What if we refactor these methods a little further and create some generic private methods that can be used in a much simpler way? Let's start with the most common method used, @selenium.find_element, and create a generic find_element method:

Creating generic DRY methods

Our find_element method now accepts an element identifier and an optional strategy parameter. If the strategy is not specified, it will default to the CSS selector.

Note

More information about element locator strategies can be found in Chapter 2, The Spaghetti Pattern.

Now let's add two new methods that use our local find_element method to click and type...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image