IF, Else, End IF, Exists in QTP/UFT with Example

IF, Else, End IF, Exists in QTP/UFT

This tutorial demonstrates advanced coding in HP QTP using if and else loop

Click here if the video is not accessible

Video Transcript with Key Takeaways Highlighted

  • From your Testing background, you will certainly infer that a more accurate Test Scenario would be Validate the Login Functionality of Flight Reservation which should have two sub-scenarios
  • Check that user successfully logs in to the application on inputting a COMBINATION OF valid ALPHANUMERIC Agent Name & Password
  • Check that user log on fails on inputting INVALID Agent Name & Password
  • More so, a robot automation script should be able to accept and handle both valid and invalid login details
  • We have the sub-scenarios already recorded So the challenge is to integrate them.
  • You May observe for both the scripts – STEPS ,Launch Flight Reservation Application, Enter Agent Name ,Enter Password ,Click OK ,while steps Checkpoint, Close Flight Reservation Window, for positive scenario, and steps, Output Error Information, Close Error Info Window, Close Login Dialog Box, for a negative scenario are different
  • There are many ways to integrate them and one of the ways, is to use if and else loop and check whether error information screen exists after entering the agent name and password. if yes do the steps for a negative scenario, if no do the steps for positive scenario
  • In Micro Focus UFT Window, After step # 4, Add a step if else loop, The check condition is whether error information screen exists. Copy this step and paste it as check condition.
    Delete the Click Operation. And replace it with Exists method. This method is applicable to almost all objects and checks whether the particular objects exist on screen or not
  • If a result is true to the negative scenario steps. I will cut and paste the steps inside the loop
  • Copy the steps from the positive scenario and paste it in the else loop. Let’s run the test for one valid and one invalid login credentials. The test Runs successfully. The note is you saved the tests in the order mentioned in the tutorials
  • PositiveLogon to NegativeLogon and Negative Logon to Combined you should have no problem running the test.
  • Apart from if and else you can also use – if elseif., while wend., do a case, for Loops. as per your requirements