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.
Screencast
Download the sample solution
To follow along with the instructions in this chapter, download the sample solution file from the link below.
Note
Sample solution
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
Hint
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:
Right-click the smart folder or test case you want to add the condition to.
Click Condition…
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.
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:
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
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 incomplete rules.
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:
Sample solution
Time: 15 minutes
Install the sample solution:
Unzip to any folder on your computer.
Start Ranorex Studio and open the solution file RxDatabase.rxsln