Espresso Framework: Creating UI Tests using Page Object Model

Dmitry Yarygin
Software Testing: Break and Improve
6 min readMar 10, 2020

Photo by Rohit Tandon on Unsplash

Page Object Model in Software Testing is not a new concept. Some people heard about it, others wanted to switch over and implement it, but it all comes down to the specific needs of the client. In some cases, it may be worth utilizing it, while in other cases it creates an unnecessary overhead.

Today we are going to create a basic Espresso test framework to execute Android UI Test Cases on it. The main goal of this tutorial is to show the basic mechanisms behind the Page Object Model (POM).

Also, if you are interested in Web Testing, consider watching my video tutorial about TestCafe and WebDriver + POM.

Page Object: The Basics

First of all, what is a Page Object? This concept is based on the idea that every UI element (page or fragment) of the application has a separate implementation of the methods. This allows us to write a reusable code that is easy to modify when necessary.

Secondly, why would we need it? Having tests using Page Object Method pattern allows us to make readable code that new team members can understand and write code faster.

Finally, with the right approach, it’s possible to make an automation testing available to non-technical team members. There is a big potential when it comes to improving the test infrastructure.

The importance of POM concept

Since we have an understanding of what do we want to be implemented the framework, let do it on a real project created in Android Studio.

We will be refactoring the existing Espresso project that we worked on in the past. This project had 3 pages: Home page, Dashboard, and Notifications. Our test class was clicking each of those buttons and confirming that it worked.

Simple Android app

The code that has performed all those actions looked like this:

@Testpublic void clickButtonHome(){onView(withId(; }

Dmitry Yarygin
Software Testing: Break and Improve

Nomad lifestyle writer. Passionate about breaking software— QA Engineer. My Travel & Tech YouTube channel: