---
schema_version: "1"
id: 84037f4d42286f8cf3bd089610b35c1fd82df89c10a24f35ed81d3370b53062f
title: How to Write End-to-End Tests with UTAM for Flexcards
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_utam_how_to_write_tests_flexcard.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_utam_how_to_write_tests_flexcard.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8ebbb1a8a4d99ccb8391ae93d134a357c82c520936adbd934504ecda8de79962
description: To fully automate and stabilize your guided user flows, structure and build end-to-end tests for Flexcards by using UTAM's commands.
products:
  - Omnistudio
release: "264"
---
# How to Write End-to-End Tests with UTAM for Flexcards

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

## Sample UTAM Methods for Flexcards

These methods are critical parts of the Omniscript Page Objects (POs). Use them to replicate essential user actions.

   
| Method | Component | Purpose | Example Action |
| --- | --- | --- | --- |
| `waitForVisible()` | General PO | Ensures the UI component has finished loading and is ready for interaction. | Waits for the spinner to disappear. |
| `getFlexCardStates()` | Flexcard | Retrieves a list of the states in the flexcard. | Finds the first state in the flexcard. |
| `getElements()` | FlexCardState | Retrieves the list of all elements in a flexcard state. | Finds the number of elements in a flexcard state. |
| `isValid() / getErrorMessage()` | Input POs | Checks if the element currently passes validation rules. | Confirms a required field shows: `Error: Field is required.` |

## Write End-to-End Tests for Flexcards 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 Flexcard validation. This example uses [Maven](https://maven.apache.org/).

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio-264-0-0-production-enus/f526eaa8-ae05-487a-8944-4bb99b0b78ac/images/icon_note.png)

Note Before you start writing end-to-end tests for Flexcards using UTAM, make sure you have a good understanding of [UTAM](https://utam.dev/guide/introduction).

- 1. Configure the initial setup. See [UTAM](https://utam.dev/guide/introduction), [Java](https://github.com/salesforce/utam-java-recipes), and [JavaScript](https://github.com/salesforce/utam-js-recipes).
    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");
            }
            ```
    3. Test logic: The actual test method uses the `@Test` annotation (example, for Maven) and orchestrates the user interaction sequence.
        1. Load and wait for visibility: After retrieving the Flexcard PO, always wait until it is visible before interacting with elements. This makes sure that the UI and underlying LWC components are rendered.
            
            Example:
            
            ```
            FlexCard flexcard = goDirectlyToFlexcard();
            flexcard.waitForVisible();
            ```
        2. Retrieve card state and elements: Each Flexcard contains one or more `FlexcardState` objects. Access the required state and retrieve its list of elements:
            
            Example:
            
            ```
            FlexCardState state = flexcard.getFlexCardStates().get(0);
            List<Element> elements = state.getElements();
            ```
        3. Testing element validation:
            1. To read labels or values displayed by the Flexcard, access the nested `OutputField` PO:
                
                Example:
                
                ```
                String label = elements.get(0) .getOutputField()..getLabel().getText();
                ```
            2. Assert that the label matches the expected value:.
                
                Example:
                
                ```
                Assert.assertEquals(label, "Result", "The label is not correct");
                ```

- **[Sample Flexcard Test (Java)](https://help.salesforce.com/s/articleView?id=xcloud.os_utam_sample_test_flexcard.htm&release=264.0.0&type=5)**  
    This example demonstrates the complete end-to-end user journey, including setup, navigation, and interaction with Flexcards.