Salesforce UTAM Explained in < 5 Minutes
UTAM, or the UI Test Automation Model, is a popular page object model design pattern used for UI tests. It relies on a CSS selector to avoid using complicated Xpath locators and is authored in JSON using the easy-to-understand UTAM JSON Grammar. The UTAM generator converts HTML files into UTAM JSON, which is then provided to the UTAM compiler to convert the JSON into executable code in JavaScript, TypeScript, and Java.
Why do we need UTAM?
Simplicity - UTAM relies on a CSS selector to avoid using complicated Xpath locators.
Affordability - UTAM is an open-source tool that is available at no cost, whereas other tools and suites with similar features often require payment.
Efficiency - The time required to run complex scenarios is comparatively less when using UTAM, as its DOM interaction is very quick. This results in lower time complexity for testing larger numbers of scenarios.
Compatibility - UTAM provides extended support through its "UTAM Chrome Extension," which allows users to check which page objects and methods can be utilized to automate the currently opened page on the browser.
Image Credits - UTAM Chrome Extension Listing
Flexibility - UTAM allows for testing of features and functionalities that cannot be covered through a test class.
Productivity Boost - By utilizing UTAM, a single automation resource can write 4-7 complex scenarios per day, which is not feasible with other frameworks due to the time-consuming task of finding locators. This ultimately leads to reduced resource requirements and increased profitability.
Scalability: As Salesforce applications grow, UTAM's JSON-based page objects facilitate the management of an expanding UI component library. This scalability means you can handle complex, large-scale applications without a proportional increase in testing effort.
Collaboration: UTAM's use of JSON democratizes test automation. It's accessible not just to developers but also to QA teams and business analysts, fostering a collaborative environment where everyone can contribute to quality assurance.
Maintainability: With Salesforce's frequent updates, traditional test maintenance can be overwhelming. UTAM reduces this burden by allowing UI changes to be reflected in one place — the JSON files. This not only saves time but also ensures that tests remain relevant without extensive rewriting.
Adoption - Many big firms have already adopted and implemented the UTAM framework and have begun training their resources on it. They see this solution as the future of Salesforce testing.
Consistency: By centralizing how UI elements are accessed in tests, UTAM ensures that every test interacts with the UI in the same way, minimizing test flakiness and improving reliability.
Adaptability: In fast-paced development environments like agile and DevOps, UTAM's design supports quick iterations. It fits seamlessly into CI/CD pipelines, ensuring that testing keeps pace with development without becoming a bottleneck.
Support for Modern Salesforce Features: Specifically designed with Salesforce's Lightning Web Components (LWC) in mind, UTAM ensures that testing strategies evolve alongside Salesforce's advancements, providing a future-proof approach to UI testing.
Key Benefits over existing solutions
Dynamic DOM Handling
Salesforce is an application that changes with each release, which can impact the existing DOM of Salesforce pages and components. In salesforce test automation, changes in the DOM structure can cause test scripts to fail as they interact with the elements present on the DOM. For frameworks such as Selenium and Protractor, changing element locators manually can be time-consuming and repetitive work. However, UTAM simplifies this task by providing updated page objects for every release. To incorporate these changes into our repository, all we need to do is run the update command.
Shadow DOM Simplified
Testing components that implement shadow DOM can be challenging for frameworks like Selenium and Protractor, as interacting with such elements often requires the use of long Xpaths, which can be tedious and error-prone. However, with the use of UTAM, an open-source tool that provides extended support and relies on CSS selectors, testing these components becomes easier and less complicated.
Automated Conversion
In other tools, we need to manually write JSON for the given HTML code. However, with UTAM's generator, we can convert HTML code into UTAM JSON and then pass it to the UTAM compiler, which will convert it into executable JavaScript, TypeScript, and Java code.
Limitations
The UTAM model is still under development by Salesforce, so it may have some minor and medium-level issues that they are continuously working to resolve.
While training novice-level resources on UTAM, you may encounter some difficulties initially. However, as you delve deeper into the framework, you may find it easier to use than other tools.
Mindset Shift for QA Engineers: The shift to defining page objects in JSON can be daunting for teams accustomed to traditional programming languages. While JSON is straightforward, the concept of using it for test automation might require new learning or training, especially for those less familiar with JSON or the specifics of UTAM's grammar.
Complexity in Dynamic UIs: While UTAM excels at handling static or semi-dynamic UI elements, highly dynamic or complex interfaces can challenge its capabilities. For UIs where elements are created or modified on-the-fly, keeping the JSON definitions up-to-date can be labor-intensive. This might necessitate frequent updates or even a hybrid approach with other testing methods.
Limited Ecosystem: Compared to more established frameworks like Selenium, UTAM's community and ecosystem are still growing. This might mean fewer plug-ins, less third-party support, and a smaller pool of shared resources or pre-built page objects for common scenarios. This limitation can affect the speed of adoption and the availability of ready-to-use solutions.
Performance Overhead: The process of compiling JSON into executable code can introduce an additional step in the test automation pipeline. While this overhead is generally minor, in high-frequency testing environments, this can add up, potentially slowing down the overall testing cycle.
Dependency on Frameworks: UTAM is designed to work with certain test automation frameworks like WebDriverIO. This dependency means that if your organization is already invested in another framework, integrating UTAM could require significant adjustments or might not be feasible without additional overhead.
Debugging Challenges: Debugging JSON-based tests can be less intuitive than with conventional programming languages. When issues arise, tracing them back through JSON to the actual UI elements can be more complex, especially for those new to this paradigm.
Maintenance of JSON Files: Over time, as the application evolves, maintaining the JSON files can become cumbersome, especially if not all changes to the UI are immediately reflected in the JSON. This requires disciplined practices in version control and documentation to keep everything in sync.