User code actions
A user code action is used in situations where standard out-of-the-box features provided by the Ranorex Recorder are not enough. Here are some examples where user code actions could be convenient:
- User-specific test validation
- Accessing test case related data and parameters
- Extended reporting
Herein, the concept of user code actions is introduced and explained. The most common application examples usually are far beyond the scope of this introductory chapter.
The application of user code actions is introduced in > Ranorex Studio expert > ⇢ User code library.
In this chapter
User code file
Ranorex manages a recording module within three (3) files. These files can be seen in the project file view, or directly in the project folder of your storage device.
Recording modules – code files
Code representation of recording module
- Machine-generated code representation of the recording module
- Repeatedly updated; All modifications of this file are discarded and lost!
- These files are read-only
- User code file for recording module and user code actions
- All modifications/amendments and user code are to be written into this file
- User code action methods will automatically be inserted in here
Double-click the code files in the project file view to open and display them in the file view.
Viewing existing action code
You can view existing code of an action any time. Here is how to!
Viewing action code
Click View Code, or press Ctrl + Enter
See the action code representation open
The file is locked – it cannot be changed. The file is updated during the next machine-generated update.
Converting to user code
Recorded actions can be converted to user code actions.
Converting to user code action
Click Convert to user code
See the generated user code action with default method name
- Double-click the user code action to see its code content
Example user code action
User code actions & arguments
User code actions methods can be defined to carry arguments.
User code action arguments & parameter
- Arguments can be of any name
- If working in a team, naming conventions are strongly recommended
Available argument type(s):
- String (value), option to be bound to a variable
- Boolean (true, false), option to be bound to a variable
- DateTime (value “YYYY/DD/MM”), option to be bound to a variable
- Duration (value in ms), option to be bound to a variable
- Int32 (integer value), option to be bound to a variable
- Location (values center, middle, …), option to be bound to a variable
- Point (coordinate values), option to be bound to a variable
- Rectangle (dimension value), option to be bound to a variable
- TimeSpan (time format), option to be bound to a variable
- Double (double value), option to be bound to a variable
- Adapter (Ranorex adapter), bound to a repository item
- RepoItemInfo (repository item), bound to a repository item
Important to know:
- Method parameters can be used within the method
- By means of the argument types ‘Adapter’ and ‘RepoItemInfo’ it is possible 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 to user code
Two or more actions can be merged into a single user code.
Merging actions to user code
Select the actions to be merged
Open the context menu and click Merge items to user code item
Assign the user code item a meaningful name and press Enter
Find the merged user code item with the code representation of the merged actions.
Merged user code items