Patterns and Coding Practices for Stable End-to-End GUI Tests

Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted

March 20, 2026 · 5 min read · Testing Guide

Sauce AI for Test Authoring: Move from intent to execution in minutes.

|

x

Back to Resources

Blog

Posted June 16, 2016

Patterns and Coding Practices for Stable End-to-End GUI Tests

quote

We all know the importance of theTest Automation Pyramidand why it makes sense to array various mechanisation in this way. Given that guiding principle, end-to-end GUI tests sit at the top, with a substantially pocket-size number of tests compared to former types (Unit, Integration, Service tests), and they are utilitarian to control business workflow. In the recordAgile Testing: A Practical Guide for Testers and Agile Teams, the authors explain the testing quadrants, the GUI test ’ fit in the grand scheme of things, how to rationalize intention, and be smart about overall Quality scheme.

The intention of the E-E GUI tests is to verify “ whether we build the correct thing from the business perspective. ”

Until some other proficiency evolves, webdriver-based GUI test are the best choice today. When we ’ re examine to mimic the end-user journey through our application, these exam naturally represent an outside-in view. Testing from the surface of the application creates a exposure to many secret factors, such as browser stability, browser performance, meshwork speed, latency, sub-systems ’ performance underneath the GUI, etc. Due to the many moving parts with every small action, GUI examination experience a non-deterministic nature. How do we win the game? The following are the top 5 coding practices that helped me achieve success.

Adopt a page object pattern

Our tests involve to interact with the HTML constituent on the webpage. If we mix HTML element locators within the examination instance, tests will be brickle whenever the UI changes. HTML selectors may be dust, mixed within the logic that interacts with the webpage. This will lead to eminent maintenance, and will limit the possibility of reusing test logic. Instead, consider secernate the test from the logic that interacts with the page. A typical design appear like this:

You ’ ll want to define responsibility for these stratum as good (this post from Martin Fowler explains the summons in detail).

But in short —

The page object should:

  • Provide an API to perform actions on the application

  • Provide access to the province of the underlying page

  • Encapsulate and hide the details of UI/HTML construction from the rest of the macrocosm (i.e. tests)

The UI Map should:

  • Serve as a UI elements repository for the page object

  • Encourage reusability—create a standard way of accessing UI elements for easier maintenance

  • Abstract UI element finder logic from consumers

    Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Follow “ Tell Don ’ t Ask ” shape

Now that tests and page object responsibilities have be defined, what is the protocol between them? Where do we leave the logic to perform the action for the behavior defined by the trial?

For example, below is the conduct we want to automatize:

Giventhe user logged into AmazonWhenthe user lookup for a volume “ Mastering Ansible ”Thenthe scheme should perform search and display consequence

While automating this, searching for a record is a multi-step procedure:

  1. Select “ books ” from the drop-down

  2. Provide the search string to the hunting box

  3. Perform search

We could execute these steps right from the test. However, one of the OOP principles recommends that instead of inquire the page object for data and then acting on it, we should “ tell ” the page object what to do. This rule enables us to move the logic (steps 1 through 3 above) into the page aim and combine datum and behavior. This tightly couples data and the logic that operates on the datum. This co-location helps developer achieve better understanding, and allows for easier maintenance.

Following the Single Responsibility Principle

Now that the page object possess the logic and data, where should we do the statement? Who is responsible for assertions, exception treatment and reporting?

I would suggest keeping this responsibility with the test and let the page object action always return an objective with necessary information, either to assert or address an exception. I choose assertion-free page aim. For example, the below page object action homecoming an fault aim on the exception and ask the test to handle exceptions, report, etc.

Dealing with asynchronous behavior

One of the common challenge is figuring out how to treat with the asynchronous behavior of an application. Webdriver offers implicit and explicit waits where you can wait for “ x ” back before proceedings; however, this is unreliable because we are waiting for that magic number of “ x ” sec. While there are agency to care this in the fabric, I would suggest consider about it from the end-user experience perspective. Remember that E-E GUI tests ’ intention is to verify the app from the business/end-user standpoint. So, how long are we asking our end-user to wait between actions? If an expected element is not visible, clickable, or whatever the case may be after a certain point, bubble an exception back to the test and let the test fail consistently.

Lint, build, publish and part the logic

Since a page object represents composite actions, they can be real handy and reusable for many behaviors.

  • Depending on the stack, Lint the page object code, since it likely contains logic and data handling, etc. Good coding drill are critical.

  • Run Sonar analysis and set quality gates on this codebase. I would yet suggest writing custom rules to forbid some traditional mistakes such as Thread.sleep (), path selectors, etc.

  • Set up CI form; neglect the build on codification lineament SLA violation

  • Package and publish reusable page object APIs and encourage wider reusability

Overall, treat test codification the same way you handle production codification. Write test codification like you ’ re developing an app, not letting your developer run your tryout.

Sahas Subramanian (@ sahaswaranamam) is a passionate engineer with experience spanning across DevOps, quality technology, web development and consulting. He is presently act as a Continuous Delivery and Quality Architect @CDK Global, and shares his mentation on tech viahttps: //cdinsight.wordpress.com

Published:
Jun 16, 2016
Share this situation
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rightfield allow. SAUCE and SAUCE LABS are registered trademarks have by Sauce Labs Inc. in the United States, EU, and may be register in other 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