Skip to main content

Overview

Snippets are reusable test sequences you create once and use across multiple test cases. They follow the DRY (Don’t Repeat Yourself) principle, eliminating duplication and ensuring consistent test execution. When you update a snippet, all tests using it automatically get the update. Snippets can contain any combination of steps, including other snippets, allowing you to build complex, modular test architectures. You can pass parameters to snippets to customize their behavior while maintaining the same core flow.

Creating Snippets

From the Snippets Page

  1. Navigate to Snippets from the main menu
  2. Click Create to open the snippet editor
  3. Build your snippet steps just like a regular test case
  4. Optionally define parameters that can be passed when using the snippet
  5. Save your snippet with a descriptive title

From Existing Test Steps

You can convert existing test steps into a snippet:
  1. Select the steps you want to convert in the test editor
  2. Use the “Create Snippet” action from the context menu
  3. The selected steps will be copied to a new snippet form
  4. Add a title and save

Snippet Nesting

Snippets can contain other snippets, creating nested structures up to 5 levels deep. This lets you build complex test flows from smaller, reusable components.
Maximum nesting depth: The system supports up to 5 levels of nesting. When you reach this limit, you’ll see an error preventing further nesting. The system calculates nesting depth automatically and prevents exceeding the limit.

Nesting Examples

Simple nesting (2 levels):
Test Case
  └─ Snippet: "User Login"
       └─ Snippet: "Enter Credentials"
Complex nesting (4 levels):
Test Case
  └─ Snippet: "Complete Checkout"
       └─ Snippet: "Add Items"
            └─ Snippet: "Search Products"
                 └─ Snippet: "Navigate to Store"

Understanding Nesting Depth

The nesting depth is calculated from the root test case:
  • Root test case = depth 0
  • First-level snippet = depth 1
  • Snippet within a snippet = depth 2
  • And so on, up to depth 5
When adding a snippet, the system checks:
  • Current maximum depth in your test case
  • Depth of the snippet you’re adding
  • Whether adding it would exceed the 5-level limit

Best Practices for Nesting

  • Keep nesting shallow: Prefer 2-3 levels when possible for easier debugging
  • Use clear naming: Name snippets to indicate their purpose and level
  • Avoid circular references: Snippets can’t reference themselves directly or indirectly
  • Test independently: Ensure nested snippets work correctly on their own
  • Document hierarchy: Keep track of snippet dependencies in your organization
Circular references: Never create snippets that reference themselves, directly or indirectly. The system will detect and prevent circular dependencies, but you should design your snippet hierarchy to avoid them.

Parameters

Parameters let you customize snippet behavior without changing the snippet itself. Define parameters when creating a snippet, then pass values when using it.

Parameter Types

Snippets support these parameter types:
  • String: Text values for form fields, URLs, selectors
  • Number: Numeric values for timeouts, quantities, indices
  • Boolean: Toggle values for flags and options
  • Object: Complex data structures (stored as JSON)
  • Array: Lists of values (stored as JSON)

Defining Parameters

When creating or editing a snippet:
  1. Open the Parameter Definitions section
  2. Click Add Parameter
  3. Configure each parameter:
    • Name: Unique identifier (used in expressions)
    • Type: Choose from the supported types
    • Required: Whether the parameter must be provided
    • Default Value: Value used if not provided
    • Description: Helpful text explaining the parameter’s purpose

Using Parameters in Snippets

Reference parameters in step values using expressions:
{{snippet.params.username}}
{{snippet.params.quantity}}
{{snippet.params.waitTimeout}}
Parameters are resolved at runtime, allowing you to use the same snippet with different values. Parameter names are case-sensitive, so ensure you use the exact name defined in the snippet’s parameter definitions.

Passing Parameters

When adding a snippet to a test:
  1. Select the snippet
  2. If the snippet has parameters, you’ll see a parameter form
  3. Enter values for each parameter
  4. Required parameters are marked with an asterisk

Best Practices

Snippet Design

Single purpose: Each snippet should do one thing well. Create focused snippets like “Login as Admin” or “Search Products” rather than mega-snippets that do everything. Self-contained: Snippets should work independently. Avoid dependencies on external state or previous steps that might not exist when the snippet runs. Clear naming: Use descriptive titles that indicate purpose and context. Examples:
  • ✅ “Login as Admin”
  • ✅ “Add Item to Cart”
  • ❌ “Snippet 1”
  • ❌ “Test Flow”
Sensible defaults: Always provide default values for parameters that work for the most common use case.
Create snippets when you find yourself repeating the same sequence of steps across multiple tests. This is especially valuable for complex workflows that are error-prone to recreate manually.

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 consistently
  • Setup/teardown that must be identical across tests
  • Workflows that change frequently (update once, everywhere gets the change)
Don’t create snippets for:
  • One-off sequences used in a single test
  • Steps that change too frequently (wait until they stabilize)
  • Overly complex mega-snippets that do too much
  • Simple, single-step actions (just use the step directly)

Parameter Strategy

Identify what varies: Focus parameters on values that change between uses, not on everything. Keep defaults useful: Default values should work for common scenarios without requiring overrides. Document parameters: Use clear descriptions so users understand what each parameter does and when to override it. Test both modes: Validate snippets work with default parameters and with overrides.

