Assertions

You can use Assertions to verify different conditions.

Action icon Deep Equal                   

Action icon Not Deep Equal

Action icon Ok

Action icon Not Ok

Action icon Contains

Action icon Not Contains

Action icon Type of

Action icon Not Type of

Action icon Greater than

Action icon Greater than or Equals to

Action icon Less than                      

Action icon Less than or Equals to

Action icon Within

Action icon Not Within

Action icon Match

Action icon Not Match

Assertion Parameters

Verified Value

Each assertion has a switcher Assertion's switcher that allows you to select what you are going to check:

DOM Element's State

To verify a page element's state, follow these steps:

  1. Activate the Assertion's switcher - DOM mode mode with the assertion's switcher.

  2. Create a selector that returns a target element. You can do this in one of the following ways:

  3. Open the Checked Property drop-down and choose a property to verify. See Element Properties for the list of available properties.

    Selecting a property

    Note

    If you add the assertion during recording, TestCafe Studio evaluates the element properties. You can view the property's value:

    • in the property grid;
    • in the Value field next to the Checked Property field.

Function's Returned Value

To verify a function's returned value, follow these steps:

  1. Activate the Assertion's switcher - Function mode mode with the assertion's switcher.

  2. Select a desired function from the Function drop-down list.

    Important

    The Fun—Ātion list contains functions that you defined in the Define Function actions earlier in the test.

Expected Value

Some assertions have the Expected parameter that takes an expected value or code expression. You can enter a value manually or copy the value to the Expected field by clicking the Copy the value to the Expected field button.

Note
  • If you add the assertion during recording, TestCafe Studio calculates the expression and shows the result in the Value field.
  • When you specify a string value, you should put it into single quotes, for example, 'Thank you, Peter' instead of Thank you, Peter.

Assertion Options

You can add the following options to assertions:

  • Timeout - the time an assertion can take to pass (in milliseconds). The assertion retries to pass multiple times within this timeframe, and verifies the Actual parameter's value each time. The test fails if the assertion could not complete successfully within the timeout.

    To add this option, click the Add Timeout button in the assertion parameters area.

    The default timeout is used if you do not add this option. To specify the default timeout, use the Assertion Timeout options in the Record Configuration and Run Configurations dialogs.

    See Wait for Assertions to Pass for more information.

  • Message - an assertion message that is displayed in the report if the test fails. To add this option, click the Add Message button in the assertion parameters area.

Assertion Status

When TestCafe Studio evaluates an assertion during recording, it indicates whether this assertion has passed or failed. This status is displayed in the Assertion Status button.

Assertion status

An assertion can have one of the following statuses:

Assertion status - success - the assertion has passed;
Assertion status - failed - the assertion has failed;
Assertion status - not evaluated - the assertion has not been evaluated;
Assertion status - in progress - the assertion is being evalulated.

Click the Assertion Status button to re-evaluate the assertion after you make changes.

Assertion Types

Deep Equal

Asserts that a verified value equal to an expected value.

Not Deep Equal

Asserts that a verified value is not equal to an expected value.

Ok

Asserts that a verified value is true.

Not Ok

Asserts that a verified value is false.

Contains

Asserts that a verified value contains an expected value.

Not Contains

Asserts that a verified value does not contain an expected value.

Type of

Asserts that a verified value belongs to a particular type specified in the Type Name field.

Not Type of

Asserts that a verified value does not belong to a particular type specified in the Type Name field.

Greater than

Asserts that a verified value is greater than an expected value.

Greater than or Equals to

Asserts that a verified value is greater than or equal to an expected value.

Less than

Asserts that a verified value is less than an expected value.

Less than or Equals to

Asserts that a verified value is less than or equal to an expected value.

Within

Asserts that a verified value is within a range from Start Value to Finish Value. Bounds are inclusive.

Not Within

Asserts that a verified value is not within a range from Start Value to Finish Value. Bounds are inclusive.

Match

Asserts that a verified value matches the Regular Expression.

You can use the following options:

  • Global - Performs a global match.
  • Sticky - Performs a sticky search.
  • Multiline - Performs a multiline match.
  • Unicode - Unicode-related features are enabled.
  • Ignore Case - Performs a case-insensitive match.

Not Match

Asserts that a verified value does not match the Regular Expression.

You can use the following options:

  • Global - Performs a global match.
  • Sticky - Performs a sticky search.
  • Multiline - Performs a multiline match.
  • Unicode - Unicode-related features are enabled.
  • Ignore Case - Performs a case-insensitive match.

Element Properties

When you verify a page element's state, you create a selector that matches a target element and then select the element's property from the property grid.

The property grid always contains the General Properties group. If you add an assertion during recording, the property grid can also contain the following groups: CSS Properties, Attributes, Rectangle.

Note

When you add an assertion during recording, the property grid also displays property values.

General Properties

Contains properties that are common across all elements and properties that are specific to the target element.

Property Type Description
exists Boolean true if at least one matching element exists.
count Number The number of matching elements.
focused Boolean true if the element is focused.
visible Boolean true if the element is visible, that means the element does not have display: none or visibility: hidden CSS properties and has a non-zero width and height.
checked Boolean For checkbox and radio input elements, their current state. For other elements, undefined.
childElementCount Number The number of child HTML elements.
childNodeCount Number The number of child nodes.
classNames Array of String The list of element's classes.
clientHeight Number The inner height of the element, including padding but not the horizontal scrollbar height, border, or margin. See Element.clientHeight.
clientLeft Number The width of the left border of the element. See Element.clientLeft.
clientTop Number The width of the top border of the element. See Element.clientTop.
clientWidth Number The inner width of the element, including padding but not the vertical scrollbar width, border, or margin. See Element.clientWidth.
hasChildElements Boolean true if the element has child HTML elements.
hasChildNodes Boolean true if the element has child nodes.
id String The element's identifier. See Element.id.
innerText String The element's text content "as rendered". See The innerText IDL attribute.
namespaceURI String The namespace URI of the element. If the element does not have a namespace, this property is set to null. See Element.namespaceURI.
nodeType Number The type of the node. See Node.nodeType.
offsetHeight Number The height of the element including vertical padding and borders. See HTMLElement.offsetHeight.
offsetLeft Number The number of pixels that the upper left corner of the element is offset by to the left within the offsetParent node. See HTMLElement.offsetLeft.
offsetTop Number The number of pixels that the upper left corner of the element is offset by to the top within the offsetParent node. See HTMLElement.offsetTop.
offsetWidth Number The width of the element including vertical padding and borders. See HTMLElement.offsetWidth.
selected Boolean For an <option> element, indicates if it is currently selected. For other elements, undefined. See HTMLOptionElement.
selectedIndex Number For a <select> element, the index of the first selected <option> element. For other elements, undefined. See HTMLSelectElement.selectedIndex.
scrollHeight Number The height of the element's content, including content that is not visible on the screen due to overflow. See Element.scrollHeight.
scrollLeft Number The number of pixels that the element's content is scrolled to the left. See Element.scrollLeft.
scrollTop Number The number of pixels that the element's content is scrolled upward. See Element.scrollTop.
scrollWidth Number Either the width of the element's content (in pixels) or the width of the element itself, whichever is greater. See Element.scrollWidth.
tagName String The element's name. See Element.tagName.
textContent String The text content of the node and its descendants. See Node.textContent.
value String For input elements, the current value. For other elements, undefined.

CSS Properties

Contains the target element's CSS properties and their computed values.

Attributes

Contains the element's attributes.

Rectangle

Contains the properties that specify the element's size and its position relative to the viewport: bottom, height, left, right, top, width.