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
| Kind | Where it lives | Use it for |
|---|---|---|
| Inline assertion | The Assertions section of an Action node (inlineAssertions). | A check that follows the action that causes it. Prefer this kind. |
| Assertion node | A standalone step (nodeType: assertion). | A check that follows no action, for example a page state after a Navigate. |
| Exact check | A 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 assertion | An Audio assertion node. | Sound the page played. |
| Visual checkpoint | A 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.
{
"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.
| Severity | A miss does this | Use it for |
|---|---|---|
fatal | Stops the run at once. | A precondition that later steps need, for example "The user is signed in". |
fail | Marks 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". |
warn | Records 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_countminus 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.