Skip to content

UI.hasClass() ​

Asserts that an element has the specified CSS class.

If the element does not have the class, the assertion fails and the test will fail.

Usage ​

js
UI.hasClass(element: string, className: string)

Parameters ​

ParameterTypeDescription
elementstringElement to target — by CSS or XPath selector.
classNamestringCSS class name to assert (without the leading .)

Example ​

In this example, we use UI.hasClass to check if the has-error CSS class is applied to a form field when the form is submitted with invalid values.

js
I.goTo("https://mystore.com")
I.click("Login") // <- go to login page

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

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