How do I use a CSV file to store variables for scenario parameters?

To genuinely replicate real world impact on an application, parameterizing data is critical. This article provides details on using a CSV file for parameterizing your data.

In ScenarioBuilder you can access unlimited rows of data values, stored in comma separated values (CSV) files, to make each playback of a scenario a unique, real user experience.

Creating a New Scenario Parameter CSV File

Start by creating a file that contains the values to be used for Scenario Parameters.

  1. Go to the View tab, and then click Scenario Parameters. The “Scenario and Component Parameters” windows opens.
  2. Enter a name for your CSV file in the Name textbox.
  3. Click the Open in Excel button (to the right of the Name box). If Excel is installed on the machine, it opens. If not, then the default application configured to open a CSV file will open (i.e. Notepad).
  4. In the first row, enter your variable names. In Excel, each variable name goes into a different column in row 1. In Notepad, enter each variable name separated by a comma. Do NOT enter any spaces between the variable names and the commas.
  5. In subsequent rows, enter the data to be used.

    This is an Excel sample file containing office staff.
Excel example

This is a Notepad example containing office staff

Notepad example

6. Once all rows have been entered, save and close the file.

TIP - if the editor does not automatically save the file in CSV format, use the editor’s Save As option and change the Save as type to All Files (*.*); add the .csv extension to the file name and save.

Editing an Existing Scenario Parameter CSV File

Once a CSV file is created, if you need to edit it, follow these steps.

  1. Click the View tab.
  2. Click Scenario Parameters.
  3. You can edit the file in this window or click Open in Excel. If Excel is not installed it will open the file in your default application associated to CSV files.
  4. Make the needed changes. If editing externally, save the file.
  5. In the “Scenario and Component Parameters” window, click OK to close the window.

Attaching an Existing Scenario Parameter CSV File

Scenario Parameter CSV files can be attached at the scenario level for global access, or at the component level for access limited to the component. Unless your intention is to have the scenario loop through a component multiple times, retrieving a new row from the CSV file with each loop, attach the file at the scenario level.

  1. Select the scenario name (top row) in the Scenario window.
  2. Click the Open icon for the Variables File Name (CSV) property.
  3. Select the CSV file you want to use, and then click OK. The file name populates in the Variables File Name (CSV) textbox.

TIP - if you have a CSV file you want to use, but it doesn’t appear in the list of files, copy the CSV file to the Variables folder for your project (i.e. C:\Users\User1\Documents\Automai\ScenarioBuilder Scripts\Add Patients\variables).

Setting How the Data will be Used During Execution

You can control how the data in the CSV file is used by setting the Variables Access Type property. This property is located just below the Variables File Name (CSV) property. There is a drop-down that provides two choices:

  • Random – this is used when you don’t care what row is used from the file during execution. For example, if you have a search process and you don’t care what it searches for, only that it does a variety of searches, you would choose Random. That way each time the script was executed it would select a row at random from the CSV file.
  • Sequential – this is used when you want it to use one row of data after another. In this case a row is not reused during a multiple iteration run. This is the most common choice of access type.

Adding Scenario Parameters

Now that you have created a CSV file and attached it to the Scenario, you are ready to add the Scenario Parameters. Parameters can be used in a variety of ways in your scenario. Here is an example of using a parameter in a Type Text action.

  1. Select the Type Text action step.
  2. In the Properties pane, click the Text box. The field expands.
  3. In the expanded textbox, right-click.
  4. In the pop-up menu, select CSV Variable > the name of your CSV file > the variable you want to add. The variable name is placed in the textbox surrounded by %.
Right-click variables menu

NOTE – if you know the name of the variable, you can enter it manually. Just remember to surround it with percent signs (%). Also be aware that variable names are case sensitive. %Name% and %name% are different variables to ScenarioBuilder.

Controlling Which Line is Used from the CSV File in ScenarioBuilder

Each time you run a scenario in ScenarioBuilder, it keeps track of the last row it used. That way it always starts with a new row. However, there may be times you want to control which row is used. To adjust the row to be used, follow these steps:

  1. Click the Run tab.
  2. Click Modify CSV Lines. The Scenario Parameters window opens. It shows the CSV file name and the last row (line) that was used for a run.
  3. In the Last Line Used field, enter a number that is 1 less that the row you want to use for the next run. If you want it to use the first row, enter 0. For example, if you want it to use the 3rd row for the next run, enter 2.
  4. Click Update.

NOTE – if accessing the CSV file randomly, adjusting the “Last Line Used” value will not impact the next playback.

Tip: For more about Variables actions, please check out Using Variable Actions in our Video Tutorials series.