Saturday, 15 October 2011

Debugging In QTP

This article explains the procedure to debug the scripts in QTP. Every Automation Engineers should be strong in debugging. Then only we can fix the script issues in a fast manner and complete the scripts successfully.
Here comes the steps involved in debugging.
01. Debugging Configuration: Navigate to Tools> Options > Run tab and make sure that the option "Normal" is enabled. If this options is disabled we can come to know that the Microsoft Script Debugger is not installed. We need to install the script debugger to enable this option.

02.Using Breakpoints: Breakpoints are inserted into script to switch the script from normal mode to debugging mode. We can insert the break point for the selected step by pressing F9 or right click on the step and select "Insert/Remove Breakpoin.." from the context menu. So, the script execution will be stopped on the selected line.
Assume that we have 4 lines of code and inserted the breakpoint on 6th line.So, the script execution will be stopped at 4th line.
Note: One Red Dot will be appeared on the left side of the selected line once the break point is inserted.

03. Enabling the Debug Viewer: Debug viewer is used to watch the values of the variables during execution. So, we should enable the debug viewer.Debug viewer can be enabled by selecting the option View>Debug Viewer.

04. Assume that we have the following code.
          01. Dim a,b
          02. a="This is the debugging code"
          03. b=Left(x,4)
          04. MsgBox b  'Assume that the break point is inserted here.

05.Working with Watch expression tab in Debug Viewer: In this tab we can add the variables a,b in left columns and can see the contents of the variables in right column of each variable. As per above example we can see "This is the debugging code" and "This" for the variables a and b respectively and also length of a,Mid of a also displayed. We can also change the values of each variables by double clicking on it.

06. Working with Variables tab in Debug Viewer: We can see the name and values of all variables that are currently visible in the local scope.As per the above example we can see "This is the debugging code" and "This" for the variables a and b respectively.

07. Working with Command Tab in Debug Viewer: This tab is used to execute the VBScript statements interactively. Select the tab and then type b "changed from command" and press Enter key.. Now navigate to Variables tab and can the value for b as "changed from command".

Friday, 14 October 2011

QTP Short Cut Keys

This article gives the short cut keys details.

File Menu

New > Test CTRL + N
New > Business Component CTRL + SHIFT + N
New > Scripted Component ALT + SHIFT + N
New > Application Area CTRL +Alt + N
Open > Test CTRL + O
Open > Business Component CTRL + SHIFT + O
Open > Application Area CTRL + ALT + O
Save CTRL + S
Export Test to Zip File CTRL + ALT + S
Import Test from Zip File CTRL + ALT + I
Print CTRL + P

Edit Menu

Cut CTRL + X (EV only)
Copy CTRL + C
Paste CTRL + V
Delete DEL
Undo CTRL + Z (EV only)
Redo CTRL + Y (EV only)
Rename Action F2
Find CTRL + F (EV only)
Replace CTRL + H (EV only)
Go To CTRL + G (EV only)
Bookmarks CTRL + B (EV only)
Complete Word CTRL + Space (EV only)
Argument Info CTRL + SHIFT + SPACE (EV only)
Apply “With” To Script CTRL + W (EV only)
Remove “With” Statements CTRL + SHIFT + W (EV only)

Insert Menu

Checkpoint > StandardCheckpoint F12
Output Value > Standard Output Value CTRL + F12
Step > Step Generator F7
New Step F8 OR INS (KV only)
New Step After Block SHIFT + F8 (KV only)
Key: KV = Keyword View
EV = Expert View

Test/Component/Application Area Menu

Record F3
Run F5
Stop F4
Analog Recording CTRL + SHIFT + F4
Low Level Recording CTRL + SHIFT + F3
Step Menu
Object Properties CTRL + ENTER
Value Configuration Options CTRL + F11 on an input value
(KV only)
Output Options CTRL + F11 on an output value
(KV only)

Debug Menu

Step Into F11
Step Over F10
Step Out SHIFT + F11
Insert/Remove Breakpoint F9
Clear All Breakpoints CTRL + SHIFT + F9

Data Table Options

