# Document Generation Steps

{% hint style="info" %}
**Who is this for?** Testers and SDETs who need to generate test files (TXT or CSV) dynamically during test execution for use in file upload, import, or data processing workflows.
{% endhint %}

Document generation steps create files during test runtime with configurable content. Use them when your test needs to upload a file with specific data, verify an import workflow with known values, or test document processing features with controlled inputs.

## Prerequisites

* You have created or opened a test case.
* You are familiar with the [Test Steps Editor](https://learning.contextqa.com/web-testing/test-steps-editor) basics.

***

## Adding a document generation step

1. Open a test case and click **Add Step**.
2. In the step builder sidebar, select **Document**.
3. Configure the document type, file name, and data mappings.
4. Click **Create Step** to add the step to your test case.

***

## Fields

| Field               | Required | Description                                                                   |
| ------------------- | -------- | ----------------------------------------------------------------------------- |
| **Document Type**   | Yes      | The file format to generate: `txt` or `csv`.                                  |
| **Output Variable** | Yes      | The variable name that stores the generated file reference. Default: `Input`. |
| **File Name**       | Yes      | The name of the generated file (e.g., `test-data.csv`).                       |

### TXT-specific fields

| Field                  | Description                                         |
| ---------------------- | --------------------------------------------------- |
| **Separator**          | The string used to separate values within the file. |
| **File Format Header** | Header content written at the top of the file.      |

### CSV-specific fields

| Field         | Description                                                                                            |
| ------------- | ------------------------------------------------------------------------------------------------------ |
| **Delimiter** | The character used to separate columns: **Comma** (`,`), **Semicolon** (`;`), **Tab**, or **Pipe** (\` |

### Template source

You can populate the document from a template or define content from scratch:

| Option         | Description                                                                         |
| -------------- | ----------------------------------------------------------------------------------- |
| **Create New** | Define a new template with a name and description. The template is saved for reuse. |
| **Existing**   | Select a previously saved template by ID.                                           |
| **Upload**     | Upload a template file to use as the base.                                          |

### Data mappings

Each mapping row defines a column or field in the generated file:

| Field          | Description                                                                                                               |
| -------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **Key**        | The column or field name.                                                                                                 |
| **Value Type** | How the value is sourced: **Variable**, **Static**, **Expression**, **Reference**, or **Text** (legacy alias for Static). |
| **Value**      | The actual value or variable reference (e.g., `${testEmail}` for Variable type, or `John Doe` for Static type).           |

***

## Example: Generate a CSV for bulk import testing

```
Step 1 (Document Generation):
  Document Type: csv
  File Name: users-import.csv
  Delimiter: Comma
  Template Source: Create New
  Mappings:
    | Key       | Value Type | Value              |
    | email     | Variable   | ${testEmail}       |
    | firstName | Static     | Test               |
    | lastName  | Static     | User               |
    | role      | Static     | viewer             |

Step 2 (AI Agent): Click the Import Users button
Step 3 (AI Agent): Upload the file ${Input} to the file upload area
Step 4 (AI Verification): Verify the import success message is displayed
```

***

## Example: Generate a TXT configuration file

```
Step 1 (Document Generation):
  Document Type: txt
  File Name: config.txt
  Separator: =
  Output Variable: configFile
  Mappings:
    | Key       | Value Type | Value                   |
    | host      | Variable   | ${ENV.APP_HOST}         |
    | port      | Static     | 8080                    |
    | debug     | Static     | true                    |

Step 2 (AI Agent): Upload ${configFile} to the Configuration Upload field
Step 3 (AI Verification): Verify the configuration was applied successfully
```

***

## Advanced settings

| Setting              | Description                                                             |
| -------------------- | ----------------------------------------------------------------------- |
| **Skip Step**        | Skip this step during execution without removing it from the test case. |
| **Mark as Optional** | If enabled, a failure on this step does not fail the overall test case. |

***

## Tips & best practices

* **Use Variable value types** to make generated documents dynamic. Reference test data profile columns or environment variables so the file content changes per test run.
* **Save templates for reuse.** If multiple test cases need the same file structure with different data, create a template once and select it with the **Existing** option in subsequent steps.
* **Reference the output variable** in later AI Agent steps to upload the generated file. The variable holds the file reference that the upload step uses.
* **Match the file format** to what your application expects. If the import feature requires semicolon-delimited CSV, set the delimiter to **Semicolon**.

## Troubleshooting

**The uploaded file is rejected by the application** Check that the document type, delimiter, and column names match the format your application expects. Generate the file, download it from the execution report artifacts, and inspect its contents.

**Variable values are not substituted in the file** Verify the variable name syntax (`${variableName}`) and that the referenced variable is set by an earlier step. Variable names are case-sensitive.

**Template not found** If using the **Existing** template option, confirm the template was saved in the same workspace. Templates are scoped to the workspace version.

## Related pages

* [Test Steps Editor](https://learning.contextqa.com/web-testing/test-steps-editor)
* [Test Data Management](https://learning.contextqa.com/web-testing/test-data-management)
* [Creating Test Cases](https://learning.contextqa.com/web-testing/creating-test-cases)

{% hint style="info" %}
**70% less manual test maintenance with AI self-healing.** [**Book a Demo →**](https://contextqa.com/book-a-demo/) — See ContextQA create and maintain tests for your web application.
{% endhint %}
