Skip to main content

Overview

The Add Snippet step lets you include pre-built, reusable test sequences into your tests. Snippets are modular test components you create once and reuse everywhere, eliminating duplication and ensuring consistency across your test suite.

When to Use Add Snippet

Use Add Snippet when you need to:
  • Reuse common flows: Include login, setup, or teardown sequences across multiple tests
  • Maintain consistency: Ensure the same actions are performed the same way everywhere
  • Simplify test maintenance: Update a snippet once and all tests using it get the update
  • Build modular tests: Compose complex tests from smaller, tested building blocks
  • Share common patterns: Let your team reuse proven test sequences

How It Works

Add Snippet inserts all the steps from a saved snippet directly into your current test at the point where you add the snippet. When the test runs, it executes the snippet’s steps as if you had added them manually. You can pass parameters to snippets to override specific values (like login credentials, timeouts, or form data), making them flexible enough to work in different contexts while maintaining the same core behavior.

Snippet Nesting

Snippets can contain other snippets, creating nested structures. This allows you to build complex test flows from smaller, reusable components.
Nesting limits: The system supports up to 5 levels of nesting. When adding a snippet, the system automatically checks if adding it would exceed this limit and prevents the action with a clear error message.
How nesting depth is calculated:
  • Root test case = depth 0
  • First snippet added = depth 1
  • Snippet within a snippet = depth 2
  • And so on, up to depth 5
The system tracks the maximum nesting depth across your entire test case and validates before allowing new snippets to be added, preventing you from accidentally exceeding the limit.

Using the Add Snippet Step

When you add an Add Snippet step, you’ll:

Select Your Snippet

Choose from a dropdown of all snippets created in your workspace. Each snippet is identified by its descriptive title. The dropdown shows only valid snippets that contain executable steps.
If you just created a snippet, it may take a moment to appear in the dropdown. Try refreshing the test editor if your snippet doesn’t show up immediately.

Pass Parameters (Optional)

Toggle “Pass Params” to override specific values within the snippet. Click “Edit Params” to set the values you want the snippet to use instead of its defaults. The following step types support parameter passing:
  • Fill: Override text values for form fields
  • Select: Override dropdown selection values
  • Press Keys: Override key combinations
  • Wait for Time: Override timeout durations

Real-World Examples

Reusing a Login Flow

Snippet: "User Login"
Pass Params: Off

Snippet contains:
1. Navigate to /login
2. Fill email: {{TEST_USER_EMAIL}}
3. Fill password: {{TEST_USER_PASSWORD}}
4. Click submit button
5. Wait for dashboard
6. Check URL: /dashboard
Why this works: Every test that needs login can use this snippet instead of recreating the login steps.

Login with Different Credentials

Snippet: "User Login"
Pass Params: On
Parameters:
  - Step 2 (Fill email): [email protected]
  - Step 3 (Fill password): AdminPass123!
Why this works: Use the same login snippet but override credentials to test with admin users, test users, or different roles.

Setup Data Before Testing

Test Flow:
Step 1: Add Snippet "Create Test Product"
Step 2: Add Snippet "Navigate to Products Page"
Step 3: Fill search field
Step 4: Check product appears
Why this works: Compose tests from modular snippets that handle setup, navigation, and common actions.

Testing Checkout with Different Items

Snippet: "Add Item to Cart"
Pass Params: On
Parameters:
  - Step 1 (Fill product ID): SKU-12345
  - Step 2 (Fill quantity): 3
Why this works: Reuse the add-to-cart flow with different products and quantities for comprehensive testing.

Multi-Environment Testing

Snippet: "User Login"
(Uses environment variables {{TEST_USER_EMAIL}} and {{TEST_USER_PASSWORD}})

Test runs on:
- Staging: Uses staging credentials
- Production: Uses production credentials
Why this works: The snippet adapts to different environments through environment variables without requiring parameter overrides.

Best Practices

Design Effective Snippets

  • Single purpose: Each snippet should do one thing well (login, search, checkout)
  • Self-contained: Snippets shouldn’t depend on external state or previous steps
  • Clear naming: Use descriptive titles like “Login as Admin” or “Create Test Order”
  • Provide defaults: Always set sensible default values for all parameters

