How-to
CSS assert (toHaveCSS)
CSS assert (toHaveCSS)
Expect assertion: the computed CSS property of the Target equals the expected value. The property name is Value. The computed value is expected_value. Both fields are required.
Step model
action_name | toHaveCSS |
| Group | Expect |
| Target | Required |
| Value | Required (css_property) |
| expected_value | Used |
| TEST_ACCOUNT | Allowed |
| Do not confuse with | toHaveAttribute, toHaveClass |
Target/Value facts match the source-of-truth catalog and Autotest step.
Prerequisites
- You know the property name and the computed value as the browser reports it.
Steps
- Add a
toHaveCSSstep. - Set Target.
- In Value enter the property name, for example
color. - In the expected value enter the computed value, for example
rgb(0, 0, 0). - Save.
The step is stored on the autotest. Next - neighbouring steps or autotest run creation.
Examples
Heading color
Fields in the UI:
| Field | Value |
|---|---|
action_name | toHaveCSS |
| Target | kind ROLE, value heading, name Cart |
| Value | color |
| value_source_type | INLINE |
| expected_value | rgb(0, 0, 0) |
Step JSON fragment (copy-paste):
json
{
"action_name": "toHaveCSS",
"target": {
"kind": "ROLE",
"value": "heading",
"name": "Cart"
},
"value_text": "color",
"value_source_type": "INLINE",
"expected_value": "rgb(0, 0, 0)"
}Common mistakes
expected_valueis required.toHaveAttributemay omit the expected value;toHaveCSSmay not.- Write the computed value, not the stylesheet source. A color often arrives as
rgb(...).
Screenshots
Screenshots of the step form for toHaveCSS will be added here in a later pass.
Did this page help?