Assertions

The Assertions category contains verification actions.

Assertion Parameters

You have to set up an assertion's parameters when you add it to a test.

Actual Parameter

Each assertion has an Actual parameter that takes a value or evaluated code expression that should be verified. If you need to verify a web page element's property, you can pass a selector's property to this parameter.

When you add an assertion during recording, TestCafe Studio can generate an element property expression and use it in the Actual field. Follow the steps below to generate the expression:

  1. Add an assertion action to a test.

    Adding an action

  2. Click the Element Picker button next to the Actual field and pick a target element on the tested webpage using an element picker.

    Selecting an element

  3. TestCafe shows the property list for the picked element. Double-click a property in the list.

    Selecting a property

  4. TestCafe Studio generates the element property expression and adds it to the Actual field. It also evaluates the specified expression and shows the result in the Value field.

    Actual value

You can modify the selector that identifies the target element. Click the Choose the selector arrow button next to the Actual field to view the auto-generated selectors.

Generated selectors

Expected Parameter

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.

When you specify the assertion parameters during recording, TestCafe Studio shows the assertion status icon (Success icon - the assertion passed, Failed icon - the assertion failed).

Assertion status

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 Configruations dialogs.

  • 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.

Equals

Asserts that Actual is equal to Expected.

Parameter Type Description
Actual Any type | Selector's property The value to verify.
Expected Any type The expected value.

Not Equals

Asserts that Actual is not equal to Expected.

Parameter Type Description
Actual Any type | Selector's property The value to verify.
Expected Any type The expected value.

Ok

Asserts that Actual is true.

Parameter Type Description
Actual Any type | Selector's property Value should be true.

Not Ok

Asserts that Actual is false.

Parameter Type Description
Actual Any type | Selector's property Value should be false.

Contains

Asserts that Actual contains Expected.

Parameter Type Description
Actual String | Array | Object | Selector's property The string that contains the Expected substring, an array that contains the Expected value or an object that contains the Expected property.
Expected Any type The expected value.

Not Contains

Asserts that Actual does not contain Expected.

Parameter Type Description
Actual String | Array | Object | Selector's property The string that should not contain the Expected substring, the array that should not contain the Expected value or the object that should not contain the Expected property.
Expected Any type The expected value.

Type of

Asserts that the Actual belongs to a particular type.

Parameter Type Description
Actual Any type | Selector's property The value to verify.
Type Name String The Actual value should be this type.

Not Type of

Asserts that the Actual does not belong to a particular type.

Parameter Type Description
Actual Any type | Selector's property The value to verify.
Type Name String The Actual value should not be this type.

Greater than

Asserts that Actual is greater than Expected.

Parameter Type Description
Actual Number | Selector's property Value should be greater than Expected.
Expected Any type The expected value.

Greater than or Equals to

Asserts that Actual is greater than or equal to Expected.

Parameter Type Description
Actual Number | Selector's property Value should be greater than or equal to Expected.
Expected Any type The expected value.

Less than

Asserts that Actual is less than Expected.

Parameter Type Description
Actual Number | Selector's property Value should be less than Expected.
Expected Any type The expected value.

Less than or Equals to

Asserts that Actual is less than or equal to Expected.

Parameter Type Description
Actual Number | Selector's property Value should be less than or equal to Expected.
Expected Any type The expected value.

Within

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

Parameter Type Description
Actual Number | Selector's property The value to verify.
Start Value Number The range's lower bound (included).
Finish Value Number The range's upper bound (included).

Not Within

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

Parameter Type Description
Actual Number | Selector's property The value to verify.
Start Value Number The range's lower bound (included).
Finish Value Number The range's upper bound (included).

Match

Asserts that Actual matches the re regular expression.

Parameter Type Description
Actual String | Selector's property The value to verify.
re RegExp The regular expression that should match Actual.

Not Match

Asserts that Actual does not match the re regular expression.

Parameter Type Description
Actual String | Selector's property The value to verify.
re RegExp The regular expression that should not match Actual.