This chapter shows 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.
Create a new collection
To create a new collection:
-
Click File > New > File…
-
Click User code collection and enter a name.
-
Click Create.
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
A new user code collection have the following code structure:
-
Inclusion of the required program libraries
-
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.
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)
-
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. -
Custom code
In this example, the first name “John” is entered into a text field that is represented by the repository item FirstName.
Addressing repository items in code modules is explained in Ranorex Studio expert > Code modules > Access the repository.