Test Blocks authoring guide
Test Blocks is the step-by-step way to author a TestZeus test. Instead of one Gherkin feature file, the test is an ordered list of steps. Each step does one thing, and TestZeus proves it before the test can run officially.
This guide covers how to write steps that verify the first time. For the builder itself (creating a test, the step list, recording, Live Test), read the Test Blocks overview. For everything you can type on a step's Code tab, read Step code and tz helpers. When a step fails, use Troubleshooting failed steps.
Five ways to create a test
Create New Test offers five ways to create a test. They produce tests that run, sit in suites, and appear in reports the same way; they differ in how you describe the test.
| Mode | You provide | You get | Best for |
|---|---|---|---|
| From scratch | A Gherkin feature file typed in the editor | A Gherkin test the agent interprets on each run | Readable specifications, reviews with business users |
| From recording | A browser session you click through once, or a Chrome Recorder JSON file | An editable Gherkin test | Capturing a long flow quickly |
| Magic Test | A prompt, story, or document | Generated tests, as Gherkin or as Test Blocks | Broad coverage from requirements |
| Import framework | Existing test scripts or a zipped project (.zip, .py, .java, .js, .json, .jsonl, .csv) |
Converted tests with their test data | Migrating an existing suite |
| Test Blocks | Steps in plain language or Python, or actions recorded in the builder's browser | A verified step list with code behind every step | Deterministic, repeatable runs; UI mixed with API and Salesforce checks; visible loops and branches |
The Interaction writing guide and the Casebook are written for Gherkin, but their advice on naming the target, the action, and the expected result applies to every Test Blocks step too.
Choose Test Blocks when the same run must do the same thing every time, when a test mixes the UI with API or Salesforce checks, when you need loops, branches, or values handed to the next test in a suite, or when you want proof for every step. You can also start in another mode and move: Convert to Test Blocks turns any Gherkin test (written, recorded, generated, or imported) into steps, and Magic Test can generate straight into Test Blocks on the web.
How a step gets verified
- Write the step in the Natural language tab, write Python on the Code tab, record it in the builder's browser, or pick a Pre-seeded step. As you type, a matching pre-seeded step may appear as Pre-seeded match; select Use this or keep typing.
- Add and run (or Save and run when editing) runs the step. TestZeus writes the code for a plain-language step, runs it, and checks the result. Add step and Save store the step without running it.
- The step shows Verified when the action and its outcome were proven. Show proof opens the screenshot after the step, the action log, the code that ran, and, for API steps, the request and response.
- When every step you keep is verified and the session is closed, the builder shows Ready for live test. Live Test runs the whole test officially.
Run until this step runs everything up to that step. Steps the open browser has already run are not replayed.
When steps need to run again
Editing a step marks the steps after it Needs run, because they may now start from a different place. TestZeus skips this when the edited step cannot change what later steps see (a wait, an assertion, a read-only API step, or a pure check), unless it saves a value a later step reads.
When the open browser is already past the step you want to run, the builder asks to Discard & Run: it closes that browser and runs again from step 1.
Browser, device, or no browser at all
Every step has one switch in its editor:
- Needs browser to run on a web test, or
- Needs device to run on a mobile test.
| Switch | The step runs | Use it for |
|---|---|---|
| On | In the test's leased browser (web) or device (mobile) | Clicking, typing, navigating, and checking what is on screen |
| Off | Without a browser or device | Salesforce queries and Apex, HTTP API calls, reading files, computing or comparing values |
A run whose steps all have the switch off never opens a browser or device, so it
starts at once. With the switch off, a step can use tz helpers such as
tz.salesforce.soql, tz.api.get, or tz.read on the Code tab, but not page
or device.
The proof and the run view label each step by what it did: Browser or Device, Advanced for code that runs without a browser, and SOQL, Apex, or API for a Salesforce query, Anonymous Apex, or an HTTP request. SOQL and Apex need a connected Salesforce org in the test's environment.
Turning the switch on or off changes where the step runs, so the builder asks first and removes the step's generated code; the step keeps its description and is written again on its next run.
One run drives one surface. A web test runs browser steps and a mobile test runs device steps; a range that mixes the two is refused.
One step, one intent
A step is the unit TestZeus verifies, retries, and reports, so each step must do one thing: one action on the screen, or one check. A bundled step cannot be verified or re-run on its own, and when it fails you cannot tell which part broke.
When you add a plain-language step, TestZeus reviews it first.
| Review result | What you see | What to do |
|---|---|---|
| One intent | Nothing; the step runs | Nothing |
| Several intents | Multiple intents detected, with a suggested breakdown | Select Add N steps to use the breakdown, or Author my own to rewrite it yourself |
| Too vague | This step needs more detail. Name the action or check and its target. | Say what to do and where: Click "Save" on the Account form |
| Not a step | This is not a step. Write one browser action or check. | Greetings, questions, and fragments are not steps |
Until the review is resolved the step shows Step needs review before it can run, and a run that reaches it stops there.
What counts as one intent
| One step | Split into several steps |
|---|---|
Click the "New" button |
Click New, fill in the account name, and save |
Type [$.testdata.account.name] into "Account Name" |
Enter the account details (a broad goal: name each field) |
Assert the toast says "Account was created" |
Save the record and check it was created |
Open [$.environment.current.base_url] |
Log in and open the Opportunities tab |
Some sentences look like several actions but are one:
- a value that contains "and", such as
Select "Research and Development" in Department; - signing in as another user (
Switch user to [$.testdata.users.rep]) or returning to the original user: TestZeus performs the whole sign-in itself; - saving a value from the page, or opening an address;
- a check limited by "without …", such as
Read the page title without clicking anything: the "without" part is a restriction, not an action.
These are never reviewed for splitting:
- Assertions and soft assertions. A check stays one step, however it is worded.
- Recorded steps. Each recorded action is already one step.
- Steps with the switch off (code that runs without a browser).
Assert and soft assert
Any step can be added as an assertion. In the composer, choose Add as → Assert or Soft assert, then write what should be true after the step.
- Assert stops the test when the check fails.
- Soft assert records the failure as Failed · soft, keeps running later steps, and still fails the test, so one run can report several problems.
Write the expected result, not how to find it: Assert the Stage field shows "Closed Won", not Check the stage.
Use variables, not literals
Anything that changes between environments, runs, or datasets belongs in a
variable. In plain language, type $ (or click an entry in the Variable
Dictionary) to insert a [$.…] reference; in code, read it from tz.
| Namespace | Reference | In code | Holds |
|---|---|---|---|
| Test data | [$.testdata.<set>.<key>] |
tz.testdata |
Values from the attached Test Data |
| Environment | [$.environment.current.<key>] |
tz.environment |
The test environment's values |
| Input | [$.input.<name>] |
tz.input |
Values passed in by a suite |
| Temp | [$.temp.<name>] |
tz.temp, tz.setTemp |
Values kept for the rest of this run |
| Output | [$.output.<name>] |
tz.output, tz.setOutput |
Values published for the next test in a suite |
| Loop | [$.loop.item], [$.loop.index], [$.loop.iteration] |
tz.loop |
The current item inside For each |
A plain-language step can save what it reads: Read the opportunity Id from the URL as [$.output.opportunity_id]. The step row then shows Saves
opportunity_id, and steps that read it show from step N. Variables and
test data are added in Configuration; the Variable Dictionary shows the
values from your open session.
References read nested fields and list items: [$.output.accounts[0].Id] and
[$.output.accounts.0.Id] are the same value.
Where a saved value is available
A value can be used only by a step that is certain to run after the step that saves it. A value saved inside one branch of an If, or inside a For each, is not available after that block, unless both branches save it. A step that uses a value no earlier step saves shows No earlier step saves "name", and the step list shows a Fix banner.
Sign-in codes
[$.environment.current.authentications.<name>] and
[$.environment.current.email.<name>] give a fresh authenticator code or the
code from the newest matching email. They work only in the plain-language
instruction of a step with Needs browser to run on, where the code is typed
into a field; not in an assertion, an If, or code. A recorded
login flow is a step of its own:
Log in as <name>. In code, use tz.mfa.totp, tz.email.otp, or
tz.auth.login.
Logic: If and For each
After the first saved step, Add logic inserts a block that wraps steps. Blocks carry no status of their own; the steps inside them do.
If
An If runs its Then steps when its condition holds, and its Else steps
otherwise. Build the condition from rows: a left value (usually a reference such
as [$.temp.status]), an operator, and a right value.
| Operator | Passes when |
|---|---|
| equals | The values match. Numbers compare as numbers, so 5 equals 5.0; text must match exactly |
| not equals | The values do not match |
| contains | Text contains the right side, a list holds it, or an object has it as a key |
| greater than | Both sides are numbers and the left is larger |
| less than | Both sides are numbers and the left is smaller |
| is empty | The left value is missing, blank, or an empty list or object (no right side) |
| is not empty | The left value has something in it (no right side) |
The right side can be a typed value or a reference such as [$.testdata.deal.stage].
Rows join with AND and OR; AND binds tighter, as the builder lays the rows out. A reference that is not set when the If runs fails the step instead of guessing. If blocks can be nested.
For each
A For each runs its steps once per item in a list: a test-data set
([$.testdata.accounts]), a saved list ([$.temp.rows]), or a JSON array
(["Hot", "Warm", "Cold"]). Inside it, [$.loop.item] is the current item,
[$.loop.index] counts from 0, and [$.loop.iteration] from 1. A
[$.loop.…] reference outside a For each is refused.
A loop runs at most 100 items by default; a longer list fails before the first
item runs. For each cannot be nested inside another For each. To loop
over the rows of an attached spreadsheet, read it into temp first with a code
step, tz.setTemp("rows", tz.read("accounts.csv")), then loop over
[$.temp.rows].
Hand values to the next test
A suite connects tests in order. A value the next test needs must be an
output ([$.output.<name>], or tz.setOutput in code), not temp. In the
suite's flow builder, map that output into the next test's input or test data.
Temp values last only for the current run.
Plain language or code
Plain language covers most clicks, typing, and checks, and TestZeus writes the code. Switch to the Code tab when you need exact control: reading a value back, comparing values, calling an API, or waiting for a specific condition. Code is what the step runs; see Step code and tz helpers.
While you edit one tab, the other is view-only. Saving a new plain-language description on a step that already has code clears that code, so the next run follows the description.
Common mistakes
- Several actions in one step. Accept the suggested breakdown instead of rewording the step to get past the review.
- Hard-coded record Ids and URLs. They differ per org and per run. Read them from a query or an earlier step's output.
- Temp used across tests. Temp values do not leave the run; use outputs for suite hand-offs.
- The browser switch on for API work. A query or HTTP call does not need a browser; turning the switch off makes the run faster.
- Creating Test Blocks tests with the Gherkin commands. Use the Test Blocks commands in the CLI, SDK, or MCP server; the generic test create and copy commands do not carry steps.