Ranorex Studio allows you to automate tests without writing code. However, if you prefer to write your code to automate a test, you can use code modules to build your test logic.
The following chapters teach you how to create code modules and perform common testing tasks, such as accessing repository items, managing variables, and implementing data-driven testing.
Build your code modules step-by-step using the instructions in these chapters using the sample solution below. Or, download the complete sample solution in Module Variables and Data-Driven Testing to experiment with the final code.
Sample solution for the chapter Data-driven testing.
- Theme: Code modules
- Time: 45 minutes
- Download sample file
Install the sample solution
- Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
RxDatabase.rxsln - Accept the automatic solution upgrade if you use Ranorex version 8.2 or higher.
Preparation
To maintain organization, place all code modules in a dedicated folder named Code modules. The sample solution already includes this folder. If you work in your own solution, create a folder as described below.
Create a code module
To create a new code module:
- In the test suite view, click the test container where you want to add the code module.
- Choose one of the following:
- Click the Add code module symbol in the toolbar.
- Select Add > New code module from the test suite menu or the context menu.
- Select the Code modules folder and click OK.
-
Name the new code module and click Create.
Ranorex Studio generates the code module in the project's configured programming language (usually C#).
A code module contains the following sections:
- Integration of the required classes and definition of the namespace
- Class definition, including the necessary empty constructor.
- Run() method, where you can implement your code. This is also where default values for various timeouts are predefined.