Context Node Guide

Prerequisite

Before using the Context Node, please ensure you have read the Context Variables Guide.

Overview

Context variables can be created from API responses, but the Context Node provides a standalone method for preparing data before any API calls are made. This is useful in scenarios such as:

  • Initializing default values before executing API requests.
  • Generating dynamic test data using Faker.js or system functions.
  • Transforming or pre-processing data before it is used in assertions.
  • Setting up session-related values to be referenced throughout the test flow.

Context Operations

Context variables are modified using a list of context operations. Each operation executes sequentially, meaning that later operations can reference values modified in previous ones. For example:

[
  { "key": "count", "value": 1 },
  { "key": "count", "value": "context.count + 1" }
]

After execution, context.count will equal 2.

Context Operation Structure

Each context operation consists of three components:

  • Operator: Defines the type of operation.
  • Key: Specifies the context variable being modified.
  • Value: Determines the new value for the variable.

Supported Operators

  • SET: Assigns a value to a key.
  • DELETE: Removes a key from the context.
  • PUSH: Adds a value to an existing key.
    • If the key does not exist, it is initialized as an array [value].
    • If the key exists but is not an array, it is converted into an array [oldValue, value].
  • MERGE: Merges an object into the existing value if both are objects.
  • CLONE: Copies an existing value to another key.

Value Configuration

The value of a context operation can be:

  • A valid Jsonata expression for dynamic data transformation.
  • A predefined function selected from our function library, including:
    • Faker.js functions for generating random data.
    • System functions for built-in operations.
    • Custom functions for user-defined scripts (see the Script Guide for details).

Summary

The Context Node is a powerful tool for managing dynamic test data. By leveraging sequential context operations, users can efficiently manipulate values, ensuring flexibility and reusability in test flows.