Loading
Salesforce Enforces New Security Requirements in Summer 2026Read More
How to Write End-to-End Tests with UTAM for Omniscripts

How to Write End-to-End Tests with UTAM for Omniscripts

To fully automate and stabilize your guided user flows, structure and build end-to-end tests for Omniscripts by using UTAM's commands.

Sample UTAM Methods for Omniscripts

These methods are critical parts of the Omniscript Page Objects (POs). Use them to replicate essential user actions, from loading the component to navigating between steps and invoking actions in your automated tests.

Method Component Purpose Example Action
waitForVisible() General PO Ensures the UI component finished loading and is ready for interaction. Waits for the spinner to disappear.
getSteps() Omniscript Retrieves a list of the flow's steps so you can target a specific one (example, index 0). Finds the first step in the flow.
getElementWithName() OmniscriptStep Retrieves a specific element PO (example, a text input) using the element's Name (API Name). Targets the Username input field.
getElements OmniscriptStep Retrieves a list of all elements of a particular type from a given omniscript step. Targets all text elements in a step.
setValue(value) Input POs Simulates a user typing input into a field. username.setValue("testdata");
getNextButton().click() Omniscript Simulates the user clicking the navigation button. Moves the flow from Step 1 to Step 2.
isValid() / getErrorMessage() Input POs Checks if the element currently passes validation rules. Indicates that a field is required: Error: Field is required.
invokeAction() Action POs Triggers actions linked to the component, such as Remote Actions. Executes a button-linked server-side process.

Write End-to-End Tests for Omniscripts with UTAM

Use these steps to structure your UTAM test class, set up your environment, and run the main logic required for an end-to-end Omniscript validation. This example uses Maven.

Note
Note Before you start writing end-to-end tests for Omniscripts using UTAM, make sure you have a good understanding of UTAM.
    1. Configure the initial setup. See UTAM, Java, and JavaScript.
    2. Setup and navigation: Before writing your test logic, make sure that your environment is set up and your test class is configured.
      • Helper methods: It's highly recommended to abstract login, navigation, and environment configuration into reusable helper methods defined in a base test class (example, SalesforceWebTestBase). This keeps your test logic clean and maintainable.

      • Test setup: Use the @BeforeTest annotation to define the setup logic, including browser initialization and logging into the target Salesforce org.

        // Handles browser setup and login before tests run
        @BeforeTest
        public void setup() {
            setupChrome();
            login(testEnvironment, "home");
        }
        
      • Omniscript navigation: Use a helper method (example, goDirectlyToOmniscript) to navigate to the Omniscript's specific App URL, returning the main Omniscript Page Object (PO).
    3. Test logic: The actual test method uses the @Test annotation (example, for Maven) and orchestrates the user interaction sequence.
      1. Load and navigate to the first step: Make sure that the test successfully retrieves the Omniscript PO and waits until the UI is ready.
        1. Retrieve PO: Call your helper method to launch the Omniscript and assign it to the main Omniscript PO.

          Example: Omniscript omniscript = goDirectlyToOmniscript("OmniScript", "Test", "English", "lightning");

        2. Wait for load: Use the omniscript.load() and omniscript.waitForVisible() methods to wait for the UI spinner to disappear and the component to be ready for interaction.
        3. Get step PO: Retrieve the PO for the first step in the flow. The getSteps() method returns a list of steps, where the first step is at index 0.

          Example: OmniscriptStep step1 = omniscript.getSteps().get(0);

        4. Wait for step: Make sure that the step is fully visible before attempting to interact with elements.

          Example: step1.waitForVisible();

      2. Interact with elements and assert input: To interact with an element, you must retrieve its specific PO using its Element name (not the Label).
        1. Get element PO: Retrieve the PO for an element inside the step using getElementWithName(), passing the element's name and its specific PO class.

          Example: OmniscriptText username = step1.getElementWithName("Username", OmniscriptText.class);

        2. Set Value: Input the test data using the setValue() method.

          Example: username.setValue("omnistudio");

        3. Assert Input: Verify that the element correctly holds the value you set.

          Example: Assert.assertEquals(username.getValue(), "omnistudio", "The value of Username is not correct");

      3. Advance flow and test actions for Omniscripts: Test the primary actions of the guided flow, such as navigation and Remote Actions.
        1. Navigate next: Click the Next button to advance the flow or trigger validation checks.

          Example: omniscript.getNextButton().click();

        2. Test Remote Action: Retrieve the PO for an action element and use the invokeAction() method to test the functionality.

          Example: OmniscriptRemoteAction submit = step2.getElementWithName("Submit", OmniscriptRemoteAction.class); submit.invokeAction();

    4. Testing element validation: Testing validation logic is critical for ensuring data quality within the Omniscript. This step also ensures that required fields show an error when empty and allow navigation only when valid.
      1. Leave the required field empty.
      2. Click the Next button or trigger the validation.
      3. Assert that the element is not valid using assertFalse("Should show error after navigation attempt", element.isValid());
      4. Assert that the expected error message is displayed using assertEquals(expectedMessage, element.getErrorMessage());
      5. Fill the element and assert that the element is now valid using assertTrue("Should be valid after setting value", element.isValid());
  • Sample Omniscript Test (Java)
    This example demonstrates the complete end-to-end user journey, including setup, navigation, interaction, and assertion across two steps.
 
Loading
Salesforce Help | Article