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_nametoHaveCSS
GroupExpect
TargetRequired
ValueRequired (css_property)
expected_valueUsed
TEST_ACCOUNTAllowed
Do not confuse withtoHaveAttribute, toHaveClass

Target/Value facts match the source-of-truth catalog and Autotest step.

Prerequisites ​

  1. You know the property name and the computed value as the browser reports it.

Steps ​

  1. Add a toHaveCSS step.
  2. Set Target.
  3. In Value enter the property name, for example color.
  4. In the expected value enter the computed value, for example rgb(0, 0, 0).
  5. Save.

The step is stored on the autotest. Next - neighbouring steps or autotest run creation.

Examples ​

Heading color ​

Fields in the UI:

FieldValue
action_nametoHaveCSS
Targetkind ROLE, value heading, name Cart
Valuecolor
value_source_typeINLINE
expected_valuergb(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_value is required. toHaveAttribute may omit the expected value; toHaveCSS may 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.

Version 1.0.0 · Last updated 2026-10-03

Did this page help?