Welcome to the Ranorex Support Portal

Collections and methods

In this chapter, we’ll show you how to create a user code collection, fill it with methods, and make it accessible to other users. This way, team members without coding skills can profit from user code methods.

A user code collection is defined as a collection of user code methods that belong together logically. All user code collections together make up the user code library.

In this chapter

Create a new collection


To create a new collection:

  1. Click File > New > File…

  2. Click User code collection and enter a name.

  3. Click Create.

Alternatively, you can also create a collection in the following ways:

  1. Click the Add user code collection symbol in the Ranorex Studio toolbar, confirm the save location, and enter a name.

  2. Right-click in the projects view and click Add > New item…

Structure of a user code collection


An new user code collection will have the following code structure:

  1. Inclusion of the required program libraries

  2. Definition of the namespace

  3. Class definition of the user code collection. This is where you define the user code methods.

User code collection file


The user code collection also appears in the projects view as a file. You can add multiple user code collections per solution and organize their files in folders.

  1. Opened user code collection file in Ranorex Studio

  2. The user code collection file in the projects view

Add user code methods


User code collections only become useful once you add user code methods to them. Others can then access these methods in the project the user code collection is part of.

To add a user code method:

  1. In the class definition of the user code collection, right-click where you want to add the new method.

  2. Click Insert new user code method…

  3. Name the method and click OK.

  4. The code construct for the method is inserted.

Program a user code method


Ranorex Studio only inserts a code snippet. You then have to add your custom code along with a good description of what the method does.

Here’s an example of a finished user code method:

  1. Instantiation of the repository in the class (optional)

Download

Reference


Addressing repository items in code modules is explained in

Ranorex Studio expert > Code modules > ⇢ Access the repository.

  1. Method description
    This short description is displayed when selecting the user code method in the library. It makes it easier for users to find out what the method does. This is why you should always make sure to add a short, but meaningful description.

  2. Custom code
    In this example, the first name “John” is entered into a text field that is represented by the repository item FirstName.

USERS LOVE US

SUBSCRIBE TO OUR NEWSLETTER

Get the latest test automation information right in your mailbox.

FOLLOW US

© 2024 Ranorex GmbH. All Rights Reserved