Skip to main content

Assets Directory : Given assets directory

The assets directory is the base path from which all file references in DataTable columns are resolved. Declare it once in the Background and all When / Then file paths become relative to it.


Syntaxโ€‹

Given assets directory
| absolutePath |
| /workspace/features/order-from-partner/assets |
ColumnTypeRequiredDescription
absolutePathstringโœ…Path to the assets directory as seen from inside the container

Where your assets liveโ€‹

Following the recommended project layout, your assets sit right next to their feature file inside your Git repository:

my-ktestify-tests/ โ† Git repository root
โ””โ”€โ”€ workspace/
โ””โ”€โ”€ features/
โ””โ”€โ”€ order-from-partner/
โ”œโ”€โ”€ order-from-partner.feature
โ””โ”€โ”€ assets/
โ”œโ”€โ”€ order.json โ† payload for When steps
โ”œโ”€โ”€ order-unknown-partner.json
โ””โ”€โ”€ order-enriched.json โ† expected file for Then steps

When you run the container, workspace/features is mounted to /workspace/features:

docker run --rm \
-v "$(pwd)/workspace/features:/workspace/features" \
...

So inside the container, your assets folder is at /workspace/features/order-from-partner/assets, that is exactly the path you declare in your Background:

Background:
Given assets directory
| absolutePath |
| /workspace/features/order-from-partner/assets |
One assets folder per feature

Keeping assets next to their feature file makes each test self-contained. You always know exactly which files belong to which scenario, no shared global assets folder to maintain.


Alternative: set globally via environment variableโ€‹

If all your feature files share a common assets root, you can skip the Given assets directory step entirely and set it once:

-e KTESTIFY_ASSETS_DIR=/workspace/features

Or in your application.conf:

ktestify.framework.directories.assets = "/workspace/features"

File references in DataTable columns are then relative to that root.


How file paths are resolved in stepsโ€‹

Once the assets directory is set, every file column in a When or Then step is resolved relative to it:

When record from file is sent
| topicName | file |
| partner-orders | order.json | โ† resolves to /workspace/features/order-from-partner/assets/order.json

Then expected record from file based on schema
| topicAlias | file |
| enriched-out | order-enriched.json | โ† same base directory