- Print
- DarkLight
Assertions on elements in a page
1. General assertions
The assertions in this section work on any kind of HTML elements.
Visibility assertion
Keyword | Description |
---|---|
Element Should Be Visible | Verify that the target element is visible |
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
Keyword | Description |
---|---|
Element Text Should Be | Verify that the string of the target element exactly matches the specified string |
Element Should Contain | Verify that the target element contains the specified string |
Element Should Not Contain | Verify that the element does not contain the specified string of characters |
Element text should start with | Verify that the string of the target element starts with the specified string |
Element text should not start with | Verify that the string of the target element does not start with the specified string |
Element text should not be empty | Verify 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
Keyword | Description |
---|---|
Element text should match RegExp | Verify that the string of the target element matches the given RegExp |
Element text should not match RegExp | Verify 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
orGood night
- Matching examples:
Good night
,Good morning, Hatty!
- Matching examples:
- Text that starts with
w[ow]+w$
- Text that matches
w
followed by one or moreo
orw
and ends withw
- Matching examples:
wowow
,Oh, wow
- Matching examples:
- Text that matches
^\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
- Matching examples:
- Text that starts with 3 consecutive digits followed by a hyphen and ends with 4 consecutive digits
For more information about its syntax, see Regular expression syntax cheat sheet (MDN)
- Text assertions with RegExp will fail when the given RegExp contains any syntax error.
- Flags such as
i
(ignore casing) orm
(multiline) are not supported.
Checkbox assertions
Keyword | Description |
---|---|
Checkbox Should Be Selected | Verify that the checkbox or radio button is checked. |
Checkbox Should Not Be Selected | Verify that the checkbox or radio button is not checked. |
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.
Keyword | Description |
---|---|
Number should be greater than | Verify that the number is greater than the given value |
Number should be smaller than | Verify that the number is smaller than the given value |
Number assertions will fail when the target is not a number.
Class assertions
Keyword | Description |
---|---|
Element classname should contain | Verify that the element contains the given class name |
Element classname should not contain | Verify 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
.
Keyword | Description |
---|---|
Element Should Be Enabled | Verify that the element is interactable (Checks if the element has not disabled or readonly attribute) |
Element Should Be Disabled | Verify that the element is not interactable (Checks if the element has disabled or readonly attribute) |
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.
Keyword | Description |
---|---|
Textfield Value Should Be | Verify that the content entered in the text field exactly matches the specified string |
Textfield Should Contain | Verify that the content entered in the text field contains the specified string |
Textarea assertions
The following assertions work on TEXTAREA
elements.
Keyword | Description |
---|---|
Textarea Value Should Be | Verify that the content entered in the text area exactly matches the specified string |
Textarea Should Contain | Verify 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.
Keyword | Description |
---|---|
List Selection Should Be | Verify that the option that match the specified string is selected |
List Should Have No Selections | Verify 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.