Loading External Data

There is a parameter called CsvDataPaths that allows us to load external data for a test. It is of type IDictionary<string, string> and contains all the parameters loaded from one or more files.

For .csv file

Include CSV data

Include a new parameter with the name of CsvDataPaths (in the trp.runsettings or during the script in the configuration). This parameter must contain the paths of the .csv files. It is possible to include more than one .csv file path; just split them with the ';' symbol, or you could use a wildcard to retrieve all the csv files on the specified folder.

For Example:

  <!-- Parameters used by tests at runtime -->
  <TestRunParameters>
  <Parameter name="Technology" value="Web" />
    <Parameter name="Application" value="" />
    <Parameter name="WebBrowser" value="Chrome" />
    <Parameter name="CsvDataPaths" value="Resources\ParametersCSV.csv;Resources\Parameters2CSV.csv" /> 
    <!-- OR <Parameter name="CsvDataPaths" value="Resources\*.csv"> -->
  </TestRunParameters>

Use CSV Data

Call the method GetCsvData and get the dictionary. Get the desired value by the associated key. For Example:

private void TestParametersGetted()
{
  Dictionary<string, string> externalData = this.GetCsvData();
  string teamName = externalData["TeamName"];
  this.ControlsPage.textbox1.Text = teamName;
  this.ControlsPage.textbox1.Validate(self => self.Text.Equals("AutomationTeam"));
}

Last updated