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;
}' Create a new property 'FirstName' Public Shared Property FirstName() As String Get Return m_FirstName End Get Set m_FirstName = Value End Set End Property Private Shared m_FirstName As String ' Create a new property 'LastName' Public Shared Property LastName() As String Get Return m_LastName End Get Set m_LastName = Value End Set End Property Private Shared m_LastName As String
@classmethod def set_FirstName(cls,name): cls.firstName = name @classmethod def get_FirstName(cls): return cls.firstName FirstName = property(get_FirstName, set_FirstName) @classmethod def set_LastName(cls,name): cls.lastName = name @classmethod def get_LastName(cls): return cls.lastName LastName = property(get_LastName, set_LastName)
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);
}
Public Shared Sub SetFirstName() Keyboard.Press(FirstName) End Sub Public Shared Sub SetLastName() Keyboard.Press(LastName) End Sub
@classmethod def SetFirstName(cls): Keyboard.Press(cls.FirstName) @classmethod def SetLastName(cls): Keyboard.Press(cls.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)
...
...
Try
' Read every row from connector and send to AddVIPApplication.
For Each row As DataRow In csvConnector.Rows
AddVIP.FirstName = row("FirstName").ToString()
AddVIP.LastName = row("LastName").ToString()
AddVIP.Start()
Next
Catch e As RanorexException
...
...
Try
for row in rows:
AddVIP_UserCode.AddVIP.FirstName = row["FirstName"].ToString()
AddVIP_UserCode.AddVIP.LastName = row["LastName"].ToString()
AddVIP.Start()
except 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)
...
Online User Guide
download as: PDF
