In most cases, you can automate tests with Ranorex Studio and never touch a single line of code. But if you prefer to write your code to automate a test, you can do so in Ranorex Studio with code modules.
In the following chapters, learn how to create code modules and how to tackle typical testing tasks with them, like accessing repository items, working with variables, and data-driven testing.
You can either follow along with the instructions in these chapters and build your code modules step by step based on the sample solution below, or you can download our completed sample solution in the chapter Module variables and data-driven testing and experiment with the completed code modules.
Download the sample solution
The examples in this chapter are based on the sample solution for the chapter Data-driven testing. Download the sample solution here to follow along with the instructions in the following chapters.
Theme: Code modules
Time: 45 minutes
Install the sample solution:
-
Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
RxDatabase.rxsln
Hint
The sample solution is available for Ranorex versions 8.0 or higher. You must agree to the automatic solution upgrade for versions 8.2 and higher.
Preparation
To keep everything organized, put all of our code modules in their folders, called Code modules. It’s already there in the sample solution. If you’re using your solution, simply create a code module 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.
-
Click either
-
The Add code module symbol in the Ranorex Studio toolbar.
-
Add > New code module in the test suite menu or the context menu of the test container.
-
-
Select the Code modules folder that comes with the sample solution, or if working on your solution, select the folder that you created in the preparation step above. Click OK.
-
Name the new code module and click Create.
Ranorex Studio creates the code module in the programming language that’s been configured for the solution/project. The standard language is C#, and the following explanations are based on C#.
Code modules are organized into several 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.