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 find how to set up a condition with a simple rule to create a conditional test case. Here, explains the related settings along the way. You can download the completed example at the end of this chapter.
Download the sample solution
To follow along with the instructions in this chapter, download the sample solution file from the link below.
Theme: Conditions
Time: 15 minutes
Install the sample solution:
-
Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
RxDatabase.rxsln
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 this example, use the data-driven test of the previous chapters. Only this time, 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:
-
Right-click the smart folder or test case if you want to add the condition.
-
Click Condition…
-
Click Add rule to define a rule for this condition.
-
The Condition tab of the test container properties dialog.
-
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.
-
Define a rule from left to right by selecting the required details and click OK when you’re done.
-
Data source/Parameter: Select whether the value you want to check is in a data source or a parameter.
-
Specific data source/parameter: Select the specific data source or whether it is a local/global parameter that contains the value.
-
Column/row: Select the column (data sources) or the row (parameters) that contains the value.
-
Operator: Select whether the value you want to check must be equal or not equal to the control value.
-
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:
-
Conditional test case.
-
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:-
Activation checkbox: Quickly switch between active/inactive conditions. Do not delete any defined rules.
-
Condition operator: Sets when the condition is met and the test container is run.
-
Incomplete rule indicator: Appears wherever a rule is missing information.
-
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:
-
Active condition with one or more complete rules.
-
Active condition with one or more incomplete rules.
-
Inactive condition with one or more complete or incomplete rules.
Run the test
The condition is completed 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:
Theme: Conditions
Time: 15 minutes
Install the sample solution:
-
Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
RxDatabase.rxsln
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.