Supercharge Your UI Test Automations for Salesforce Using UTAM

A quick summary of the framework and the best resources to get started

Nerea Leguinazabal
Better Programming

--

Photo by Sigmund on Unsplash

If you are here, it is because you have heard about UTAM — UI Test Automation Model — which Salesforce came up with some months ago, or you are just looking for a way to automate the testing in your applications so you can spend time in more fulfilling tasks.

In case you are not sure what all the hype is about, UTAM is a model that helps us automate user interface tests. This is usually a tedious task that consumes a good chunk of the QA and development teams’ time!

Keep reading to get a quick understanding of how the framework works and why you should automate your tests.

Understanding the Basics

Before we start explaining how the actual automation is done, I want to give a bit of context that will make everything easier to understand when reading the extensions, scripts, and examples.

UTAM is based on the Page Object Model (POM) design pattern used in UI tests. Let’s say we want to use the framework. We first need to identify all the elements in our application and assign them a Page Object, which is just the definition of given elements in a JSON format, following some specific grammar.

This definition file will not only tell us what this element is but also what other elements it is related to and what actions we can perform with it. This new file will enable us to find web elements and interact with them in any other pages they are present. Though we could do the same without the model in a single script, it would get messy quickly, and we would not be able to reuse the code!

Page Object Model Schema — where each page element has its corresponding page class and the methods to promote interaction with it.

Luckily, UTAM provides a JSON grammar to write page objects and a compiler to generate runnable code in Java or JavaScript, so we don’t have to start from scratch. Though it might seem a bit confusing at first, you should retain two things:

  • Each element in a page has a corresponding JSON file that describes it.
  • Using the JSON file, we can generate a Java/JavaScript file per element, encapsulating methods used to interact with them.

To ease the first steps of identifying elements and writing basic JavaScript methods, Salesforce has created a library of Page Objects for their standard pages. You can find it here. But it does not end there, you can also create your own page objects for any custom development within the Salesforce platform or any other website application you are working on.

Start by creating the page objects with the UTAM generator using your application’s HTML source code. Once you have your JSON files, you can simply run the UTAM package’s compiler and generate the JavaScript files you need to build the tests. These two packages will do most of the heavy lifting and provide the base for us to start creating our automated tests. Nevertheless, you will have to refine the base methods or even create new ones if you want to have more functionality.

I would personally recommend taking a look at this repository to understand how the configuration can be done to set your package’s generator and package. There are also a bunch of resources and tutorials on their official website. I would especially encourage you to take a look at the tutorials; they allow you to start playing around straight away without having to go through the whole setup!

Some Extra Tips

If you are using an already existing page object library, and you are not that familiar with the names and methods of the elements, I would get this browser extension. It allows us to load the given package, easily identify the elements, and it provides the actual code to access the selected PO methods.

Are you ready to start automating your tests? Keep an eye on the next article, where I’ll go over the initial setup and some easy-to-write tests.

--

--

I’m a technical consultant passionate about technology and nerdy subjects 🤖