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

    tipp icon

    Screencast

    The screencast “Conditions” walks you through information found in this chapter.:

    Watch the screencast now

    Download the sample solution

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

    Note icon

    Note

    We’ve disabled two modules in this solution because they would interfere with the condition (validation) or prevent you from seeing the results in the Ranorex Studio Demo Application (teardown).

    Sample solution

    Theme: Conditions
    Time: 15 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.

    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.

    Test example definition for conditions & rules

    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…

    Defining a condition - part I
    Click Add rule to define a rule for this condition.
    Defining a condition - part II
    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.

    Specifying a rule for a condition
    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:

    Condition indicator in test suite view
    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:

    Condition settings

    Condition settings

    Activation checkbox: Quickly switch between active/inactive condition. Does 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:

    Types of condition
    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

    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

    Theme: Conditions
    Time: 15 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.