Introduction | Ranorex
Help CenterUser GuideRanorex Studio expert

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.

In this chapter

    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

    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

    tipp icon

    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, 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:

    Integration of the required classes and definition of the namespace

    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.