The Directory data source iterates through the files within the specified directory and puts the files' content to the first property specified in the Properties panel.
The data source assigns data to the first property in the list. Other properties will be blank, except for
fileName (see below).
|In this topic, we focus on how to configure the Directory data source. We assume you are already familiar with data-driven testing and how to configure a data-driven loop. Otherwise, please read Basic Concepts of Data-Driven Testing, or complete some of our tutorials before you continue.|
You can only use this data source in the Data Source test step in functional tests. It is not available in virtual services.
The directory to scan for files.
Specifies a wildcard expression to filter files to read. For example, if you specify
*.xml, the data source reads only XML files.
Specifies the encoding used to read the files. By default, ReadyAPI uses the ASCII character encoding.
|Note:||You can use property expansions to insert values into the above-mentioned fields.|
To get file names, create the
fileName property in the data source. On each iteration, this property will store the name of the file the data source is reading.
Do not use
fileName as the first property of the data source, since it will overwrite the default assignment rules, and the files’ contents will not be available.
Let's imagine that we have a folder with files, and we want to send the content of the .json files as a request body and send the file name as a query parameter.
To do that:
Create a data source loop with the Directory data source:
Tip: You can read about setting up data source loops here.
Create two properties within the data source, fileContent and fileName.
The data source will always write the file content to the first property, so make sure fileName is the second property in the list.
Click Browse and select the directory that stores the files:
In the Filename Filter field, enter
*.jsonso that the data source only retrieves the content of the .json files:
Click to check what data is retrieved:
To pass the data to the request test step, use property expansions to refer to the properties in the data source: