Ranorex

Ranorex Professional Buy Now Compare Free Trial

The Ranorex Professional Edition provides all necessary features and tools to automate applications with the most common programming languages. Use the power of object-oriented programming techniques to develop professional test or automation systems. Create, manage and debug your automation projects with your existing development infrastructure like Visual Studio or SharpDevelop.

RanorexPro Features

Regular Expressions

Regular expressions are text patterns that are used for string matching. Regular expressions are strings that contains a mix of plain text and special characters to indicate what kind of matching to do. You can use Regular Expressions with the enumerator SearchMatchMode.RegExp in Ranorex.

Suppose we are looking for a form with a name "Sample" and a numeric digit e.g. "Sample3". The regular expression we would search for is "Sample[0-9]". The brackets indicate that the character being compared should match any one of the characters enclosed within the bracket. The dash (-) between 0 and 9 indicates that it is a range from 0 to 9. Therefore, this regular expression will match any character between 0 and 9, that is, any digit. If we want to search for a special character literally we must use a backslash before the special character. For example, the single character regular expression "\*" matches a single asterisk.

Action Keys

An action key is a key combination that the user can press to perform a special action. For example, a user can create an action key that exits a running script. Use the SetActionKey function to activate a key combinationan for an action. You can retrieve the specified key combinations with the GetActionKey function. Whenever the user presses the action keys, from any part of the system, the action will be started. The action key remains valid until the script is running.

Extended Functions and Properties

  • For .NET Framework 2.0 Controls almost every property can be automated with RanorexPro.
    Use RanorexSpyPro to see which controls support the extended properties.

    A System.NotSupportedException will be thrown if the control does not support the property.
  • FormFind function for searching of windows by title and class name
  • ControlFind functions for searching child controls in a control (e.g. TabControl) by text, class name, control name or control id.
  • ControlId and ControlName of the controls can be read

Automating Forms and Controls

The list of all top-level windows can be read from the Application.Forms property
C#
foreach (Form topform in Application.Forms)
{
    Console.WriteLine("Text= " + topform.Text);
}

Get all controls in a Form

The list of the controls in a Form can be read as follows:
C#
foreach (Control control in form.Controls)
{
    Console.WriteLine("Text= " + control.Text);
}

Get all children of a control

The Children property of the Control class contains all children of the control
C#
foreach (Control child in control.Children)
{
    Console.WriteLine("Text= " + child.Text);
}

Automating GUI elements

Finding a child element with extended search

The FindChild function has been extended with the SearchMatchMode parameter.
Use this parameter for extended search operations e.g. RegExp.
C#
Element child = control.Element.FindChild(Ranorex.Role.Text, "Text", SearchMatchMode.MatchFromStart);

FindChildren

The function searches the sub-tree of the element (or form, control) and returns all children that match the specified role, name, className and search mode. The function performs a recursive search through all child elements. The following code reads all items of a listview control:
C#
Element[] items = listView.Element.FindChildren(Role.ListItem);
foreach (Element item in items)
{
    Console.WriteLine("{0} Item Name={1})", i, item.Name);
}
The following code reads all list items of a form:
C#
Element[] items = form.Element.FindChildren(Role.ListItem);

FindChildValue

The function searches the sub-tree of the element (or form, control) and returns
the first found element with the specified value.
C#
Element item = treeView.Element.FindChildValue("Value", SearchMatchMode.MatchExact);

FindChildrenValue

The function performs a recursive search through all child elements and returns all children that match the specified value and search mode. The following code reads all elements of a treeview with the value "1", "2" or "3":
C#
Element[] items = treeView.Element.FindChildrenValue("[1-3]", SearchMatchMode.MatchRegExp);
foreach (Element item in items)
{
    Console.WriteLine("{0} Item Name={1})", i, item.Name);
}

Exception Handling

Exceptions in RanorexPro can be devided in to two categories:
  • Bugs (i.e. RanorexNet API misuse), or system failures (e.g. ArgumentException, NullReferenceException,)
  • Exceptions that signal, that a test operation couldn't be performed correctly
We don't suggest to catch exceptions from the first type. Only catch the specific Ranorex.Exceptions. If a bug in your code manifests itself as an exception, then it's best to let the test application terminate right at the point of failure. When the bug is discovered, you'll get exactly the diagnostic information you need to fix it quickly and move on.

If you write exception handling code, catch all Ranorex.Exceptions:
Exception handling with RanorexPro in C#
try
{
    Application.ErrorAsException = true;
 
    form = Application.FindFormTitle("RanorexTestedApp");
 
    Button button1 = form.FindButton("button1");
    Mouse.ClickControl(button1);
    ...
    Console.WriteLine("TEST PASSED");
}
catch (RanorexException e)
{
    Console.WriteLine("EXCEPTION Source={0} Sender={1} Message={2}
              StackTrace={3}", e.Source, e.Control, e.Message, .StackTrace);
    Console.WriteLine("TEST FAILED");
}
This code throws an exception if the application with the title "RanorexTestApp" cannot be found. You don't need error handling code if you use Ranorex.Exceptions, RanorexNet throws every time an exception if an operation failed. Normally you can exit your test case with an error if a Ranorex.Excetion accours.

If you want to test a specific error situation, you should use an additional try catch block for this case:
C#
try
{
    Application.ErrorAsException = true;
    Form form;
    try
    {
        form = Application.FindFormTitle("RanorexTestedApp");
    }
    catch (ControlNotFoundException)
    {
        Application.Start(startApplication);
        form = Application.FindFormTitle("RanorexTestedApp", 
        		SearchMatchMode.MatchExact, true, 5000);
    }
    ...
    Console.WriteLine("TEST PASSED");
}
catch (RanorexException e)
{
    ...
    Console.WriteLine("TEST FAILED");
}

Inheritance

All classes have a public constructor in RanorexNet, they can be used as a base class.

For testing complex user applications, we suggest writing an application specific wrapper module around the RanorexNet classes.

Installing Ranorex in the GAC

If you want to make RanorexNet globally accessible then you have to place the assemblies RanorexNet.dll and RanorexSpy.dll into the Global Assembly Cache. (The folder is dependent on the version of Visual Studio that you have installed and whether or not you installed it to the default path, so you may need to adjust it as needed for your system.)
    1. Open a command line window
    2. Navigate to the folder: "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin"
    3. Deploy the assemblies to the GAC using the gacutil command:
      gacutil /i C:\Ranorex-1.1.0\Bin\Net-2.0-Pro\RanorexSpy.dll
      gacutil /i C:\Ranorex-1.1.0\Bin\Net-2.0-Pro\RanorexNet.dll
    4. Copy the assemblies RanorexNet.dll and RanorexSpy.dll in the folder
      "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies"
      (This adds the assemblies to the Add References dialog of Visual Studio 2005)
    5. Copy RanorexCore.dll into the Windows\System32 folder

    RanorexSpyPro

    RanorexSpyPro is the extended version of RanorexSpy. This tool gives you all information about a selected GUI element and its components. Use RanorexSpyPro to see which kind of GUI elements could be automated with Ranorex. RanorexSpyPro shows almost every property of the .NET Framework 2.0 controls.
    Thanks to Benjamin Wulfe, we used the idea and some part of the source code from his brilliant article: Deliver The Power Of Spy++ To Windows Forms

    Python 2.5 Support

    RanorexPro supports the latest version of the Python interpreter. The Python samples in the Ranorex Scripts directory works with all Python versions.