This article explains how you create a user code collection, add methods to it, and share it with other users. This process enables team members without coding skills to benefit from custom user code methods.
A user code collection is a group of logically related user code methods. Together, all collections form the user code library.
Create a new collection
-
Main Menu: Click File > New > File..., select User code collection, enter a name, and click Create.
- Toolbar: Click the Add user code collection icon in the Ranorex Studio toolbar, confirm the save location, and enter a name.
-
Projects View: Right-click in the projects view and click Add > New item....
Structure of a user code collection
A new user code collection has the following code structure:
- Libraries: Includes the required program libraries.
- Namespace: Defines the namespace for organization.
- Class Definition: Contains the class where you define your user code methods.
The user code collection appears as a file in the Projects view. You can add multiple collections per solution and organize them into folders.
- User code collection file that is currently open in Ranorex Studio.
- The user code collection file in the Projects view.
Add user code methods
Add user code methods to make the collection useful. Other users can then access these methods within the project.
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.
Ranorex Studio inserts the code construct for the method. Ensure the method stays inside the class definition.
Program a user code method
When you create a user code method, Ranorex Studio inserts a basic code snippet. You must add your custom logic and a clear description.
A complete user code method includes:
- Instantiation of the repository in the class (optional)
- Method description: Provides a short, meaningful description. This text appears when a user selects the method in the library.
- Custom code: Defines the specific automation logic. For example, entering the name “John” into a text field that is represented by the repository item FirstName.
For more information on addressing repository items, refer to Access the Repository and Repository Items.