Skip to main content

Reusability — Snippets

The primary mechanism for reuse in msg.ZenTestAI is the snippet. A snippet is a piece of test logic — a short sequence of steps, typically organized into activities — that you author once and then call from any number of test cases. The classic example is Login: rather than copying the same five login steps into every test, you write them once as a snippet and reference that snippet from each test that needs to log in.

What is a snippet?

In structural terms, a snippet is almost identical to a test case. It has steps, activities, parameters, and the same General-tab meta-data — but it is not directly executable. It only runs when a test case references it through a snippet-reference step. Snippets get their own page in the left navigation (Snippets) and behave just like the test-case list page, with the obvious difference that there is no Play / Execute action on a snippet row.

The differences between a snippet definition and a test definition are deliberately small, and almost all of them concern fields that wouldn't make sense for a building block:

  • Tags and Fail on failed HTTP-requests are hidden — those apply to the calling test, not the snippet.
  • Start URL and User / Role only appear when Login required is enabled.
  • An extra Isolated toggle appears when Login required is on (see Isolated snippets below).
  • Activities work the same way as in a test, with a slightly simplified hover toolbar.

Apart from those, the editor is the same: same Steps tab, same parameters, same change history, same recording, same advanced step settings.

How a snippet is called

You insert a snippet into a test by adding a snippet-reference step on the Steps tab. The step picker offers a list of all snippets available in the tenant; pick one and the step is created.

A snippet-reference step does two things:

  1. It marks the position in the test where the snippet's steps will run.
  2. It carries a parameter binding — a mapping that decides, for each parameter the snippet's inner steps expect, where the value comes from. Bindings can be hard-coded values, references to the calling test's parameters, or — when the reference is wrapped in a loop — column references into a data table.

At execution time, the snippet's steps are inlined into the test's step list at the position of the reference. In the execution results, the inlined steps remain grouped under a Snippet: <name> heading so you can see where the snippet's contribution begins and ends.

A snippet can be used in many tests and multiple times in the same test. The only constraint is no circular references — a snippet cannot, directly or transitively, call itself.

Isolated snippets

When a snippet has both Login required on and the Isolated toggle on, msg.ZenTestAI gives it its own browser session at execution time. Cookies and local storage are snapshotted before the snippet runs and restored after it finishes. This is the right setting when the snippet must log in as a different user than the calling test — for example, a snippet that performs an approval action as an admin from within a regular-user test.

Without Isolated, the snippet shares the calling test's browser session.

Creating a snippet

You can create a snippet in two ways.

From scratch on the Snippets page

In the left navigation, open Snippets, then click Add Snippet. The creation form is identical to the test creation form except the type is preset to Snippet.

From an existing activity inside a test

If you find yourself wanting to reuse a chunk of an existing test, you don't need to retype it. On the Steps tab, hover over the activity you want to extract and click the Create snippet from activity icon on the activity's hover toolbar.

What this does:

  • It opens the snippet creation form prefilled with the activity's steps (renumbered from 1) and the activity's name as the snippet title.
  • Parameter bindings, loop and condition settings on the original activity are copied along with the steps.
  • You review and save the new snippet.

What it does not do:

  • It does not automatically replace the original activity in the parent test with a snippet-reference. The original activity stays as-is until you remove it yourself and add the snippet-reference step in its place.

Treat the action as "copy these steps to a new snippet" — the replacement in the parent test is a separate, conscious step.

From a recording

Recording produces a regular test case, not a snippet. If you want to turn part of a recorded test into a snippet, recorded steps into an activity, then use Create snippet from activity.

From an external system

When a test is imported from Jira XRay or Zephyr Scale, any Call to Test (XRay) or Test Call (Zephyr) step in the source becomes a snippet in msg.ZenTestAI. The parent test ends up with snippet-reference steps in those positions. See External Systems → Snippets and external systems for the full behavior, including locking and unlinking.

Inside the Steps tab

A snippet-reference step shows the snippet's title and an icon that makes it visually distinct from regular steps. You can expand the reference inline to preview the snippet's steps without leaving the test, which is handy for sanity checks during editing.

If the snippet is wrapped in a loop or a condition (see Loops and Conditions), small chips on the snippet-reference step indicate that — same convention as for activities.

Editing and deleting snippets

Anyone with edit rights on the tenant can create, edit and delete snippets. Editing a snippet immediately affects every test that references it the next time those tests execute. If you delete a snippet that is still referenced by one or more tests, the deletion is blocked and the UI lists the tests that still depend on it — you have to update those tests first (or delete them).

What is not a snippet — quick comparison

It's easy to confuse snippets with other reuse mechanisms. The shortest summary:

MechanismWhat it reusesWhen to use
Snippet (this page)A sequence of steps, with its own activities and parameters.Reusing whole flows like login, search, approve, …
MacroA small computed value (date, sum, random, …).A one-line expression that returns a value, not a sequence of UI actions.
Script functionA JavaScript hook (before / after the test, or as a step).Custom logic that doesn't fit into natural-language steps.

If you find yourself copy-pasting the same handful of steps into many tests, that is almost always a sign you want a snippet.