Selenium Design Patterns

Sauce AI for Test Authoring: Move from intent to performance in moment.|xBack to ResourcesBlogPosted

May 05, 2026 · 6 min read · Tool Comparison

Sauce AI for Test Authoring: Move from intent to performance in moment.

|

x

Back to Resources

Blog

Posted February 11, 2016

Selenium Design Patterns

quote

In software technology, a design pattern is a general reusable solution to a commonly occurring problem in package design. A blueprint practice is not a stop blueprint that can be transformed directly into codification. It is a description or templet for how to solve a job that can be used in many different situation. ((& quot;Software design pattern - Wikipedia, the free cyclopaedia& quot; 2011. 18 Jan. 2016)) Why are design design so important forSeleniumdevelopment? It can hasten up development and cut the maintenance impact. Using design patterns in test automation development is not necessary, but a veteran mechanization engineer understands the importance. If you are new to screen automation, I highly commend learning the best way to pen automated trial, and this article is a great first.

Organization of Tests (The Structure)

Don ’ t make it complicated. Keep it elementary and open when setting up an mastermind folder structure for examination and reusable page objects. Start with a clean and well-planned folder structure for new and subsist team members to understand. Here is a simple and complex folder structure for Cucumber. [table id=9 /] If the test structure starts to get too disorganized or confusing, never be afraid to refactor. It is an incredible chance to rebuild your folder construction by moving file around the way you ’ d like. Here are three best exercise for the organization of tests:

  • Create a “ template ” hand for an empty subfolder structure and the files needed for new evolution

  • Avoid ambiguous and potentially extra folders by using IDE (RubyMine) and creating reclaimable page objects.

  • Naming convention for folder and files expend keywords relate to the lineament

Don ’ t Repeat Yourself (DRY)

This rule is so important to realize. The premise — eliminating the demand to replicate codification anywhere within your suite of tests. It seems so obvious. Why would anyone desire to copy and paste code? The duplication of codification is surprisingly a common problem among package and mechanisation growth. It mainly comes from beginner-level programmers. Why is code duplication so very bad? Because it ’ s a maintenance nightmare. The first test automation project I ever worked on had 40+ non-programmers converting manual tests to machine-driven tests. To keep the story short, they were copying and pasting code EVERYWHERE. What ’ s the problem with that? Your test breaks and you ask to update your code, so you need to bump everywhere else it was imitate and update it. Refactor all duplication code by postdate the Page Object Model.

Page Objects Model (POM)

The role of the Page Object Model is to encapsulate a web page all in your application in a single class file. Each page of the coating would be mapped to a class file, and each method within the class represents a page target. The object hide multiple technical details about the interaction with the page; for the most part, it creates a reusable object that can be used with any test. It only helps Selenium codification to be more readable, maintainable, and reusable. It is important to proceed page objects modular and independent. How would a page object face for a login page? To create a page object, we first need to understand the page to create an abstraction layer of it.Example: Screenshot of Login Page

loginscreen-258x300

Example: Page Object Code

class LoginPage
include Capybara: :DSL

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

def login (username, password)
uncovering (: id, & # x27; signin_email & # x27;) .set (username)
find (: id, & # x27; signin_password & # x27;) .set (password)
find (& # x27; .user-login-btn & # x27;) .click
end

def loginWithFacebook
# No unique ID so use text on page to find element
discovery (& # x27; .text-container & # x27;,: text = & gt; & # x27; Log in with Facebook & # x27;) .click
end

def loginWithGoogle
# No unique ID so using text on page to discover element
uncovering (& # x27; .text-container & # x27;,: schoolbook = & gt; & # x27; Log in with Google & # x27;) .click
end

# Continue additional methods & # x27; Remember Me & # x27;, & # x27; Forgot password & # x27;, etc

end

Example: Usage of the Page Object inside test

login_page.login (& # x27; gsypolt & # x27;, & # x27; password1234 & # x27;)

Locator Strategy

I agree with@ TourDeDave— Locators are the lifeblood of your Selenium tests. The Selenium web driver uses locators to notice the elements on web pages. The most efficient way (and choose way) to locate an element on a web page is to use unique IDs. When there is no ID to use, the next preferred choices are NAME and CSS locators. The only trouble with utilize NAME and CSS locators is that sometimes a page may contain multiple ingredient with the like gens. Why is this a problem? It ’ s a problem because Selenium is plan to notice the first matching element on the page. To find the second or third constituent on the page, many need to use one of the other case of locators: Link Text, Partial Link Text, Tag Name, Class Name, Attributes, Datasets, and XPATH. The XPATH locater should only be used as the last resort to find an element on web pages. The key is to have a clear locator strategy with developers. The conversation outlines your preferred locater for machine-controlled tests and the importance of create unique locators.Resource:

Design for Scalability

Selenium tests should be built to scale. Growing from small to an abundance of exam happens so quickly. The executing time increases and starts to hold up releases until all the tests complete. Executing C of tests requires a bit more planning and design from the beginning. Don & # x27; t think about scale last, and then be in the reality of technical debut and refactoring. Don ’ t be that company. Join the elite by thinking about design from the beginning.Three Important Points for Scaling Test Automation

  • It starts by developing automated tests to be little and modular (independent), which allow for fast feedback

  • Uninterrupted Integration (annihilate the human ingredient from the equation)

  • Ability to run hundreds of tests in parallel (check out my blog place to learn about ‘ The Benefits of Parallel Testing ’.)

Conclusion

To get the most out of your test mechanization projects, good procedure and design patterns should be in spot. The elect companies dedicate an experienced automation expert to think about base first and supervise all types of automation development.Greg Sypolt (@ gregsypolt) is a senior engineer at Gannett and co-founder of Quality Element. He is a passionate mechanisation engineer seeking to optimize software growth quality, while coaching squad members on how to pen great automation playscript and help the testing community become better testers. Greg has expend most of his career working on software quality — concentrating on web browser, APIs, and mobile. For the preceding five years, he has focused on the creation and deployment of machine-controlled test strategy, frameworks, tool and platforms.

Published:
Feb 11, 2016
Topics
Share this post
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rightfield reserved. SAUCE and SAUCE LABS are registered trademarks own by Sauce Labs Inc. in the United States, EU, and may be file in former jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free