Download the sample solution

Sample solution

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.

Define the test

Before we start building our test, we need to define what it’ll do. We’re keeping it simple, so our test will only add an entry to a database and then validate whether it’s been added. Our AUT will be the Ranorex Demo Application. The required steps are:

Start the Ranorex Demo Application.

Click the Test database tab.

Enter the first name in the First name field.

Enter the last name in the Last name field.

Select the department from the Department drop-down.

Enter the age in the Age field.

Select a gender from the Gender box.

Click Add Entry.

Validate that Number of entries has changed from 0 to 1.

Exit the Ranorex Demo Application.

Animated test definition

Review the recording modules

The modules are organized in two folders. The application functions folder contains the modules needed to control the application itself, i.e. starting and exiting the Ranorex Demo Application. The database functions folder contains the modules related to adding an entry to the database.

The modules in these folders are quite specific, as you can see from their names. They each contain only the actions necessary for an individual step in our test definition. Modules built in this way are easier to reuse. This gives you more flexibility when building tests.

Assemble the test

We’ve got everything we need, so let’s get to business and start building our test. There is one test suite in our project, RxDatabase.rxtst. It should already be open. If it isn’t, simply double-click the file in the project view.

Add a setup region

In the test suite view, you’ll see that the test suite is mostly empty, except for a single test case with the default name. Our test definition lists starting the AUT as the first step, so that’s what we’ll add first. Starting the AUT is a perfect example of a module to include in a global setup region because, without it, no other test steps will work. To add a global setup region:

In the test suite view, right-click the test suite and click Add setup.

Adding a setup region using the context menu

From the module browser, drag the module StartAUT to the setup region. In addition to starting the demo application, the StartAUT module also clicks on the Test database tab, which is step 2 from our test definition.

Add the database test

Steps 3 to 9 in our test definition represent adding an entry to the database and validating it. This is the core of our test, so it should get its own test case. We can use the existing test case, but let’s first give it a more meaningful name.

To rename it:

Click the test case and press F2.

Rename it to SimpleDatabaseTest and pressEnter.

Renaming a test case

Now we can fill the test case with the required modules. These are, in test definition order: InsertName, SelectDepartment, InsertAge, SelectGender, AddEntry, andValidateEntries. You can add the first four modules in any order you like, but AddEntry must be second-to-last, and ValidateEntries must be last.

To add the modules:

From the module browser, drag the modules to the test case.

You can add them individually or select several modules at once using Ctrl + Click.

If you misplace a module in the test suite view, simply drag it to its correct place.

Create a module group

The modules InsertName, InsertAge, SelectGender, and SelectDepartment are all part of the same process: defining the data that will be added to the database, in other words, inserting a person. This is why it makes sense to organize them in a module group. This way, you won’t have to add all four modules over and over again when you create more test cases where this process is needed. To add the modules to a module group:

In the test suite view, select the four modules using Ctrl + Click or Shift + Click.

Right-click the modules; and then clickGroup selected modules.

The newly created module group opens in the module group view.

Creating a module group with direct grouping

Rename the module group to InsertPerson and close it.

The test case now contains the module group InsertPerson and the module group also appears in the module browser for reuse.

Add a smart folder

As tests grow larger and more complex, it can become difficult to manage the test suite. Smart folders are a useful structuring item to overcome this issue. Instead of filling a test case with 50 modules that all logically belong to the same test, add smart folders to the test case and organize the modules in them. Smart folders also make it easy to exclude particular parts of a test case from being run during test execution. This is exactly what we’re going to use a smart folder for in our example. We might not always want the validation to be carried out, so it will get its own smart folder. To add ValidateEntries to a smart folder:

Reference

Add a teardown region

Our test is almost complete. We only need to add the last step, exiting the Ranorex Demo Application. This is a perfect example of a step that should be in a global teardown region because, after it, no other test actions can be performed. The system is restored to its state before the test. Normally, this would also include deleting all entries made, but our database doesn’t save any entries when exiting, so we don’t need to include this action. To add the teardown region:

In the test suite view, right-click the test suite and click Add teardown.

Adding a teardown region

From the module browser, drag the module ExitAUT to the teardown region.

Run the test

Congratulations, you’ve just built a test in the test suite. You can apply the basic principles of this tutorial to any other test you’ll create.

This is the point where you’ll runyour test. We’ll cover the details and advanced options of running tests in the next chapter. For now, just press the large RUN button in the test suite view and enjoy your database test executing!