Edit > Cut CTRL + X
Edit > Copy CTRL + C
Edit > Paste CTRL + V
Edit > Clear > Contents CTRL + DEL
Edit > Insert CTRL + I
Edit > Delete CTRL + K
Edit > Fill Right CTRL + R
Edit > Fill Down CTRL + D
Edit > Find CTRL + F
Edit > Replace CTRL + H
Data > Recalc F9
Insert Multi-line Value CTRL + F2 while editing cell
Activate next/previous sheet CTRL + PAGEUP/CTRL + PAGEDOWN

General Options

View Keyword View/Expert View CTRL + TAB
Open context menu for step or Data Table cell SHIFT + F10
or Application key ( )
Expand all branches * [on numeric keypad] (KV only)
Expand branch + [on numeric keypad] (KV only)
Collapse branch - [on numeric keypad] (KV only)

Thursday, 13 October 2011

Synchronization in QTP

Synchronization is the process of matching the speed of the AUT and QTP inorder to get the proper execution of results.As part of the script execution QTP give the instructions step by step with the same speed. Sometimes AUT may respond quickly. Sometimes AUT may take time to respond. In such kind of situations we may not proper result. To resolve these type of issues, we can use synchronization.

Synchronization can be done by using any one of  the following methods.

01. Using Wait method:By using this we can make the script to wait for n-number of seconds before moving to next step. But this is not most useful method. Assume that we have given the waiting time as 20 seconds and the AUT is responding in 5 seconds. But the execution will be resumed after 20 seconds only.Wait method is useful to capture the screenshots when the script is waiting for the desired number of time. Wait method doesn't requrie any references.It's a VBScript function.So, can be used globally.

Syntax:Wait(time in seconds).

02. Inserting Synchronization points: Make sure that QTP is in recording mode.Keep the cursor in the desired location and navigate to Insert menu> Synchronization point>select the object> OK> select property name and value as True>Enter time in milli seconds and click ok> Stop recording.
Syntax: Object.WaitProperty "property name","value",time in milli seconds

03. Increasing QTP default time wait:We can change the QTP synchronization time out by navigating File> Settings> Run tab > Increase the synchronization time out.The same time setting is applicable for all steps in the script. But the main advantage is the script will move to next step as soon as the current step is over. It'll not wait for the maximum amount of time configured.

04. Sync method: This method can be used with web based applications only. This method waits for the browser to complete the current operation.
Syntax: Browser("aaa").Page("bbb").Sync
Appropriate Methods selection:

01.Suppose in our test one or more statements only are taking more time for execution then selecting “Inserting synchronization method” is better.
02. Suppose in our test more statements are taking more time for execution then selecting “increasing tool time out” .
03. Above two are local features but wait statement is Vbscript feature, even though some drawbacks are there in using wait statement, it is better to use wait statement in functions.

Wednesday, 12 October 2011

How to close all browsers in QTP?

This is very basic task to be done by the automation test engineer before starting the script execution.It's always better to kill/close
all related applications to avoid the unexpected behavior of QTP.
For example we can take a web based application.Assume that there are
n-number of windows has been opened for the same application. In such kind of scenarios, it's always better to close all windows and start from scratch.
 To achieve this we can use the QTP browser property "CreationTime".CreationTime indicates the order in which the browsers are opened.

Assume that we opened 5 browsers at 1.10,1.12,1.13,1.14 and 1.15.So, we will have the creation times as 0,1,2,3 and 4 for each browsers.The browsers can be closed by using the creation time.

Code Snippet:

01.While Browser("CreationTime:=0).Exist

Details of the above snippet:

01. Checks whether the first opened browser exists or not
02. Closes the first opened browser
03. Loop end

We can also close the browsers based on the mask.Assume that we opened n-number of Google sites.All browsers will have the URL as ""This is called mask. We can use the following code snippet to close the browsers based on the mask.

Dim Url, CreationTime,Mask
While Browser("CreationTime:="&CreationTime).Exist
'check whether Url contains the mask
If InStr(Url,Mask)>0 Then
'Close the current browser
End If

Using the above code snippet we can close the browsers dynamically by mask.

Back To Top