When to Create Snippets

Create snippets for:
  • Actions repeated across 3+ tests
  • Complex sequences that are error-prone to recreate
  • Team-shared patterns everyone should use the same way
  • Setup/teardown that must be consistent
Don’t create snippets for:
  • One-off sequences used in a single test
  • Steps that change frequently (until they stabilize)
  • Overly complex mega-snippets that do too much

Parameter Strategy

  • Identify what varies: Focus parameters on values that change between uses
  • Keep defaults sensible: Default values should work for the most common case
  • Document parameters: Use clear parameter names that indicate their purpose
  • Test both modes: Validate snippets work with and without parameter overrides

Maintain Your Snippets

  • Review snippets regularly to ensure selectors are still valid
  • Update snippets when UI changes instead of creating new ones
  • Deprecate snippets that are no longer needed
  • Test snippets independently before using them in tests

Troubleshooting

Snippet Not Available

Symptom: Can’t find a snippet in the dropdown Solution:
  • Verify the snippet exists in your workspace
  • Check that the snippet contains valid steps
  • Refresh the test editor to reload available snippets
  • Ensure you have access to the snippet (permissions)

Snippet Steps Fail

Symptom: Test fails when executing snippet steps Solution:
  • Test the snippet independently to isolate the failure
  • Check if selectors in the snippet are outdated
  • Verify environment variables the snippet uses are defined
  • Check if the page state is correct before the snippet runs

Parameters Not Working

Symptom: Parameter values aren’t being used Solution:
  • Verify “Pass Params” toggle is enabled
  • Check that you’ve set parameter values for the steps you want to override
  • Ensure parameter types match (text for Fill, options for Select, etc.)
  • Test the snippet without parameters first to confirm base functionality

Snippet Changes Don’t Appear

Symptom: Updated snippet still shows old behavior Solution:
  • Refresh your test editor to reload snippet changes
  • Clear cache if changes still don’t appear
  • Wait a moment for cache updates to propagate
  • Check that you saved the snippet changes

Performance Issues

Symptom: Snippet loading causes delays Solution:
  • Check network connection
  • Break large snippets into smaller, focused components
  • Reduce snippet complexity if possible
  • Verify snippet size is reasonable

Nesting Depth Exceeded

Symptom: Error message saying maximum nesting depth reached when trying to add a snippet Solution:
  • Simplify your snippet structure by reducing nesting levels
  • Break complex nested snippets into separate, parallel snippets
  • Review your snippet hierarchy to find opportunities to flatten
  • Consider if some nesting can be moved to the test case level
  • The maximum nesting depth is 5 levels; restructure if you’re hitting this limit
Maximum nesting depth: You cannot exceed 5 levels of nesting. If you’re hitting this limit, consider restructuring your snippets to use parallel snippets instead of deeply nested ones.

Understanding Snippet Execution

How Steps Are Inserted

When you add a snippet, its steps are inserted into your test at that point. During execution:
  • Steps run in sequence as if you’d added them manually
  • Parameter overrides apply to the specified steps
  • Environment variables resolve at runtime
  • The snippet doesn’t create a separate scope - it’s part of your test

Variable Scope

Variables created in snippets:
  • Are available to steps after the snippet in your test
  • Follow the same naming rules as regular variables
  • Can conflict if snippet and test use the same names
  • Persist throughout the test execution

Parameter Passing Details

Only these step types support parameters:
  • Fill (override text values)
  • Select (override option selections)
  • Press Keys (override key combinations)
  • Wait for Time (override timeout durations)
Other step types in snippets use their configured values and can’t be overridden via parameters. Parameter names are case-sensitive, so ensure you use the exact name defined in the snippet’s parameter definitions.
  • Navigate - Often included in navigation snippets
  • Fill - Commonly used in form snippets with parameter support
  • Click - Frequently used in interaction snippets
  • Check Text - Often included in validation snippets
  • Extract Value - Used for data capture snippets
  • Snippets - Comprehensive guide to creating and using snippets, including nesting strategies and debugging techniques