Assert the presence of a CSS class on an element.


UI.hasClass(target, cssClass)
Parameter Type Remarks
target string Expression to target an element. This can be a text, CSS selector, or XPATH selector.
cssClass string CSS class that should exist on the element.

# Validating that the error class is applied to an invalid form field

I.click("Login") // <- go to login page

// fill in the username, and wrong password
I.fill("Username", "john")
I.fill("Password", "WRONGPASSWORD") 

// assert that the #password-field-group has the "has-error" css class
UI.hasClass("#password-field-group", "has-error")

We can use UI.hasClass to check if the has-error CSS class is applied to an form field when the form is submitted with invalid values, like an invalid password.