Skip to content

TEST.assert()

Asserts a condition and logs either a success or failure status message to the test report depending on the result.

If the condition evaluates to false, the test is marked as failed.

Usage

javascript
TEST.assert(condition: boolean, message: string)
TEST.assert(condition: boolean, message: string, errorMessage: string)

Parameters

ParameterTypeDescription
conditionbooleanCondition to validate. This should evaluate to a boolean value.
messagestringThe message to log. This should describe the assertion.
errorMessagestringAdditional message to log if the condition fails.

Examples

js
I.click("Add to cart")

var cart = UI.LocalStorage.get("cart")
var cartSize = cart ? cart.items.length : 0

TEST.assert(
  cartSize === 10,
  "Cart should contain 10 items",
  "Cart only contains " + cartSize + " items"
)

In this example, the assertion fails if the cart does not contain exactly 10 items, logging a failed step with both messages to the test report.