Docs/End-to-end tests
#

End-to-end tests

Write an E2E test for a user journey, check its outcome with assertions, and run it on a sandbox.

Write and run an E2E test

An E2E test is one user journey written in plain language, like "sign in as the owner and change the plan." An agent plays that journey in a real browser on a sandbox and checks the result along the way. You end with a test you can run again after every change.

Write and run a test

  1. Claim a sandbox. The test runs on a copy of your app with its own data and logins. See Environments.

    bash
    cofactor sandbox claim --application "Acme App" --wait
    

    The output lists the sandbox's logins with their passwords. Note the persona names, such as owner, and don't copy the passwords.

  2. Pick one journey. A test covers one job, such as creating a ticket and finding it in the queue. These rules keep it reliable.

    • Follow the action to its effect. Check where the ticket shows up after you save it.
    • Create the data the test changes, with fresh names from macros such as $EMAIL(). Clean up what you created.
    • Name the persona that signs in. To switch roles midway, add another login step.
    • Take page paths such as /settings/billing from your app's routes, or browse the sandbox's web URL to find them.
    • Check for an existing test first with cofactor workflow list --search "billing". The search matches names, so try other words from the journey.
  3. Write the steps. Save this as test.json. Each action has a short title that names the goal, and the detail goes in actionDescription.

    json
    {
      "name": "Owner changes the billing plan",
      "description": "An owner can switch the organization to the Pro plan so the new limits apply right away.",
      "nodes": [
        {"nodeType": "login", "configJson": {"credentialSource": "from_template", "credentialTemplateName": "owner", "performLogin": true}},
        {"nodeType": "navigate", "configJson": {"pageUrl": "/settings/billing"}},
        {"nodeType": "action", "title": "Change the plan to Pro",
         "configJson": {
           "actionDescription": "Open the plan switcher, choose Pro and confirm.",
           "inlineAssertions": [
             {"condition": "The billing page shows Pro as the current plan", "severity": "fail"},
             {"condition": "A confirmation message appears", "severity": "warn"}
           ]
         }}
      ]
    }
    
    bash
    cofactor workflow create --from-file test.json
    

    The command prints the test's ID and URL. Use the ID as <workflow id> below. Your agent can also write this for you.

  4. Check the outcome with assertions. An assertion is a plain-language statement that must be true after a step. The step above carries two, so each check stays next to the action that causes it. The severity says what a miss does to the run.

    SeverityA miss does this
    warnLogs a warning and the run continues.
    failMarks the run failed, and later steps still run.
    fatalStops the run at once. Use it for a precondition that later steps need.

    Write what a user would see, like "The billing page shows Pro as the current plan." Leave out CSS classes, DOM details and pixel distances. A few meaningful assertions work better than many fragile ones.

  5. Run it on your sandbox. The run targets the sandbox's own environment.

    bash
    cofactor workflow run <workflow id> --sandbox <sandbox id> --stream
    
    A passed run. Every step reads Success, and each step lists its assertions with a green count. The panel shows 9 of 9 assertions passed.

    To read each assertion's result, run 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.

    If a step fails, run cofactor workflow debug <run id> to see which step broke and why.

  6. Keep it. Add the passing test to Regression, your default suite. This changes what your default suite runs, so confirm it first. The test starts running automatically once it has passed once. Then destroy the sandbox.

    bash
    cofactor workflow add-to-regression <workflow id>
    cofactor sandbox destroy <sandbox id>
    

Check it worked

bash
cofactor workflow runs list <workflow id>
cofactor workflow status <workflow id>
cofactor workflow list --in-regression true

The latest run reads success, and workflow status prints the test's status, whether it is in Regression, and its health. The test appears in the Regression list. In the app, open E2E tests to see the same run with its steps and screenshots.

The E2E tests page listing each test with its suites, tags, recent run results, pass rate and author.

Go deeper

Advanced

Old names, test status, roles, waits and shared data.

Old name. An E2E test used to be called a flow. If your organization was created before 2026-11-25, the left nav reads "E2E tests (flows)" until 2027-01-20. The CLI commands still say workflow.

Status. A test is active until you set it to paused, blocked, under_construction or deprecated. Any other status keeps the test in its suites but stops automatic runs. Run cofactor workflow status <id> --set paused --reason "Checkout redesign" to record why. Every change shows in the test's Activity tab, and in cofactor workflow events <id>.

Roles and waits. Each login step starts a fresh session as another persona, so one test can follow an invite from an admin to a member. A wait step pauses for minutes, hours or days. Add a login step after it to sign in again.

Shared data. When several tests need the same starting data, put it in a seed test. Run cofactor workflow guide seed-workflows to see how.

Undo. cofactor workflow remove-from-regression <id> takes a test out of Regression. cofactor workflow archive <id> hides a test you no longer want, and unarchive restores it.

Two applications with the same persona name. If workflow create says a credential template name is ambiguous, the name exists on more than one application. Use "credentialTemplateId": "<id>" in the login node instead of the name. Run cofactor workflow get <id> --json on an existing test for that application to find its id.

Editing. To change a test, run cofactor workflow get <id>, edit the JSON and run cofactor workflow sync <id> --from-file test.json. Keep each node's id so the change stays small.