TestProject Forum

Add more than one condition to TestStep

How to add more than one condition to the test step which is recorded? Scenario: A field should appear only for few States. Can we add more than one condition by using parameters to the step? Will it look for all the conditions one by one and will select the one applicable during execution?

You can apply multiple conidiation to your step, but they will be added as AND (P1 > 5 AND P1<20 AND…). If I understood your scenario correctly you should to something else:

  1. Create a parameter “State” that will hold all of your states (give it a default value of New Jersey for instance)
  2. Create another parameter “True_False” that will indicate with a specific State should have this field appearance, give it a default value of True.
  3. Use the “State” parameter in your test to search for the desired state
  4. locate the filed that appeared with the recorder spy and record a single validation action of Is-Visible? on the desired field (you can find them under validations)
  5. Now go to advanced section of this Is Visible step, Add a condition that will ask if “True_False” Contains True (This is basically will tell the automation run this step only if the True_False value==True)
  6. Now run your test with the default values (New Jersey + True) - it should pass
  7. Now use CSV and data driven to pass different values to the test
    State True_False
    New Jersey True
    New York False
    Alaska True

The end result that test will run with all of your values one by one and trigger the step of Is-Visible? only for the states that paired with true values.

here is a screenshot on how its done

let me know if it helps :slight_smile:

Thanks, Mark for the prompt reply. This is helpful…Please tell me if more than one condition can be added to a Test Step. If yes, then is it going to check the relevant state and run the test. For example:
If Field1 is applicable for State Montana, Georgia but not for Illinois. I have added Condition State Equal “Montana” and other Condition State Equal “Georgia” to the Field1. Will this step be executed if the state is MT and GA and skip if the State is IL?

Basically, I am trying to find if we can avoid repeating test steps several times to add conditions for different States.

When you add multiple conditions to a Test Step they will be acting as AND not OR.
In case you described the Test step won’t be executed at all, since State can’t be equal to Montana and Georgia at the same time.

If you don’t want to repeating the steps you should create data driven test as suggested, in such case you will have one step with one simple condition.

another thing you can do create a sub test (nested test) that will have these multiple validation steps then adding it as a step in your main test where applicable.
in such case you will be able to reuse this sub test in many test cases

Thanks, Mark! This is really helpful and worked for me.