Assertions Overview
Assertions in AI Recorder allow you to confirm that your application behaves as expected during test execution. They help ensure that users see the right information, critical assets are loaded, and unintended states do not occur.
Types of Assertions
This overview explains the different assertion types available and provides guidance on deciding which ones to use in various scenarios.
Text-Based Assertions
- Verify Text Is Found on the Page – Confirms that specific text appears anywhere on the page.
- Verify Text Is Not Found on the Page – Ensures that unwanted or outdated text does not appear.
- Verify Text in Relation to Other Text – Ensures context by verifying that two related pieces of text appear together, such as a label and its value.
Element and Attribute Assertions
- Verify Element Property – Confirms that an HTML element has the correct attribute or property value. Useful for links, images, input fields, and custom attributes.
Page-Level Assertions
- Verify Page Title and URL Path – Validates navigation by checking that the page has the correct title or URL path.
- Verify Page Snapshot – Captures a group of elements as a text-based snapshot, ensuring parts of the UI remain consistent across runs.
File Assertions
- Validate File Was Downloaded – Confirms that a file download occurred and that the file name, extension, or pattern matches what is expected.
Deciding Which Assertion to Use
Choosing the right assertion depends on your test goal. Below are guidelines for making the best choice.
When Verifying Text
- Use Verify Text in Relation to Other Text when possible, since it provides stronger validation and ensures correct context. For example, checking that “Price” is paired with “$30”.
- Use Verify Text Is Found on the Page when you only need to know a text string is visible anywhere, without context.
- Use Verify Text Is Not Found on the Page when ensuring that errors, outdated messages, or deleted data are absent.
Best Practice
For text validation, use in relation instead of standalone text checks when possible. It reduces false positives by anchoring the text to its expected context.
When Verifying Attributes or Links
- Use Verify Element Property to check properties like
href
,src
,alt
, orplaceholder
. - Favor this assertion for cases where content may be hidden or non-visible but still critical to function. This is one of the most powerful verifications for ensuring correct configuration of elements.
When Verifying Navigation
- Use Verify Page Title and URL Path to confirm users land on the right page after a navigation event, login, or redirect.
- Choose title checks when verifying identity of a page.
- Choose URL path checks when validating routing behavior.
When Verifying UI Layout
- Use Verify Page Snapshot to validate structured regions with multiple related elements, such as forms or toolbars.
- Avoid using snapshots for highly dynamic content, since snapshot currently does not support dynamic test data.
- Keep snapshots focused and minimal for easier maintenance.
When Verifying Downloads
- Use Validate File Was Downloaded for cases where a test triggers a download, such as reports, invoices, or receipts.
- Choose exact match for static filenames, or regex for dynamic filenames with timestamps.