How-to
Element count assert (toHaveCount)
Element count assert (toHaveCount)
Expect assertion: the Target locator matches the given number of elements. Value is an integer from 0 with no leading zeros and at most 9 digits.
Step model
action_name | toHaveCount |
| Group | Expect |
| Target | Required |
| Value | Required (count) |
| expected_value | Unused |
| TEST_ACCOUNT | Allowed |
| Do not confuse with | toBeVisible |
Target/Value facts match the source-of-truth catalog and Autotest step.
Prerequisites
- The locator is meant to match several elements. For one element, prefer an exact locator and
toBeVisible.
Steps
- Add a
toHaveCountstep. - Set Target.
- Enter the count in Value, for example
3. - Save.
The step is stored on the autotest. Next - neighbouring steps or autotest run creation.
Examples
Three rows
Fields in the UI:
| Field | Value |
|---|---|
action_name | toHaveCount |
| Target | kind ROLE, value row |
| Value | 3 |
| value_source_type | INLINE |
Step JSON fragment (copy-paste):
json
{
"action_name": "toHaveCount",
"target": {
"kind": "ROLE",
"value": "row"
},
"value_text": "3",
"value_source_type": "INLINE"
}Common mistakes
03and an empty string are rejected. Zero is written as0.
Screenshots
Screenshots of the step form for toHaveCount will be added here in a later pass.
Did this page help?