User code actions | Ranorex
Help CenterUser GuideRanorex Studio fundamentals

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.

Further reading

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

    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!
    • These files are read-only
    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
    tipp icon

    Hint

    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

    Viewing action code

    Select an action and open the context menu

    Click View Code, or press CtrlEnter

    See the action code representation open

    Note icon

    Note

    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

    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

    Result(s):

    • Double-click the user code action to see its code content
    Example user code action

    Example user code action

    User code actions & arguments

    User code actions methods can be defined to carry arguments.

    User code action arguments & parameter

    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

    Argument name:

    • 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

    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

    Merged user code items