User code actionsA 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
In this chapter
User code fileRanorex 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
Action list with repository of recording module in Recorder view
Code representation of recording module
- Machine-generated code representation of the recording module
- Repeatedly updated; All modifications of this file are discarded and lost!
- Therefore, this file must not be changed or modified
User code representation of recording module
- 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 Recorder file view.
Viewing existing action codeYou can view existing code of an action any time. Here is how to!
Viewing action code
Select an action and open the context menu
Click View Code, or press Ctrl + Enter
See the action code representation open
The file is locked. Do not change or modify this file. All changes and modifications are lost during the next machine-generated update.
Converting to user codeRecorded actions can be converted to user code actions.
Converting to user code action
Select a recorded action and open the context menu
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 & argumentsUser code actions methods can be defined to carry arguments.
User code action arguments & parameter
Button to open the argument editor of the code method
Argument editor of the code method
Argument of user code method
- 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 codeTwo 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
Result(s):Find the merged user code item with the code representation of the merged actions.
Merged user code items