Welcome to the new Ranorex Support Portal

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 however make use of user code actions programmed by others through the user code library.

Download

Further reading


The user code library is an expert topic explained in Ranorex Studio expert > User code library > ⇢ Introduction.

In this chapter

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
  1. Actions table with repository in the Recorder view.

  2. Code representation of the recording module.

  • Machine-generated code representation of the recording module.
  • Automatically updated by Ranorex. Any modifications you make are discarded.
  • Read-only.
  1. User code representation of the recording module.

  • 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
  1. Select an action.

  2. Right-click it and click View Code, or press Ctrl + Enter.

  3. 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
  1. Right-click an action.

  2. Click Convert to user code.

  3. The action appears as a user code action with a default method name.

  4. 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
  1. Button to open the argument editor of the code method.

  2. The argument editor.

  3. The argument in the action’s code.

Argument name:

  • 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

User code return values


User code methods do not return a value by default. However, you can configure specify one of the available data types as method return value.

To do so:

  1. Replace the default void return value with your desired data type.

  2. Implement your individual user code and add a line to return the specified value.

  1. This causes a Return value column to appear in the action table. It contains the return value of the user code method and allows you to make it variable.

Alternatively, you can use the context menu to create a user code method with return value:

  1. Right-click an action.

  2. Click Convert to user code with return value.

  3. The new action appears in the action table, including a Return value column.

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
  1. Select the actions you want to merge.

2

Right-click them to open the context menu.

a

Click Merge items to user code item to create a default user code method without return value.

b

Click Merge items to user code item with return value to create a user code method with a return value.

  1. Name the new user code action and press Enter.

Result(s):

The code of the actions appears in the code of the new user code action.

Merged actions in user code
  1. Default merged user code method without return value

  2. Merged user code method with Boolean return value.

USERS LOVE US

SUBSCRIBE TO OUR NEWSLETTER

Get the latest test automation information right in your mailbox.

FOLLOW US

© 2024 Ranorex GmbH. All Rights Reserved