The 202 of UI Testing Automation Model from Salesforce
Testing apps is critical to ensure that they are of top-notch quality. And to test applications, one type of testing you can trust is end-to-end (E2E) tests.
E2E tests are executed with an automated UI testing tool like Selenium or WebdriverIO. The USP of E2E tests is that you can:
- Use a real browser to interact with components and navigate across screens when you execute test scenarios.
- Test an app with restricted access to its source code.
However, writing E2E tests, testing your UI thoroughly, and avoiding repetitive manual testing is no easy feat. Often you’ll find yourself investing in third-party tools and solutions to write and maintain E2E tests.
Enter – a new UI test automation framework by Salesforce – UI Test Automation Model (UTAM).
So, what is UTAM? Why use UTAM? How to run tests with UTAM?
Read on to learn the answers to all these questions and more.
With the Salesforce Spring ‘22 release, UTAM became generally available.
UTAM adopts the Page Object Model design pattern associated with Selenium, taking Page Objects to the next level by creating abstractions of Page Components, allowing for robust UI testing.
It doesn’t replace a UI testing tool but supplements it by decoupling the test code from the Document Object Model (DOM) using Page Objects.
UTAM Page Objects can describe a web page itself or a web component at a granular level.
Don't forget to check out: What is Case Automation Tool in Salesforce
Why Use UTAM?
UTAM dissociates a test case from a web page or a web component, this helps to increase the test robustness, and reduce the cost & complexity of test case maintenance because Salesforce changes DOM after every release. Because of this, the UTAM component definitions may require code changes, allowing the test case(s) to be unchanged and accordingly providing separation of concerns:
- Decrease duplication of Web Components/Page Objects and provide individual reusable UTAM components that are easier to maintain.
- Ensure each UTAM component is related to an individual set of cohesive responsibilities. Also, check that it is connected to a single web component for better stability and maintainability.
- Improve maintainability to support custom Lightning Web Components.
- Execute a test case using Selenium or WebDriver.io test automation frameworks.
- Be used for both Salesforce and non-Salesforce web pages.
You can write UTAM Page Objects in JSON. Also, Page Objects act as a shareable contract and are written in JSON. This makes UTAM unique from other UI testing tools. Simply put, UTAM enables multiple teams to collaborate and share Page Objects regardless of the technology they use for testing.
Running End-to-End Tests With UTAM
Now that we’ve covered what UTAM is and how it helps, let’s look at a practical example.
Here, we’re testing a static HTML page with “Hello, World!” as display:
Check out the steps needed to test this page:
- Declare a JSON Page Object with a world element. This element consists of a .world CSS class selector, in alignment with a DOM element on the page under test.
- Compile Page Object, which generates a class with a getWorld method that is tied to the world element defined in JSON.
- Use the getWorld method from the compiled Page Object in the test code to get access to the content of the DOM with the .world CSS class.
While this may seem long-winded for a simple use case, the true power of UTAM is evident when the pages are complex. In complex cases (which are closer to real-life apps), composition and reusability are a must-have, and that’s where UTAM helps.
UTAM is not restricted to testing Salesforce apps; it can be used with any technology or platform. But Salesforce provides a set of hundreds of reusable UTAM Page Objects for the base Lightning Components and the Lightning Experience. This saves a lot of time when writing E2E tests for Salesforce apps. That’s why most Salesforce engineering teams use the power of UTAM internally to test their apps.
Want to level up your testing game with UTAM? Talk to us!
Our Salesforce QA experts are adept with the whole nine yards of Salesforce testing and QA and would love to ensure that your apps are of the highest quality. Drop us a line at [email protected], and we’ll take it from there.