User code actions
User code actions extend the functionality of basic and smart actions. Examples include custom validations, accessing test-case related data and parameters, and extended reporting.
In this chapter, you’ll learn how to manage user code actions in the actions table. Writing your own user code requires programming knowledge and is therefore outside the scope of this chapter. You can
The user code library is an expert topic explained in Ranorex Studio expert > User code library > ⇢ Introduction.
Locate the user code file
Each recording module is made up of three files. You can find these files in the projects view in Ranorex Studio or directly on your hard drive in the project folder. Double-click to open them.
Recording modules – code files
- Machine-generated code representation of the recording module.
- Automatically updated by Ranorex. Any modifications you make are discarded.
- The user code file for the recording module and user code actions.
- Write all your user code to this file.
- User code methods from the user code library will automatically be added to this file.
View the underlying action code
To view the underlying code of an action:
Viewing action code
Right-click it and click View Code, or press Ctrl + Enter.
The action’s code appears.
Convert a standard action to user code
You can convert standard actions to User code actions.
To do so:
Converting to user code action
Double-click the user code action to view its code in the code editor.
Example user code action
User code actions and arguments
You can configure arguments for user code actions in the argument editor or in code.
User code action arguments and parameters
- Any name is possible.
- It is a best practice to use naming conventions, especially when working in a team.
Available argument type(s):
- String (value), can be bound to a variable
- Boolean (true, false), can be bound to a variable
- DateTime (value “YYYY/DD/MM”), can be bound to a variable
- Duration (value in ms), can be bound to a variable
- Int32 (integer value), can be bound to a variable
- Location (values center, middle, …), can be bound to a variable
- Point (coordinate values), can be bound to a variable
- Rectangle (dimension value), can be bound to a variable
- TimeSpan (time format), can be bound to a variable
- Double (double value), can be bound to a variable
- Adapter (Ranorex adapter), linked to a repository item
- RepoItemInfo (repository item), linked to a repository item
Important to know:
- Method parameters can be used within the method.
- Use the argument types ‘Adapter’ or ‘RepoItemInfo’ to pass a reference to a repository item into an action method.
- Using repository items as arguments for user code actions enables a variety of possibilities such as providing a framework of smart test actions, defining generic technology-independent get/set value actions, combining several related actions to one user code action, implementing complex validations, and many more.
Merge actions into a user code action
Two or more actions can be merged into a single user code action, as shown below:
Merging actions to user code
The code of the actions appears in the code of the new user code action.
Merged actions in user code