Docs/Assertions
#

Assertions

Reference for assertions in Cofactor E2E tests. Inline assertions, Assertion nodes, exact checks on run variables, audio assertions and visual checkpoints, with warn, fail and fatal severity.

An assertion is a plain-language statement that must be true after a step, for example "A confirmation message appears". Cofactor checks it and records the result on the step.

Kinds of assertion

KindWhere it livesUse it for
Inline assertionThe Assertions section of an Action node (inlineAssertions).A check that follows the action that causes it. Prefer this kind.
Assertion nodeA standalone step (nodeType: assertion).A check that follows no action, for example a page state after a Navigate.
Exact checkA Condition node with Fail the run when false.A value the run already holds, for example an email body or an API response. No agent is involved.
Audio assertionAn Audio assertion node.Sound the page played.
Visual checkpointA Visual checkpoint node.A screen compared with a baseline.

Fields

Both inline assertions and Assertion nodes have a Condition (condition) and a severity. Type $ in a condition to insert a variable or macro.

json
{
  "nodeType": "action",
  "title": "Submit the support ticket",
  "configJson": {
    "actionDescription": "Fill in the required fields and save.",
    "inlineAssertions": [
      { "condition": "A success message appears", "severity": "warn" },
      { "condition": "The ticket appears in the ticket list", "severity": "fail" },
      { "condition": "The form is no longer visible", "severity": "fatal" }
    ]
  }
}

Severity

Severity says what a miss does to the run. Set it on every assertion.

SeverityA miss does thisUse it for
fatalStops the run at once.A precondition that later steps need, for example "The user is signed in".
failMarks the step failed and the run failed, and later steps still run.An independent claim about the feature, for example "The new record appears in the table".
warnRecords a warning and the run continues. The run still passes.A cosmetic or optional check, for example "A toast appears".

Write good assertions

  • Describe what a user sees, for example "The status badge shows 'Active'". Leave out CSS classes and DOM attributes.
  • Make each assertion stand alone. For a relative check, capture the baseline earlier with Outputs and use it: "The row count equals $var.row_count minus 2".

Read results

Each step lists its assertions with a result. A missed fail or fatal assertion has a Link issue action that files a new issue or attaches the failure to an open one. From the CLI, read results with cofactor workflow runs get <workflow id> <run id> --json. They are under data.run.steps[].metadataJson.assertionResults, with a condition, severity and passed for each. See Runs.