Create a collection 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:
Click File > New > File…
Click User code collection and enter a name.
Alternatively, you can also create a collection in the following ways:
Click the Add user code collection symbol in the Ranorex Studio toolbar, confirm the save location, and enter a name.
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:
Definition of the namespace
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.
Opened user code collection file in Ranorex Studio
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:
In the class definition of the user code collection, right-click where you want to add the new method.
Click Insert new user code method…
Name the method and click OK.
The code construct for the method is inserted.
The code construct of the method will be inserted wherever you right-clicked. Always make sure the method has been inserted at the correct position, i.e. in the class definition.
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:
Instantiation of the repository in the class (optional)
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.
In this example, the first name “John” is entered into a text field that is represented by the repository item FirstName.
Instead of instantiating a repository in the class of a user code collection, you can also pass a repository to a method as a parameter. Available argument types are listed in Ranorex Studio fundamentals > Actions > ⇢ User code actions.