How-to
Attribute assert (toHaveAttribute)
Attribute assert (toHaveAttribute)
Asserts that Target has the attribute named in Value. The expected attribute value goes in expected_value when you set one.
Step model
action_name | toHaveAttribute |
| Group | Expect |
| Target | Required |
| Value | Required (attribute_name) |
| expected_value | Used |
| TEST_ACCOUNT | Allowed |
| Do not confuse with | toHaveText, toBeVisible |
Target/Value facts match the source-of-truth catalog and Autotest step.
Prerequisites
- The element with the attribute is on the page.
Steps
- Add a
toHaveAttributestep. - Set Target.
- In Value put the attribute name (
href,src,aria-label). - Optionally fill Expected value (
expected_value). - Save.
The step is stored on the autotest. Next - neighbouring steps or autotest run creation.
Examples
Link points to the right path
Fields in the UI:
| Field | Value |
|---|---|
action_name | toHaveAttribute |
| Target | kind ROLE, value link, name Docs |
| Value | href |
| value_source_type | INLINE |
| expected_value | /docs/ |
Step JSON fragment (copy-paste):
json
{
"action_name": "toHaveAttribute",
"target": {
"kind": "ROLE",
"value": "link",
"name": "Docs"
},
"value_text": "href",
"expected_value": "/docs/",
"value_source_type": "INLINE"
}Common mistakes
- Value holds the attribute name, not its contents.
- Put the contents in
expected_value.
Screenshots
Screenshots of the step form for toHaveAttribute will be added here in a later pass.
Did this page help?