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 and therefore, are addressed in separate chapters which will be referenced from herein.
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
- 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 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 code
You can view existing code of an action any time. Here is how to!
Viewing action code
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 code
Recorded actions can be converted to user code actions.
Converting to user code action
- 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
Find the merged user code item with the code representation of the merged actions.
Merged user code items