This example illustrates how to integrate Data-Driven Testing into Ranorex recordings. The application under test is a simple application where you can add contacts.
In this tutorial you will create a simple recording and perform the same operations with multiple sets of data. You will use a data table (Excel CSV) with a set of parameters so that you can run your recording several times using a different set of data.
The Ranorex Data Driven Test Sample for C#, VB.NET and IronPython is shipped with the Ranorex setup package. You can find it using the link on the Ranorex Studio startpage or by navigating to "Ranorex Installation Folder\Samples\DataDrivenTest".
In this tutorial the VIP-Application is our application under test. The VIP-Application (VIPApplication.exe) is just a simple example, where you can load, add or delete your data.
Start Ranorex Studio, choose "File" -> "New" -> "Solution..." and create a “Ranorex C# Test Automation” project.

On the Projects tab double-click ‘Recording1.rxrec’ to open the Recorder view.
On the Recorder View click the Record button. The Ranorex Recorder is minimized.

You can now begin to record some action on the VIP Application like this:
Stop the recording by clicking the Stop button. The Recorder view should be visible then.

Now we implement properties in our recording class to make it able to have parameters assigned.

// Create a new property 'FirstName'
public static string FirstName
{
get;set;
}
// Create a new property 'LastName'
public static string LastName
{
get;set;
}Edit the 'SetFirstName' and 'SetLastName' methods and replace the Keyboard.Press strings:
public static void SetFirstName()
{
Keyboard.Press(FirstName);
}
public static void SetLastName()
{
Keyboard.Press(LastName);
}
Now we have the ability to configure our Keyboard.Press() action outside the recording class.
...
try
{
AddVIP.FirstName = row["FirstName"].ToString();
AddVIP.LastName = row["LastName"].ToString();
AddVIP.Start();
}
catch (RanorexException e)
...The implementation of properties in chapter:1 is the base for data driven testing. Now we can feed the textboxes with data.

...
try
{
// Create a new CSVConnector object
CSVConnector csvConnector = new CSVConnector(@"..\..\TestData.csv");
}
catch (RanorexException e)
...Now we are able to access the rows in the data table.
Within a foreach loop we start 'Recording1' for each data row. By executing the test you can see that the test is executed for each data set defined in the CSV file.
...
try
{
// Create a new CSVConnector object
CSVConnector csvConnector = new CSVConnector(@"..\..\TestData.csv");
// Read every row from connector and send to AddVIPApplication.
foreach(DataRow row in csvConnector.Rows)
{
AddVIP.FirstName = row["FirstName"].ToString();
AddVIP.LastName = row["LastName"].ToString();
AddVIP.Start();
}
}
catch (RanorexException e)
...
Our test example is now connected to the test data CSV file. To run and execute the test it is necessary to compile the source code we've just added. Hence, click on the green 'Run' button in the Ranorex Studio toolbar or press F5 to run the compiler and to start the compiled executable.
// Create a new property 'Gender'
public static string Gender
{
get;set;
}
public static void SetGender()
{
if(Gender == "Male")
{
repo.FormVIP_Database.RadioButtonMale.Click();
}
else if(Gender == "Female")
{
repo.FormVIP_Database.RadioButtonFemale.Click();
}
}
...
try
{
// Create a new CSVConnector object
CSVConnector csvConnector = new CSVConnector(@"..\..\TestData.csv");
// Read every row from connector and send to AddVIPApplication.
foreach(DataRow row in csvConnector.Rows)
{
AddVIP.FirstName = row["FirstName"].ToString();
AddVIP.LastName = row["LastName"].ToString();
AddVIP.Gender = row["Gender"].ToString ();
AddVIP.Start();
}
}
catch (RanorexException e)
...