Tuesday, 9 September 2014

Vbscript in QTP - Part-1

VB Script
It is a Microsoft scripting language
VB script is case-insensitive
For comment we can use “Rem” or Single quote (‘) in front of the statement
Action Template: (Header file)
To get pre-defined components in each Action script in QTP we create and maintain Action Template

In general following are the components maintained in Action Template:
Project:
Module:
Created By:
Created On:
Test Script Description:
Referred Doc:
QTP version:
Reviewed By:
Reviewed On:

Navigation: to create Action template
  • Open Text file
  • Write required components in Action template
  • Provide comments (Rem or “’”) for each component
  • Save file with name as “ActionTemplate.mst” in QTP, data folder
  • (mstà module script template)


Note:
For a QTP we can maintain only one Action template, based on requirement we can modify information in Action template that modification will be effected only for new tests


Low-Level Recording

Low-Level Recording:
In following scenarios we can prefer Low-level recording
1.      To record operations which we perform on non-supported environment application objects
2.      To get exact co-ordinates of application object in the script

Low-level recording mode is able to convert some of mouse clicks and keyboard operations .
Script generates irrespective of object class like window and winobject
Navigation:
Enter into standard recording mode
·         “Automation” menu
·         Select “Low-Level Recording”
·         Perform operations on AUT
·         Stop recording
Note:
Low-level recording script sometimes may not execute successfully.
In one script we can maintain different recording modes script


Analog Recording

Analog Recording:
It records mouse clicks, key board operations and mouse movements w.r.t screen area or specified window co-ordinates based.
There are 2 types of options in Analog Recording:

Record relative to screen:
When we select this option QTP records our operations w. r. to desktop co-ordinates based
Script:
Desktop.RunAnalog “Track1”
During runtime QTP identify same position on desktop and perform operations irrespective of application objects availability
Note: this option can be preferred to record operations which we perform on pop-up windows

Record Relative to the following window:
When we select this option QTP records our operations w. r. to specified window co-ordinates based
Script:
Window(“window name”).RunAnalog “Track 1”
During runtime first QTP identify specified window on screen and then perform operations w. r. to that window co-ordinates based.

Navigation: for Analog Recording
1.      Enter into standard recording mode
2.      “Automation” menu
3.      Select “Analog Recording”
4.      Select option in “Analog Recording settings” window {if we selected 2nd option click on “Hand icon” button and click on application window}
5.      Click on “Start Analog recording” button
6.      Perform required operations on AUT which you want to convert into automation script
7.      Stop recording
8.       
Ex: create basic script to open 5th order number record in “FR” application using analog recording 1st option
Ex: create basic script to open 5th order number record in “FR” application using analog recording 2nd option

Note:
Analog recording script is not possible to perform any editing operations due that reason it is not preferable to record all the operations into automation script
To record general operations we prefer standard recording
To record operations which are related to mouse movements like drawing operations, digital signatures…etc
Ex: create script to write “Mindq” in ms-paint window

Ex: Create script to open 5th order number record and to send fax to customer

Standard Recording

Standard Recording:
It records mouse clicks and key board operations which we perform on supported environment applications
For each operation there will be individual steps generate in the script
Script will generate w. r. to class of the object
Navigation: for standard recording:
Open New Test in QTP
Click on “Record” icon
Perform operations on AUT, which operations do you want to convert into automation script
Stop recording

Ex: create Basic script to perform multiply operation on calculator application
Step 1: activate “Calculator” window
Step 2: click on “C” button
Step 3: click on “9” button
Step 4: click on “*” button
Step 5: Click on “5” button
Step 6: click on “=” button

Ex: create basic script to open 5th order number record in “FR” application
Step 1: activate “FR” window
Step 2: select “Open Order…” option in “File” menu
Step 3: activate “Open Order” sub window
Step 4: set “ON” for “Order No.” check box
Step 5: enter value “5” in edit box
Step 6: click on “OK” button

Ex: create basic script to perform login operation where QTP should open application during recording and runtime
Step 1: Activate Login window
Step 2: enter “Mindq” in “Agent Name:” edit box
Step 3: enter “Mercury” in “Password:” edit box

Step 4: click on “OK” button

Recordings in QTP

By default QTP able to convert our business transactions which we perform on AUT into automation script is called Recording

There are 3 types of recording modes:
  • Standard Recording\context sensitive recording
  • Analog recording
  • Low-level recording