With GenAI assertions, you can validate more complex aspects of your application, such as text content, quality, and images. This article explains how to create a GenAI Assertion, including tips for selecting elements, working with viewport sizes, and returning results in non-English languages.
Advanced AI
GenAI Assertions are available as an add-on to your mabl subscription. Contact your customer success manager to learn more.
How to create a GenAI Assertion
To create a GenAI Assertion, open your web or mobile application in the mabl Trainer and get your application in the desired state. Then take the following steps:
- In the Trainer window, click on the check mark icon to create a new assertion.
- Identify what you want to validate:
- To validate the entire page, click on GenAI Screen Capture in the Trainer window.
- To validate part of the page, select the element that you want to validate in the browser window and select AI in the assertion menu.
- In the Assertion description field, describe what you want to verify using natural language. Your assertion description may include references to variables used in the test, including values from DataTables and other data-driven variables. For example, "Verify that the results are relevant to {{@search_input}}."
- Click on Test assertion. The first time you test the assertion, mabl generates assertion criteria. This criteria is sent with the assertion description to the LLM to provide a consistent set of criteria to evaluate as part of your assertion. If you iterate on the assertion description, mabl updates the assertion criteria to reflect the current state of the description.
- Choose a behavior on failure. By default, AI assertions are set to "Fail at end of test."
- Click OK.
For more guidance on writing an assertion description, see the article on best practices for GenAI Assertions.
Selecting from overlapping elements
When you select an element for a GenAI Assertion, the mabl Trainer highlights the element with the highest z-index at your mouse position by default.
If you want to target a different overlapping element, hold [SHIFT] and use the up and down arrow keys to highlight different elements at your mouse position. Once the Trainer highlights the correct element, release the [SHIFT] key and click on the element.
Iterating through overlapping elements
GenAI Assertions and viewport size
Unlike HTML and CSS assertions, GenAI Assertions evaluate based on the screenshot of the element, not the DOM or the page source.
- For a GenAI Screen Capture assertion, the screenshot only includes the portion of the page that is currently visible in the screenshot.
- For a GenAI Assertion on a specific element, the screenshot only includes the portion of the element that is visible in the viewport.
If you assert on something that isn't fully visible in the viewport, such as a long table element, the off-screen part of the element will not be evaluated.
To resize the window in a browser test, add a "set viewport" step before the assertion. The "set viewport" step ensures that the test uses the new viewport size for the GenAI Assertion during test execution. If you manually resize the browser window during a training session, the browser will still use the size specified in the "set viewport" step when run in the cloud.
Returning output in non-English languages
The models used for GenAI Assertions are biased towards returning results in English. If you submit a prompt in a non-English language, you can increase the likelihood of returning the result in the same language by specifying the desired output language.
For example, to return results in Japanese, add the sentence, "Return the results in Japanese" to the end of the prompt.
Execution limits
GenAI Assertions are unlimited during training so that you can iterate on your assertion as much as you need. During execution, however, keep in mind the following limitations:
- Cloud runs: GenAI Assertions are limited to 6 per test. If they exceed this limit, the test will fail.
- CI Runner and CLI local runs: Any GenAI Assertions will fail when run locally in the mabl CLI or the CI Runner.
- Performance tests: GenAI Assertions will fail when run within the context of a performance test.