Setup, seed and teardown
Reference for test data in Cofactor E2E tests. Seed flows and Seed Data nodes, seed outputs, teardown flows, scope, execution mode and deprecated setup flows.
A seed flow provisions data that several tests share, and a teardown flow removes it. A Seed Data node in a test pulls the seed's outputs in as variables. Data that only one test uses is better created inside that test. For logins and seed data in a sandbox, see Seed data and logins.
Flow types
| Type | What it is |
|---|---|
seed | Creates data and exports named values for tests. |
teardown | Cleans up after a seed. A seed links to one teardown flow. |
setup | Deprecated. See Setup flows are deprecated. |
Create these from the E2E tests list. Open the Seeds or Teardowns tab and select New seed or New teardown. A new seed also creates a paired teardown flow named Teardown: <seed name>. From the CLI:
cofactor workflow seed create --name "Create Client" \ --output client_id:"Client id" --output client_name:"Client name"
Each --output is key:name or key:name:description. Add --no-teardown to skip the paired teardown. To change an existing flow's type, run cofactor workflow patch <workflow id> --flow-type seed.
Seed outputs
A seed flow declares the values it exports. Each output has a Name, a Data Key and an optional Description. A test reads an output as $var.<data key>, for example $var.client_id. See Macros and variables.
To sign in as a user the seed creates, turn on Provisions a credential on an output. Then set the Login node's Credential Source to From seed script and pick that output. That option appears when a Seed Data node comes before the Login node.
The Seed Data node
nodeType: seed. Label: Seed Data.
| Field | configJson key | Notes |
|---|---|---|
| Seed Script | seedWorkflowId | The seed flow to run. |
| Version | snapshotVersion | Pins a published version of the seed. null is Live (latest definition). |
| Execution Mode | executionMode | Recommended (API when available) is recommended. API Only is api. Browser is browser. |
| API call timeout (seconds) | apiTimeoutSeconds | Default 120. Ignored in browser mode. |
| When to run | scope | See the next table. |
| Continue on failure | onFailure | Unchecked is block (default): a failed seed skips the test. Checked is warn: the test continues. |
| Run teardown | runTeardown | On by default. Shown when the seed has a teardown flow. |
| When to run | scope | Behavior |
|---|---|---|
| Each test (before every test that uses it) | inline | The default. The seed runs again for each test. |
| Once per suite (before all layers) | suite | The seed runs once and every test in the suite shares its outputs. Teardown runs once at the end. |
| Once per layer (before its layer) | layer | The seed runs before the layer that uses it, and its teardown runs right after that layer. Outside a suite, it acts like inline. |
To force suite scope for every test that uses a seed, run cofactor workflow patch <seed id> --run-once-per-suite true.
With Recommended, Cofactor uses the seed's API sequence when it has one, and a browser session otherwise. See API sequences.
Teardown
A teardown flow cleans up what its seed created. A fatal assertion failure halts the run, so cleanup steps at the end of a test do not run after it. Use a teardown for anything that must not be left behind.
- Run teardown on the Seed Data node turns it off for one test.
- A wait in a seed or teardown flow is limited to 5 minutes.
Seed Data catalog
In Applications & environments, select Applications, then Seed Data. Each seed has a card with View Flow, View Teardown and a Teardown switch. If the seed has no teardown, the card shows Add Teardown.
Setup flows are deprecated
A setup flow, and the Setup Flow node (nodeType: setup) that calls it, ran another flow as a prerequisite. Do not create new ones.
| Need | Use |
|---|---|
| Shared data | A seed flow. |
| Tests that must run in order | Suite layers. |
| A reusable step in the middle of a test | A Run a flow node. |
Rules for test data
- Create what a test changes, with a unique name, for example
QA Test $RANDOM_STRING(6)or$EMAIL(), so reruns do not collide. - Seed only what several tests share.