Assertions on elements in a page
  • 04 Oct 2023
  • 4 Minutes to read
  • Contributors
  • Dark
    Light

Assertions on elements in a page

  • Dark
    Light

Article Summary

1. General assertions

The assertions in this section work on any kind of HTML elements.

Visibility assertion

KeywordDescription
Element Should Be VisibleVerify that the target element is visible
Tip

This assertion will fail if the target element exists in the HTML code but is not visible due to display: none;, visibility: hidden; or opacity: 0;, or the target element is outside of viewport. See also the following FAQ:
What is the difference between "Page Should Contain Element" and "Element Should Be Visible"?

Basic text assertions

KeywordDescription
Element Text Should BeVerify that the string of the target element exactly matches the specified string
Element Should ContainVerify that the target element contains the specified string
Element Should Not ContainVerify that the element does not contain the specified string of characters
Element text should start withVerify that the string of the target element starts with the specified string
Element text should not start withVerify that the string of the target element does not start with the specified string
Element text should not be emptyVerify that the target element contains one or more non-space characters (Space characters include spaces, tabs, line breaks such as LF, CR, etc.)

Text assertions with RegExp

KeywordDescription
Element text should match RegExpVerify that the string of the target element matches the given RegExp
Element text should not match RegExpVerify that the string of the target element does not match the given RegExp

Using RegExp, you can create pretty flexible text assertions that fit your use case. Here are some RegExp ideas for your reference:

  • ^Good (morning|night)
    • Text that starts with Good morning or Good night
      • Matching examples: Good night, Good morning, Hatty!
  • w[ow]+w$
    • Text that matches w followed by one or more o or w and ends with w
      • Matching examples: wowow, Oh, wow
  • ^\d{3}-\d{4}$
    • Text that starts with 3 consecutive digits followed by a hyphen and ends with 4 consecutive digits
      • Matching examples: 123-4567, 999-0000

For more information about its syntax, see Regular expression syntax cheat sheet (MDN)

Note
  • Text assertions with RegExp will fail when the given RegExp contains any syntax error.
  • Flags such as i (ignore casing) or m (multiline) are not supported.

Checkbox assertions

KeywordDescription
Checkbox Should Be SelectedVerify that the checkbox or radio button is checked.
Checkbox Should Not Be SelectedVerify that the checkbox or radio button is not checked.
Tip

Autify's ML-powered assertions on checkboxes work not only on <input type="checkbox"> elements but also any elements that look like checkboxes, such as <div> and <span> elements disguised as checkboxes using styles!

Number assertions

The following assertions are based on the numbers and ". (period)" .
Specifically, assertions are made on the first digit (0 - 9) through all non-numeric characters (including commas) in the text. Thus, for example "$1,234", if the text contains ", (comma)", the assertion is made for 1 only.

KeywordDescription
Number should be greater thanVerify that the number is greater than the given value
Number should be smaller thanVerify that the number is smaller than the given value
Note

Number assertions will fail when the target is not a number.

Class assertions

KeywordDescription
Element classname should containVerify that the element contains the given class name
Element classname should not containVerify that the element does not contain the given class name

Class names are detected by partial matching. For example, if you specify state-1 for the class name, it matches with the following:

  • <div class="state-10">
  • <div class="sample-a state-1">

One of the use cases of this assertion can be to verify the presence or absence of a class to which a particular style is applied.

2. Interactivity assertions

The following assertions work on BUTTON, INPUT, SELECT,TEXTAREA, OPTGROUP, OPTION, and FIELDSET.

KeywordDescription
Element Should Be EnabledVerify that the element is interactable (Checks if the element has not disabled or readonly attribute)
Element Should Be DisabledVerify that the element is not interactable (Checks if the element has disabled or readonly attribute)
Note

Even if the element looks like a <button> or a <select> element, these commands will not be shown if it is actually implemented as a different element decorated by CSS. And also, Elements that don’t have a disabled attribute but cannot be operated with JavaScript are considered to be enabled.

3. Form element assertions

Input assertions

The following assertions work on INPUT elements.

KeywordDescription
Textfield Value Should BeVerify that the content entered in the text field exactly matches the specified string
Textfield Should ContainVerify that the content entered in the text field contains the specified string

Textarea assertions

The following assertions work on TEXTAREA elements.

KeywordDescription
Textarea Value Should BeVerify that the content entered in the text area exactly matches the specified string
Textarea Should ContainVerify that the content entered in the text area contains the specified string

Pull-down menu assertions

The following assertions work on SELECT elements. SELECT elements let users choose an option from multiple options, and they are often referred to as a drop-down list, pull-down menu, list box, etc.

KeywordDescription
List Selection Should BeVerify that the option that match the specified string is selected
List Should Have No SelectionsVerify that nothing is selected with select with "multiple" attribute.

Note that this may not work well when multiple options are selected, and it will be supported in the future.

Tips for pull-down menu assertions

If the default option is selected for an element in a selection, it cannot be verified by List Should Have No Selections.

For example, the following screenshot shows a pulldown included in the form to request a demo of Autify, where the Company Size is displayed at the top, is not a No Selections state, but the option Company Size is selected.

If you want to check if the default choices are selected, use the "List Selection Should Be" option instead of the "List Should Have No Selections" option.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.