Welcome to the Ranorex Support Portal

Conditions and rules

Conditions and rules give you additional control over test execution. As the name suggests, they execute tests based on whether a certain condition is met. Conditional execution depends on values from a data source or a parameter, which is why this topic is explained as part of data-driven testing.

In this chapter, we’ll show you how to set up a condition with a simple rule to create a conditional test case. We’ll explain the related settings along the way. You can download the completed example at the end of this chapter.

In this chapter

Download the sample solution


To follow along with the instructions in this chapter, download the sample solution file from the link below.

Download

Sample solution


Theme: Conditions
Time: 15 minutes

Install the sample solution:

  1. Unzip to any folder on your computer.

  2. Start Ranorex Studio and open the solution file RxDatabase.rxsln

Note 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.

Test scenario


For our example, we’ll use the data-driven test of the previous chapters. Only this time,  we want to insert just the female staff members into the database of the Ranorex Studio Demo Application.

In summary:

  • Normally, 8 staff members are inserted into the database.
  • We want to modify the test case so that it enters only female staff members into the database.
  • We want to accomplish this with a condition.

Add a condition


  • You can add a condition to test cases or smart folders only.
  • Only one condition per test container.
  • Conditions can contain and are defined by one or more rules.
  • The entire process is the same for both types of test containers.

To add a condition:

  1. Right-click the smart folder or test case you want to add the condition to.

  2. Click Condition…

  1. Click Add rule to define a rule for this condition.

  1. The Condition tab of the test container properties dialog.

  2. The inactive condition, with no rules defined below it yet.

Define rules


Conditions are defined by rules. You can add up to 10 rules to a condition. Rules always follow the same pattern and check whether a data source or parameter value is equal or not equal to a control value.

  1. Define a rule from left to right by selecting the required details and click OK when you’re done.

  1. Data source/Parameter: Select whether the value you want to check is in a data source or a parameter.

  2. Specific data source/parameter: Select the specific data source or whether it is a local/global parameter that contains the value.

  3. Column/row: Select the column (data sources) or the row (parameters) that contains the value.

  4. Operator: Select whether the value you want to check must be equal or not equal to the control value.

  5. Control value: Select a possible control value from the data source/parameter.

Result

If you defined the rule just as above, you now have a condition with one complete rule. In the test suite view, this will be indicated as follows:

  1. Conditional test case.

  2. Indicator showing that the test case has an active, defined condition.

Condition settings


The condition dialog has various settings in addition to the ones we’ve already used:

Condition settings
  1. Activation checkbox: Quickly switch between active/inactive condition. Does not delete any defined rules.

  2. Condition operator: Sets when the condition is met and the test container is run.

  3. Incomplete rule indicator: Appears wherever a rule is missing information.

  4. Rule completeness indicator: Shows whether the rule is complete or incomplete.

Condition status


Depending on their completeness and activation status, conditions are indicated by three different symbols in the test suite view:

  1. Active condition with one or more complete rules.

  2. Active condition with one or more incomplete rules.

  3. Inactive condition with one or more complete or incomplete rules.

Run the test


We’ve completed the condition and are ready to run the test. Run the test from the test suite view as usual. You will notice the database in the Ranorex Studio Demo Application only contains female staff members. The report will also reflect the condition, with iterations where the condition wasn’t met marked as blocked:

Download the completed sample solution


You can download the completed sample solution with all the steps in this chapter carried out and ready to run:

Download

Sample solution


Theme: Conditions
Time: 15 minutes

Install the sample solution:

  1. Unzip to any folder on your computer.

  2. Start Ranorex Studio and open the solution file RxDatabase.rxsln

Note 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.

USERS LOVE US

SUBSCRIBE TO OUR NEWSLETTER

Get the latest test automation information right in your mailbox.

FOLLOW US

© 2024 Ranorex GmbH. All Rights Reserved