Nesting Strategy

Limit depth: Prefer shallow nesting (2-3 levels) for easier debugging and maintenance. Layer responsibilities: Use nesting to create logical layers:
  • Level 1: High-level workflows (e.g., “Complete Purchase”)
  • Level 2: Mid-level actions (e.g., “Add to Cart”)
  • Level 3: Low-level interactions (e.g., “Click Button”)
Avoid circular dependencies: Never create snippets that reference themselves, directly or indirectly. Test incrementally: Test nested snippets at each level to isolate issues.

Maintenance

Regular review: Periodically review snippets to ensure selectors and logic are still valid. Update, don’t duplicate: When UI changes, update existing snippets rather than creating new ones. Deprecate unused snippets: Remove or mark snippets that are no longer needed. Test independently: Run snippets on their own before using them in tests to catch issues early. Version awareness: When updating snippets, consider impact on existing tests that use them.
Breaking changes: When updating a snippet, be aware that all tests using it will get the update. If you’re making significant changes, consider testing a few dependent tests first or creating a new snippet version.

Debugging Snippets

Common Issues

Snippet not appearing in dropdown Symptom: Can’t find your snippet when adding an Add Snippet step Solutions:
  • Verify the snippet exists in your workspace (check the Snippets page)
  • Ensure the snippet contains valid steps
  • Refresh the test editor to reload available snippets
  • Check that you have access permissions if using team snippets
If you just created a snippet, it may take a moment to appear in the dropdown. Try refreshing the test editor if the snippet doesn’t show up immediately.
Snippet steps fail during execution Symptom: Test fails when executing snippet steps Solutions:
  • Test the snippet independently to isolate the failure
  • Check if selectors in the snippet are outdated
  • Verify environment variables the snippet uses are defined
  • Ensure page state is correct before the snippet runs
  • Check browser console for JavaScript errors
  • Review the trace view to see exactly where it fails
Parameters not working Symptom: Parameter values aren’t being used when snippet runs Solutions:
  • Verify you’ve set parameter values in the parameter form
  • Check that parameter names match exactly (case-sensitive)
  • Ensure parameter types match (string vs number vs boolean)
  • Test the snippet without parameters first to confirm base functionality
  • Review snippet parameter definitions to ensure they’re configured correctly
Snippet changes don’t appear Symptom: Updated snippet still shows old behavior in tests Solutions:
  • Refresh your test editor to reload snippet changes
  • Clear browser cache if changes still don’t appear
  • Wait a moment for cache updates to propagate
  • Verify you saved the snippet changes
  • Check if other browser tabs have the editor open with stale data
Nesting depth exceeded Symptom: Error message saying maximum nesting depth reached Solutions:
  • 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
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.
Circular reference detected Symptom: Error preventing snippet addition due to circular dependency Solutions:
  • Review snippet dependencies to find the circular path
  • Remove the circular reference by restructuring snippets
  • Create a new snippet that doesn’t reference the problematic chain
Circular dependencies: The system automatically detects and prevents circular references. If you see this error, review your snippet hierarchy to identify where snippets reference each other in a loop.

Debugging Techniques

Test snippets independently: Always test snippets on their own before using them in tests. This isolates issues to the snippet itself and makes debugging much faster.
Use the trace view: When a snippet fails, use the trace view to see exactly which step failed and why. The trace shows the full execution path including nested snippets.
The trace view shows the complete execution path including all nested snippets, making it easy to see where failures occur in complex nested structures.
Check step details: Review individual steps within snippets to ensure selectors and values are correct. Verify environment variables: If snippets use expressions with environment variables, ensure those variables are defined in your environment. Review parameter values: When debugging parameterized snippets, verify the values being passed match what the snippet expects. Test with and without parameters: Test snippets both with default parameters and with overrides to ensure both paths work. Check nesting depth: If you’re hitting nesting limits, review your snippet hierarchy and consider flattening some levels. Use browser console: Check browser console logs during execution for JavaScript errors or warnings that might affect snippet steps.

Real-World Examples

Login Flow Snippet

Purpose: Reusable login sequence used across multiple tests Steps:
  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. Verify URL contains /dashboard
Usage: Add this snippet to any test that needs authenticated access. Works across environments through environment variables.

Parameterized Search Snippet

Purpose: Search functionality with customizable query Parameters:
  • searchQuery (string, required): What to search for
  • waitForResults (boolean, default: true): Whether to wait for results
Steps:
  1. Fill search field: {{snippet.params.searchQuery}}
  2. Press Enter
  3. If {{snippet.params.waitForResults}}, wait for results to appear
Usage: Reuse search functionality across tests with different queries, with optional waiting behavior.

Nested Checkout Flow

Structure:
Test Case: "Complete Purchase"
  └─ Snippet: "Add Items to Cart" (depth 1)
       └─ Snippet: "Search and Select Product" (depth 2)
  └─ Snippet: "Proceed to Checkout" (depth 1)
       └─ Snippet: "Fill Shipping Info" (depth 2)
       └─ Snippet: "Fill Payment Info" (depth 2)
  └─ Snippet: "Complete Purchase" (depth 1)
Benefits: Each snippet handles a specific responsibility, making the overall flow easy to understand and maintain.