Assertions are a fundamental component of testing; they help answer the question, “Is my application behaving as expected?”
At a high level, a browser or mobile test consists of the following:
- An action in the application under test, such as clicks, entering text, and visiting a URL.
- Assertion(s) to verify that the previous actions yielded the expected result.
For example, after taking the actions to log into an application, a good assertion would validate that these actions yielded the expected results. In this instance, after logging in, the assertion validates that the username appears on the page.
This article provides a high-level overview on assertions in the mabl Trainer.
For more general guidance on creating assertions, see our article on assertion best practices.
Types of assertions
In the mabl Trainer, you can make assertions against the following:
- The entire page
- A specific page element
- Variables
- The current URL - browser tests only
- Cookies - browser tests only
- Emails
- Downloaded files
Which assertion should I use?
Assertions define the logic mabl should use to confirm that your application is in the correct state at a specific step in a test run. The following table offers recommended assertions for different goals.
| Goal | Recommended assertion |
| Verify what the page looks like | Screen assertion |
| Check a property or attribute of a specific element | Element assertion (HTML or CSS) |
| Validate something complex, like image or content quality | Element assertion (visual) |
| Confirm the test is on the right page | URL assertion |
| Check a cookie value | Cookie assertion |
| Check a variable’s value | Variable assertion |
| Validate the contents of a downloaded file | Download assertion |
Assertion settings
The following settings can be configured for element, variable, URL, and cookie assertions:
Ignore case
When enabled, mabl checks that the value matches what you expect without regard to what letters are in uppercase or lowercase. For example, if your application displays names in all capital letters in some parts (“SMITH”) and only partially capitalized in other parts (“Smith”), then case insensitive assertions could be used to validate the same name is being displayed in both areas.
Note
The Ignore case setting may behave unexpectedly for certain characters and languages where casing exists and the rules different significant from standard English. For example, the dotted uppercase “İ” character is not the equivalent of the dotted lowercase “i”.
Failure options
Indicate what should happen if the assertion fails:
| Option | Details |
| Fail immediately | If the assertion fails, the test stops running and fails. This is the default option. |
| Fail at end of test | If the assertion fails, the test continues running and is marked failed at the end. |
| Continue on failure & mark warning | If the assertion fails, the step still passes and is marked with a warning. |
“Fail at end of test” and “Continue on failure & mark warning” are two implementations of a soft assertion. Soft assertions are useful for asserting non-functional aspects, such as element labels and style, without stopping the test from executing.
Failure options apply to local and cloud runs. When playing steps in the Trainer, a failed assertion will immediately stop Trainer playback if it is marked “fail immediately” or “fail at end of test.” Assertions marked “continue on failure & mark warning” always pass and never stop Trainer playback.
Additional details and limits
- Character limit: assertions have a character limit of 300. If you are trying to assert on an element that has more than 300 characters, mabl will capture only up to 300 characters.
-
Lexicographic comparisons: if an assertion type involves a comparison - greater than, less than, greater than or equals, and less than or equals - and the assertion values cannot be interpreted as numbers, mabl orders the values according to their characters’ Unicode code points. In this standard, the order of values from lowest to highest is as follows:
- Numbers (123…)
- Capital letters (ABC…)
- Lowercase letters (abc…)
-
matches regex: if the assertion type is “matches regex”, keep in mind that mabl uses JavaScript regular expression syntax. You can wrap the pattern in forward slashes and add optional flags such as
ifor case-insensitive search andmfor multiline matching. If the forward slashes are omitted, mabl asserts against the provided pattern as if no flags were passed in.