Expect
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" that let you validate different things on the browser or an element object.
Matcher Options
Every matcher can take several options that allows you to modify the assertion:
Command Options
| Name | Type | Details |
|---|---|---|
| wait | number | time in ms to wait for expectation to succeed. Default: 3000 |
| interval | number | interval between attempts. Default: 100 |
| message | string | user message to prepend before assertion error |
String Options
This options can be applied in addition to the command options when strings are being asserted.
| Name | Type | Details |
|---|---|---|
| ignoreCase | boolean | apply toLowerCase to both actual and expected values |
| trim | boolean | apply trim to actual value` |
| containing | boolean | expect actual value to contain expected value, otherwise strict equal. |
| asString | boolean | might be helpful to force converting property value to string |
Number Options
This options can be applied in addition to the command options when numbers are being asserted.
| Name | Type | Details |
|---|---|---|
| eq | number | equals |
| lte | number | less then equals |
| gte | number | greater than or equals |
Browser Matchers
toHaveUrl
Checks if browser is on a specific page.
Usage
toHaveTitle
Checks if website has a specific title.
Usage
Element Matchers
toBeDisplayed
Calls isDisplayed on given element.
Usage
toBeVisible
Same as toBeDisplayed.
Usage
toExist
Calls isExisting on given element.
Usage
toBePresent
Same as toExist.
Usage
toBeExisting
Same as toExist.
Usage
toBeFocused
Checks if element has focus. This assertion only works in a web context.
Usage
toHaveAttribute
Checks if an element has a certain attribute with a specific value.
Usage
toHaveAttr
Same as toHaveAttribute.
Usage
toHaveAttributeContaining
Checks if an element has a certain attribute that contains a value.
Usage
toHaveAttrContaining
Same as toHaveAttributeContaining.
Usage
toHaveClass
Checks if an element has a certain class name.
Usage
toHaveClassContaining
Checks if an element has a certain class name that contains provided value.
Usage
toHaveProperty
Checks if an element has a certain property.
Usage
toHaveValue
Checks if an input element has a certain value.
Usage
toHaveValueContaining
Checks if an input element contains a certain value.
Usage
toBeClickable
Checks if an element can be clicked by calling isClickable on the element.
Usage
toBeDisabled
Checks if an element is disabled by calling isEnabled on the element.
Usage
toBeEnabled
Checks if an element is enabled by calling isEnabled on the element.
Usage
toBeSelected
Checks if an element is enabled by calling isSelected on the element.
Usage
toBeChecked
Same as toBeSelected.
Usage
toHaveHref
Checks if link element has a specific link target.
Usage
toHaveLink
Same as toHaveHref.
Usage
toHaveHrefContaining
Checks if link element contains a specific link target.
Usage
toHaveLinkContaining
Same as toHaveHrefContaining.
Usage
toHaveId
Checks if element has a specific id attribute.
Usage
toHaveText
Checks if element has a specific text.
Usage
toHaveTextContaining
Checks if element contains a specific text.
Usage
toBeDisplayedInViewport
Checks if an element is within the viewport by calling isDisplayedInViewport on the element.
Usage
toBeVisibleInViewport
Same as toBeDisplayedInViewport.
Usage
toHaveChildren
Checks amount of fetched elements using $$ command.
Usage
toBeElementsArrayOfSize
Same as toHaveChildren.