Introduction
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 own code to automate a test, you can do so in Ranorex Studio with code modules.
In the following chapters, you’ll 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.
Watch our on-demand webinar
Mastering User Code in Ranorex Studio: Extend your automated tests with user code actions, user code modules, and user code libraries.
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.
Sample solution
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
Preparation
To keep everything organized, we’ll put all of our code modules in their own folder, called Code modules. It’s already there in the sample solution. If you’re using your own 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 in your own 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/the project. The standard language is C#, and the following explanations are based on C#.
Code modules are organized into several sections:
Class definition, including the necessary empty constructor.
The Run() method, where you can implement your code. This is also where default values for various timeouts are predefined.