This document summarizes the topics covered in the QTP Training Session V, including:
- Conditional statements like If/Then/Else and Case statements for controlling script flow.
- Error handling using recovery scenarios and On Error Resume Next.
- Inserting transaction points to measure execution time.
- Scheduling script execution using a .vbs file and the Windows Task Scheduler.
- Best practices for writing scripts that can be executed by others, like including instructions, comments, and readable formatting.
2. Agenda - Advance
Conditional Statements
Error Handling
Inserting Transaction Points
Schedule execution of scripts.
Executing scripts made by others
3. Conditional Statements
Enables you to control the flow of your Test or
component. Two ways:
If Then Else Decision making, evaluates whether a condition is true or
false, and then based upon the result certain set of statements are run.
You can check multiple conditions within a single If statement
using And & Or operators
Using Case - Works on a single expression which is evaluated at the
beginning on the Select Case statement. The result of the expression is
then compared with the values for each Case in the structure
5. Recovery Scenario
Recovery scenario gives you an option to take some
action for recovering from a fatal error in the test.
Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It
could be any popup window, any test error, particular state of an object or
any application error.
Action: Defines what needs to be done if scenario has been triggered. It can
consist of a mouse/keyboard event, close application, call a recovery function
defined in library file or restart windows. You can have a series of all the
specified actions.
Post-recovery operation: Basically defined what need to be done after the
recovery action has been taken. It could be to repeat the step, move to next
step etc.
6. When to use a Recovery Scenario and when to
us on error resume next?
Recovery scenarios are used when you cannot predict at what
step the error can occur or when you know that error won't
occur in your QTP script but could occur in the world outside
QTP, again the example would be "out of paper", as this error
is caused by printer device driver.
"On error resume next" should be used when you know if an
error is expected and don't want to raise it, you may want to
have different actions depending upon the error that
occurred. Use err.number & err.description to get more
details about the error.
7. Transaction Point
A utility object called Services for measuring
transaction time.
To find out execution time of the by using the
start transaction and end transaction points
8. Schedule execution of scripts
1. Create a .vbs file to launch QTP with required settings, add-ins etc.
2. Go To Start > Control Panel > Schedule Tasks > Click Add Schedule Tasks
Click Next on the screen.
3. Click Browse and select the .vbs file you just created. You will get this
screen
4. Give a name to the task and select the frequency for performing the given
tasks. For this demo we will select "One time only
5. Select Start Time and Start Date. For this demo, select Start Time as
current time+5 mins and Start date as today's date.
6. Next Screen Enter "UserName", "Password" and "Confirm Password" Click
Next and you should get this screen.
7. Click on Finish.
9. Executing scripts made by others
Your Scripts will be executed by others as
well. Make sure following points.
Write instructions what and how the steps are
executed.
Use comment blocks to define your actions.
Make the script easily readable, format it
Using of self explanatory variables.
10. Advantages
Can execute and share the code on different
machines.
No objects storage required.
Change in object properties does not interupt
whole application.
Its fun in learning and writing your test
yourself