This tutorial demonstrates advanced coding in QTP using if and else loop
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 robut 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 negative scenario are different
- There are many ways to integrate them and once 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 negative scenario, if no do the steps for positive scenario
- In QTP 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 exists on screen or not
- If result is true do 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. Lets run the test for one valid and one invalid login credentials. The test Runs successfully .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 case ,for Loops. as per your requirements