Handle conditional cases in your tests

Handling conditional cases may become important when you want your scenarios to be executed successfully under different circumstances. An example of that is a website whose functionality depends on the log-in state. You have to log in first, only then you can use the functionality.

The test scenario

  1. Go to https://katalon-demo-cura.herokuapp.com/
  2. If you are not logged in, go to Log in screen then log in into the system. Otherwise, skip this step.
  3. Select Hongkong CURA Healthcare Center in the Facility drop down

Record the scenario

1/ Start recording on Katalon Recorder

2/ On the Chrome's active tab, go to https://katalon-demo-cura.herokuapp.com/

Notes: Make sure that you are not logged in.

3/ Click on the hamburger menu then click on Login link

4/ Input the Username and Password that are on the screen

5/ Select 'Hongkong CURA Healthcare Center' in the Facility drop down

Then, you got this automated steps

6/ Run the test, it will be failed due to there is no Login link

7/ Manually log out the web, then run the test again, it should be passed

Add conditional statements

Manually add IF statement to check the log-in state. If user is already logged in, then we want to only select the value. Otherwise, we want to log in into the system first.

1/ Add a new test step after Open command

2/ Add storeElementPresent step to store a value into a variable

3/ Add IF statement after storeElementPresent command

4/ Add ELSE statement before Select facility command

5/ Run the test several times

The test case should be passed for both cases, logged and not logged in.