> For the complete documentation index, see [llms.txt](https://docs.qapilot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.qapilot.io/detailed-documentation/test-plan-executions/dynamic-test-data.md).

# Dynamic Test Data

### Dynamic Test Data during Recording

We’ve enhanced the test data handling experience within the Recorder to improve usability, reduce context switching, and provide better control over how input data is managed during test creation.

#### Background

Previously, when recording steps that required input values, users could either:

* Enter direct input data, or
* Use a variable, which would then automatically be added to the test data set along with its corresponding value.

While functional, this approach required manual entry and did not provide a structured way to reuse existing test data items efficiently.

***

### 1. Dropdown-Based Test Data Selection

The standard variable text box has now been replaced with a **dropdown menu** that lists all existing test data items for the selected test data set.

This allows users to:

* Easily select from previously defined test data items
* Maintain consistency across test cases
* Avoid manual retyping of variable names

<figure><img src="/files/fPO3CaTqT0zcXcrQQ0mX" alt=""><figcaption></figcaption></figure>

***

### 2. Inline Test Data Item Creation

Users can now create new test data items directly from the same dropdown interface.

Instead of navigating away from the Recorder screen:

* Select the option to create a new test data item
* Define the required value inline
* Continue recording without interruption

This ensures smoother workflow and eliminates unnecessary screen transitions.

***

### 3. Intelligent Selection Logic

If a user selects an existing test data item and leaves the input field blank:

* The system automatically retrieves the value from the selected test data item
* That value is used during step execution

This reduces redundancy and ensures accurate value binding without additional input.

***

### 4. Flow Continuity & Backward Compatibility

The existing logic for creating variables during recording remains fully supported.

When new items are added inline:

* They are automatically incorporated into the test data set
* The system continues to behave consistently with prior variable-handling logic

No changes are required to existing test cases.

### 5. Update Test Data During Run time

QApilot supports dynamic test data updates mid-execution using a new "Update Test Data" keyword, allowing the same functional block to be driven by different data values without duplicating steps.

<div align="left"><figure><img src="/files/kX1zmsNWNyNkqquhXeS6" alt="" width="375"><figcaption></figcaption></figure></div>

<figure><img src="/files/EVjx7xgtFSqnrw3Vg977" alt=""><figcaption></figcaption></figure>

With the new keyword, users can specify a variable name and provide the updated value as the step input.

* For dynamic variables, QApilot generates the value at runtime according to the configured rules and assigns it back to the variable automatically.
* For static variables, the value is applied directly before the step executes.

***

### **6. Custom Test Scripts**

QApilot now supports a **Custom Test Script** type that lets users write lightweight native JavaScript snippets to generate values dynamically at execution time.

This is useful for scenarios where the required test data depends on runtime context - such as today's date, a calculated future date, a formatted string, or a unique identifier - without relying on external data sources or manual updates before each run.

***

**Setting Up Custom Test Script**

When creating or editing a test data item, select **Custom Test Script** from the **Data Type** dropdown. A code editor will appear where you can write your JavaScript snippet.

<figure><img src="/files/KXzpIG9JI6mk6eK1Ifh9" alt=""><figcaption></figcaption></figure>

The snippet runs once at the start of execution. Its return value is injected into every step that references the variable for the duration of that run.

<figure><img src="/files/uoj0s75Q8AZuSrkPxjqM" alt=""><figcaption></figcaption></figure>

***

**Writing Your Snippet**

* Only standard, native JavaScript is permitted - no TypeScript, transpiled code, or external libraries.
* The snippet must explicitly `return` a value. Execution will fail if no `return` statement is present or if the script returns `undefined`.
* Maximum length: **1,000 characters**.

**Examples:**

1. Get a date 5 days from today:

```javascript
let targetDate = new Date();
targetDate.setDate(targetDate.getDate() + 5);
return targetDate.toLocaleDateString();
```

2. Format today's date as YYYY-MM-DD:

```javascript
let d = new Date();
let month = String(d.getMonth() + 1).padStart(2, '0');
let day = String(d.getDate()).padStart(2, '0');
return d.getFullYear() + '-' + month + '-' + day;
```

3. Generate a unique timestamped identifier:

```javascript
return 'testuser_' + Date.now();
```

***

**Restrictions**

The following are not permitted:

* `import` / `require` - no external libraries or modules
* `fetch`, `XMLHttpRequest`, `WebSocket` - no network access
* Scripts that return `undefined` or have no `return` statement

Violations will cause a validation error at the Test Data resolution step, before any test steps run.

***

**Execution Behaviour**

The snippet executes before the first test step runs. The resolved value is then used consistently across all steps that reference that variable within the same run.

***

**Viewing Results in Reports**

After execution, the **Test Data** tab in the execution report displays the resolved value - the actual output of the script - alongside the steps that used it. This makes it easy to audit what value was in play for any given run.

### Impact

This enhancement streamlines test data management directly within the recording flow, improves reusability of data, reduces manual effort, and ensures cleaner separation between test steps and test data configuration. The addition of Custom Test Script further extends this flexibility to handle time-sensitive, computed, or uniqueness-dependent values without any external tooling.
