The CSVToMapGen Generator reads data from one or more columns within a specified CSV file and saves the data to memory. Once the data is in memory, the CSVFromMapGen can obtain the data for a particular column by Column Name for each Attribute.
In This Article
- When can the CSVToMapGen Generator be used?
- When should the CSVToMapGen Generator not be used?
- Does it work with any other Generators?
- CSVToMapGen Parameters
- CSVFromMapGen Parameters
- Preview Showing Empty Values - List Parameter
- Use Case 1 - Read Column Data into Memory for a Single Attribute
- Use Case 2 - Read Column Data into Memory for Multiple Attributes
When can the CSVToMapGen Generator be used?
- Any time column data needs to be read from a CSV file.
When should the CSVToMapGen Generator not be used?
- Reading data from other file types (e.g., Excel, ORC)
- Reading column data from a CSV file using a key or index reference.
Does it work with any other Generators?
- The CSVFromMapGen Generator reads the value of a specified column by Column Name from the data read and stored in memory by the CSVToMapGen Generator.
- path* - Defines the path where the CSV file is located.
- subDir - Defines an optional sub-directory under the resourcePath where the CSV file exists.
- fileName* - Defines the name of the CSV file located on the user's system.
- columnNames - Defines the list of columns to read the data from.
- delimiter* - Defines what delimiter is used to separate column data within the CSV file.
- bufferSize* - Defines how many rows to keep in memory from the CSV to avoid the memory out of exception.
- setLoop* - Allows you to OVERRIDE the loop count at the Scenario level and ONLY produce the number of rows defined in this list. Note: This does not apply to GenRocket Express, as it does not use Scenarios.
- list - Stores one value on each line in the list. To add values, type them in and then hit ENTER. Note that the listed value shown is only for simulation mode; when running a true Scenario, the data will be loaded from the specified resource.
Use Case 1 - Read Column Data into Memory for a Single Attribute
A tester wants to read data from a column titled "Level" within a CSV file and use the read data for a programLevel Attribute within a User Domain.
For this example, the CSVToMapGen and CSVFromMapGen Generators will be linked within the programLevel Attribute.
The CSVToMapGen Generator will read the values within the 'Level' column:
The User Domain has the following Attributes:
|firstName||Generates the user's first name.||NameGen|
|lastName||Generates the user's last name.||NameGen|
|programLevel||Reads data from the 'Level' column in CSV File and maps it to this Attribute.||CSVToMapGen|
The CSVToMapGen and CSVFromMapGen Generators will be linked for the programLevel Attribute.
CSVToMapGen Generator (gen1)
- fileName = CSVSample.csv
- columnNames = Level
- delimiter = pipe ( | )
- buffersize = 6 Note: The buffer size matches the number of records in the CSV file.
CSVFromMapGen Generator (gen2)
- columnName = Level
The programLevel column in the delimited file has been populated from the Level column within the CSV file.
Use Case 2 - Read Column Data into Memory for Multiple Attributes
A tester wants to read (query) data from multiple columns within a CSV file using the CSVToMapGen Generator. They then want to use the CSVFromMapGen Generator for specific Attributes to read the column data in memory by Column Name.
A Customer Domain has been set up with the following Domains:
|csvDetails||Reads CSV's 'Level' and 'Reward' columns into memory.|
Note: This Attribute is not visible.
|firstName||Generates the customer's first name.||NameGen|
|lastName||Generates the customer's last name.||NameGen|
|programLevel||Reads 'Level' column data stored in memory by the csvDetails Attribute.||CSVFromMapGen|
|reward||Reads 'Reward' column data stored in memory by the csvDetails Attribute.||CSVFromMapGen|
The csvDetails Attribute uses the CSVToMapGen Generator to read the 'Level' and 'Reward' column data from the CSV file. This Attribute is not visible (i.e., hidden), so it is not part of the generated output.
CSVToMapGen Generator Configuration
- fileName = CSVSample.csv
- columnNames = Level, Reward
- delimiter = comma ( , )
- bufferSize = 6 Note: The value entered here matches the number of rows in the CSV file.
The programLevel Attribute reads the data stored in memory from the 'Level' column in the CSV file.
The CSVFromMapGen Generator has been assigned to it, and 'Level' has been added for the columnName parameter.
The reward Attribute reads the data stored in memory from the 'Reward' column in the CSV file.
The CSVFromMapGen Generator has been assigned to it, and 'Reward' has been entered for the columnName parameter.
The 'programLevel' and 'reward' columns in the delimited file have been populated from the 'Level' and 'Reward' columns within the CSV file.