Tuesday 7 August 2012

QTP class notes


AUTOMATION TESTING

MANUAL TESTING

Testing an application with human interaction is called Manual Testing.

Drawbacks of Manual Testing

(i)                Time consuming.
(ii)              More resources required.
(iii)           Human Errors
(iv)           Repetition of the Task is not much
(v)              Tiredness
(vi)           Simultaneous auctions are not possible (Parallel) 

 

Automation Testing
Testing an application with 3rd Party Software help is called Automation

Testing.
(or)

Testing  an  application  with  an  Automation  Tool  is  also  called  as

Automation Testing.

Benefits of Automation Testing:

a)     Fast
b)    Reliable
c)      Repeatable
d)    Reusable
e)      Comprehensive
f)      Programmable.

a)  Fast

Automation  tool  runs  tests  significantly  more  faster  than  human
users.

b) Reliable

Automation tool can perform the same operation each time, if you repeated multiple times, so that we can eliminate human errors.

c)  Repeatable

We can check how application or website reacts after repeated the same operation with multiple times.




d) Reusable

Automation scripts are reusable on different version of the application of websites even if the user interfaces changes.

e)  Comprehensive

In automation testing we can build a suit of tests that covers every feature in the application or website.

f)  Programmable.

We can program sophisticated Tests that bring out hidden information from the application.

Drawbacks of Automation Testing

1)    It is expensive
2)    We cannot automate all areas.
3)    Lack of expertisation.
4)    It has some limitations (It cannot test every thing)

Which Software Testing should be automated?

Tests that need to be execute of every build of the application (Sanity Testing)

Tests that use multiple data values (Retesting / Data Drives Testing) Tests that required data from application intimates (G.U.I. Attributes) Load and Stress Testing

Which Software Testing should not be automated?

Usability Testing One time testing

Quick look Tests or A.S.A.P (As soon as possible) Testing Ad-hoc testing / Random Testing

Customers requirement are frequently changing.

Type of Tools

Generally they are (4) Types of tools are available in the market.  They are
1)    Functional Tools:

QTP, WinRunner, Silktest, Rational Robot, TestPartner, etc.,

2)    Performance Tools:
LoadRunner, J-Meter etc.,

3)    Test Management Tools:
Quality Center (QC), Test Director.

4)    Version Control Tools

VSS (Visual Safe Source), PVCS (Polytron Version Control System) etc.,






QUICK TEST PROFESSIONAL

QTP is a Functionality Testing Tool developed by Mercury Interactive later merged with HP
QTP has released in following Versions. 5.5 6.5 8.0 8.2 9.0 9.1 9.2


9.5 (Latest)

License
They are Two types of licenses (1) Seat License (Single User) and (2) Concurrent License (Multiple Users).

Technologies

QTP 9.2 Supports following Technologies
.Net, VB, JAVA, ActiveX Controls, Web Servers, People Soft, SAP, Oracle, Terminal Emulators, HTML, DHTML, XML ….. etc.,

QTP 9.5 Supports following Technologies

Power Builder, Oracle Forms10, Apps 12, New Terminal Emulator Versions (Mainframe Application Technologies), .Net (3.5)

Environments

QTP 9.2 Support on following Environment
Windows 2000 Server, 2000 Professional, 2003 Server, XP etc.,
QTP 9.5 Support on following Environment
Windows Vista (64 Bit), Eclipse (3.2 & 3.3), Netscape 9.0, Firefox (3.0)
Note

QTP does not support on Linux / Unix Operating Systems. X-Runner supports on Linux / Unix Operating System.

QTP can support client / Server, Web Applications.
QTP Records the business operations in VB Script (It can also support JAVA Script)
QTP can support Multimedia Applications such as Flash, Windows Media Player, Real Video etc.,









How to Launch QTP (9.2)

Start Æ Programs Æ QuickTest Professional Æ QuickTest Professional ÆSelect Specified Add-in Manager Æ Ok



Apart from the 3 Options, QTP supports standard windows Environment (When we uncheck the above 3 Options)











Prepare to Record

Recording










Editing







Debugging



Running


Analyze Results







QTP (9.2) TESTING PROCESS

Context Sensitive Mode / Standard Mode (Default)
Analog Recording Mode Low Level Recording Mode

Standard Checkpoint
Bitmap Checkpoint

Database Checkpoint

Text Checkpoint

Text Area Checkpoint

Page Checkpoint

Table Checkpoint

Image Checkpoint

Accessibility Checkpoint

XML Checkpoint




Verify Mode (Default)
Update Run Mode

Debugging Mode




Defect Report






Recording Modes

In QTP, there are (3) Recording Modes such as

1)  Context Sensitive Mode

In this mode QTP Records the operations which are performed on the objects. Context Sensitive Mode is also called as “Standard Recording Mode / Normal Recording Mode”.

Context Sensitive Mode is default Recording Mode in QTP.

2)  Analog Recording Mode

In this mode QTP records the Mouse and Keyboard Operations with respective to Window (or) Desktop co-ordinates.
Syntax: If you take Desktop Coordinates Desktop Æ Desktop.RunAnalog "<Track No.>"

Window Æ       Window("Window_Name").RunAnalog "<Track No.>"
Navigation

Start  Recording  (F3)  Æ  Automation  Menu  Æ  Analog  Recording  Æ





Analog  Recording  Settings                                          (Shift  +  Alt  +  F3)  Æ
Click on Æ Click on Start Analog Record Æ Record your required Operation Æ Stop Recording (F4)

Generally we are using Analog Recording Mode to compare “Digital Signatures, Barcodes, Scientific Graphs etc.,
Note

In Context Sensitive Mode, QTP Generate one statement for each operation. But in Analog Recording Mode, QTP Generates single statement for all the operations which you perform on the application.

In Analog Recording Mode, if you take Desktop Co-ordinates, you can get wrong output, if application is moved from one place to another place at Run Time.
If you take Window co-ordinates, we can get right output even if the application moved from one place to another place.













3)    Low Level Recording Mode

We can use this mode to records the operations which are not recognized

by Tool.

Navigation

Start Recording (F3) Æ Automation Menu Æ Low Level Recording Mode (Crtl + Shift + F3) Æ Record your required Operation Æ Stop Recording (F4)

Note: We are giving low priority to this recording mode.
Important Note

If you want to select Analog Recording Mode or Low Level Recording Mode you must be under Context Sensitive Mode.

Running Modes

There are (3) Running Modes such as (1) Verify Mode (2) Update Run Mode (3) Debugging

1)  Verify Mode

To compare expected value with Actual value and Return results.

2)  Update Run Mode

To update Test or Component.

3)  Debugging

Whether the script is smoothly executing or not without any interruptions.
Note

Verify Mode is the default Running Mode in QTP. Maintenance Run Mode is the extra Run Mode in QTP 9.5 than 9.2.

Window / Object
Script
Main Window
Window(“Window_Name”)
Sub Window
Dialog (“Window_Name”)
Edit Box
WinEdit(“EditBox Name”)
Combo Box
WinCombo(“ComboBox Name”)
Menu
WinMenu (“Menu”)
Radio Button
WinRadioButton(“Radio Button Name”)
Check Box
WinCheckBox(“Check Box Name”)
Push Button
WinButton(“Push Button Name”)












Note










Environment
Class Name



Visual Basic
VBButton



JAVA
JAVAButton



Web
WebButton



ActiveX
ACXButton



.Net
SWFButton




(Shock Wave Flash)



Standard Window
WinButton









Operations
Script
Active Window
.Activate
Enter Text in Edit Box
.Set "Text"
Select Item from the Combo Box
.Select "Item Name"
Select item from the Menu
.Select "Menu_Name;Item_Name"
Check on or off the Radio Button
.Set
Check on or off the Check Box
.Set “On/Off”
Press on Push Button
.Click
Enter Password in Edit Box
.SetSecure "Encrypted_Text"

Windows Based

In which window.on what object.what operation is done. Syntax:
Window(“Window_Name”).Object(“Object_Name”).Operation/Method.

Web Based

In which browser.in which page.on what object.what operation is done. Syntax: Browser(“Browser_Text_Name”).Page(“Page_Name”).Object(“Object_Name”)

.Operation/Method.

Example-1:
Expected:

Π  Activate Window.

Π  Enter Employee Name as Appa Rao.
Π  Enter Employee No. as E001
Π  Enter Employee Salary as 10000
Π  Click on Submit

Script

Π  Window("Employee").Activate

Π  Window("Employee").WinEdit("Employee Name:").Set "Appa Rao"
Π  Window("Employee").WinComboBox("Employee No:").Select "E001"
Π  Window("Employee").WinEdit("Employee Salary:").Set "10000"
Π  Window("Employee").WinButton("Submit").Click





Ex-2:

Expected:
Π Activate Window.

Π Enter Agent Name as Apparao

Π Enter Password as mercury

Π Click on Ok




Script

Π Dialog("Login").Activate

Π Dialog("Login").WinEdit("Agent Name:").Set "Apparao"
Π   Dialog("Login").WinEdit("Password:").SetSecure "492555ba0ee4f4f47004a1821cb87f8cc8ffe920"

Π Dialog("Login").WinButton("OK").Click



Ex-3:













Expected

Π Activate Window.

Π Enter Patient Name as “XYZ”
Π Select Ward No. as “101”
Π Select Referral Doctor as “Dr.John”
Π Cough Radio Button ON
Π Bill Check Box ON
Π Click Ok
Π Enter X-Ray cost as “200”
Π Enter Blood Test as “300”
Π Enter Bed Bill as “500”
Π Click Ok.









8                                                                                                                           Automation Testing


Script

Window("KeyClinic").Activate
Window("KeyClinic").WinEdit("Patient Name:").Set "XYZ"
Window("KeyClinic").WinComboBox("Ward No:").Select "101"

Window("KeyClinic").WinComboBox("Referral Doctor:").Select "Dr.John"
Window("KeyClinic").WinRadioButton("Cough").Set
Window("KeyClinic").WinCheckBox("Bill").Set "ON"

Window("KeyClinic").WinButton("Ok").Click
Window("KeyClinic").Dialog("Bill").WinEdit("X-Ray:").Set "200"
Window("KeyClinic").Dialog("Bill").WinEdit("Blood Test:").Set "300"
Window("KeyClinic").Dialog("Bill").WinEdit("Bed Bill:").Set "500"

Window("KeyClinic").Dialog("Bill").WinButton("Ok").Click

Ex-4
Expected
ÎClick Ok

Script

Window("SAMPLE").Dialog("SAMPLE-1").
Dialog("SAMPLE-2").WinButton("Ok").Click




Ex-5
Expected
Π  Enter Branch Name as “Ameerpet”

Π  Enter Address as “Ameerpet”.
Π  Enter ZIP Code as “500016”
Π  Select Country as “India”
Π  Select State as “Andhra Pradesh”
Π  Select City as “Hyderabad”.









Script

Π  Browser("AXIN BANK").Page(“AXIN BANK).WebEdit("Branch Name").Set "Ameerpet"

Π  Browser("AXIN BANK").Page(“AXIN BANK).WebEdit("Address").Set "Ameerpet"

Automation Testing                                                                                                                           9





Π Browser("AXIN BANK").Page(“AXIN BANK”).WebEdit("ZIP Code").Set "500016"
Π Browser("AXIN    BANK").Page(“AXIN    BANK”).WebList("Country")
.Select "India"
Π Browser("AXIN BANK").Page(“AXIN BANK”).WebList("State").Select "Andhra Pradesh"
Π Browser("AXIN BANK").Page(“AXIN BANK”).WebList("City").Select "Hyderabad"

Π Browser("AXIN BANK").Page(“AXIN BANK”).WebButton("Submit"). Click

Ex-6

Expected
Π  Enter Agent Name as “John”

Π  Enter Password as “mercury”
Π  Click on “Login”



Script

Π  Browser("Rediff Shopping").Page(“Rediff Shopping”).WebEdit("Agent Name").Set “John”

Π  Browser("Rediff Shopping").Page(“Rediff Shopping”).WebEdit("Password").SetSecure“49 2b7106207d6db37e2a339047b52e9d09b8ed48”

Π  Browser("Rediff Shopping").Page(“Rediff Shopping”).Image("Login").Click






























10                                                                                                                        Automation Testing


                                                                                                                           


Architecture of QTP Screen






Data

Table

Test Pane









Active
Debug

Viewer

Screen



Information


Pane


Missing


Resources


Pane



1)  Test Pane

In this QTP displays the Test Script which you record on the application.

To view the Test scripts, there are two modes such as (i) Keyword View (ii) Expert View.
(i)      Keyword View
In this mode QTP displays the test script in object hierarchy way and it provides documentation for every operation.
There are (4) Parts (i) Item (ii) Operation (iii) Value (iv)Documentation likes as below.





(ii)     Expert View

In this mode QTP displays the Test script in VB Script.

                                                                                                                                                      
2)    Data Table

Π It is used to store the data and parameterize that data to the test script
Π There are (2) Sheets by default.  They are (1) Global (2) Action1
Π In one data table we will have 256 Sheets. Out of 256 sheets, one sheet is Global and remaining 255 sheets are Action Sheets
Π Global Sheet related to all the tests.
Π Action Sheet related to corresponding Action only.

3)    Active Screen

In this QTP captures window snapshots for every object operations and displays those images in Active Screen Area.
Advantages
i)      Easy to insert Check Points

ii)    Easy to insert Output values.
iii) Easy to add objects to all object repository.
iv) Easy to insert steps.
v)    Easy to understand  script by observing images in active screen area
Disadvantages

It occupies lot of space to store the snapshots.

To disable Active Screen

Tools Æ Options Æ Active Screen Tab Æ Custom Level Æ under Windows applications Select “None” Æ under Web select “Disable Active Screen capture” Æ Ok Æ Ok

4)  Debug Viewer

It is used for viewing, modifying or setting the current values of variables or objects during Test execution break with the help of “3” Options, such as (i) Watch (ii) Variables (iii) Command.

5)  Information Pane

It displays the syntax of related information during “Check Syntax” “Syntax Check” (Ctrl + F7)

6)  Missing Resources Pane

Whenever we open a test, the files which are associated with that test are missed / moved, then Missing Resources Pane will be opened automatically and displays the information about that missed file.








Run in Update Run Mode
CHECK POINTS

1)  Standard Check Point
We can use this check point to verify the property of an object.
Ex: Verify Update Order
Step Name
Step description
Expected result
Actual
Status
Step-1
Activate Window
Disable


Step-2
Open Record
Disable


Step-3
Perform change
Enable



Navigation

Start Recording Æ Click on “Ok” Æ Activate Window (Flight 4a.exe) Æ File Menu Æ Click on Open Order Æ Select Order No. Æ Enter No. Æ Click on Ok Æ Perform any change Æ Click Update Order Æ Stop Recording Æ Keep the application (Flight4a.exe) in base state Æ Identify positions in the Test Script to insert Check Points [After Activate window; after open order; after perform change] Æ Start Recording Æ {Insert Menu Æ Check Points Æ Click on
Standard Check Point} {or F12} Æ show object [ ] with Æ Click Ok Æ Enter Name of the Check Point Æ Select Property with expected value (Enable-True = Enable; Enable-False = Disable)Æ Click Ok Æ Stop Recording after insertion of all Check points at relevant places Æ Click Run Æ Analyze results manually.
Ex:1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("CP_1") Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("CP_2") Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "30" Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click Window("Flight Reservation").WinRadioButton("Economy").Set Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("CP_3") Window("Flight Reservation").WinButton("Update Order").Click
wait (10)
If Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty("text") ="Update Done..." Then
msgbox ("Test is pass")
else
msgbox ("Test is fail")
End If







How to edit existing check point:

Place the cursor on Check Point which you want to edit Æ Right Click Æ Check Point Properties Æ Select property Æ Change value or Rename Check

Point Æ Click Ok.


How to insert check point through Active Screen

Start Recording Æ Record Required Operation like as below [Click on “Ok” Æ Activate Window (Flight 4a.exe) Æ File Menu Æ Click on Open Order Æ Select Order No. Æ Enter No. Æ Click on Ok Æ Perform any change Æ Click Update Order] Æ Stop Recording Æ Keep the application (Flight4a.exe) in base state Æ Identify positions in the Test Script to insert Check Points [After Activate window; after open order; after perform change] Æ place the cursor on specified statement Æ Click on Active Window Æ Right Click on object Æ Click on Insert Standard Check Point Æ Click Ok Æ Enter Check Point Name Æ Select Property with expected value (Enable-True = Enable; Enable-False = Disable) Æ Select option to insert statement (Before current Step / After current Step) Æ Click Ok Æ Click Run after insertion of all Check points at relevant places Æ Analyze results manually.









2)  Bit Map Check Point

We can use this Check Point to conduct test on Bitmaps.
Navigation

Start Recording Æ Help Menu Æ Click on about Æ Insert Menu (QTP) Æ Check Point Æ Click Bit Map Check Point Æ Show Bitmap with hand icon
Æ    Click Ok Æ Enter Name of the Check Point Æ Click on select area if you want to check a specific area with in the Bit Map Æ Select save only selected area Æ Click on Ok Æ Stop Recording Æ Close current application (Flight 4a)
Æ      Open another application (Flight 4b) Æ Click run to analyze results manually.

How to insert check point through Active Screen

Start Recording Æ Help Menu Æ Click on about Æ Click on Bit Map Æ Stop
Recording Æ Click on Active Screen Icon  Æ Right click on Bit Map which you want to check Æ Click on Insert Bitmap Check Point Æ Click Ok Æ Enter Name of the Check Point Æ Select area which area to be checked Æ Select option to insert statement (Before current Step / After Current Step) Æ Click on Ok Æ Close current application (Flight 4a) Æ Open another application (Flight 4b) Æ Click run to analyze results manually.



















3)  Database Check Point

To automate backend testing we are using Database Check Point. During this testing we are validating backend table in terms of Data validation and data integrity.
Data validation means that the correctness of storing values into backend table.

Data integrity means that the impact of stored values on existing data table content. In this we will be concentrate on primary keys, foreign keys, unique keys, ……. etc.,
To automate backend testing we can follow below approach.

4


1

5

Actual Data

3




2













Expected Value

= = Fail

= ! Pass


Step 1:
Connect to Database using DSN (Data Source Name)
Step 2:
Execute Specified Select statement.

Step 3:
Retrieve the result of SQL Statement

Step 4:
Perform any db Operation.

Step 5:
Compare expected data with actual data to verify the impact of

frontend operation on backend table content.


Navigation

Insert Menu Æ Check Point Æ Database Check Point Æ Select “Specify SQL Statement Manually” Æ Next Æ Create Æ Machine Data source (Select Data source) Æ Select DSN (QT_FLIGHT32) Æ Click Ok Æ SQL Statement (Enter your specified SQL Statement Ex:. select * from orders) Æ Finish Æ Change the Check Point Name Æ Click Ok Æ Open Frontend (perform any db operation like insert, delete, update) Æ Click Run Æ Analyze results manually.


To Create New DSN

*) First of all you create One database in MS Access with specified table.

Navigation

Insert Menu Æ Check Point Æ Click on Database Check Point Æ Select “Specify SQL Statement Manually” Æ Next Æ Create Æ Machine Data source (Select Data source) Æ New Æ Select type of data source (User [Single user] / System Data Source [multiple users]) Æ Next Æ Select a Driver (Microsoft Access Driver) Æ Select database Æ Click Ok Æ Enter Data Source Name with description Æ Click Ok Æ Click Ok Æ Take your specified statement (Table) Ex:. select * from orders) Æ Finish Æ Click Ok.

Note Database Check Point insertion is not possible through Active Screen.



4)  Test Check Point

We can use this checkpoint to conduct test on text present on the object.
Navigation

Start Recording Æ Insert Menu Æ Check Point Æ Click on Text Check Point
Æ   Select object with hand icon Æ Click Æ Ok Æ Enter Name of the Check Point Æ Enter your expected Text in ‘Constant’ Æ Select Matching [(1) Match Case (2) Ignore Spaces (3) Exact Match (4) Text Not displayed] Æ Click on Ok

Æ   Stop Recording Æ Click run to analyze results manually.

Regular Expression. [A-Z] [a-z] [0-9]*
[A-Z] [a-z] [ ] [A-Z] [a-z]* [A-Z] [a-z]*
                                                                                                                            


How to insert check point through Active Screen

Start  Recording  Æ  Activate  Window  Æ  Stop  Recording  Æ  Click  on  Active
Screen Icon  Æ Right click on object, which object text you want to check Æ Select insert Text Check Point Æ Click Ok Æ Enter Checkpoint Name Æ Expected text fill in ‘constant’ Æ Select Matching [(1) Match Case (2) Ignore Spaces (3) Exact Match (4) Text Not displayed] Æ Select Insert Statement (Before / After Current step) Æ Click Ok Æ Click run to analyze results manually.

Regular Expressions:

Whenever the object text is changing dynamically at run time, we can use

regular expressions. Ex
Expected Srnagar1 John Smith Suresh


5)  Test Area Check Point

We can use this Checkpoint to conduct test on Text present in the specified screen area.

Navigation

Start Recording Æ Insert Menu Æ Check Point Æ Click on Text Area Check Point Æ Select the area specified to check Æ Click Ok Æ Enter Name of the Check Point Æ Enter your expected Text in ‘Constant’ or
click on to give Regular expression Æ Select type of Matching [(1) Match Case (2) Ignore Spaces (3) Exact Match (4) Text Not displayed] Æ Click on Ok Æ Stop Recording Æ Click run to analyze results manually.

Note: Text Area Checkpoint is not possible through Active Screen.

6)  Page Check Point (For Web Pages only)

We can use this Checkpoint to verify the properties of a web page.
Navigation

Start Recording Æ Insert Menu Æ Check Point Æ Select Standard Checkpoint

Æ     Show Image / Link with Hand Icon Æ Select Page Æ Click Ok Æ Enter Name of the Checkpoint Æ Select Property [give your expected value (Load time, No. of Images, No of links)] Æ Click Ok Æ Stop Recording Æ Click Run

Æ   Analyze Results manually.

7)    Table Checkpoint

We can use this checkpoint to verify the content of a Web Table.
Navigation

Start Recording Æ Insert Menu Æ Check point Æ Select Standard Checkpoint Æ Select Image with Hand Icon Æ Click Æ Select Web Table Æ Click Ok Æ Enter name of the Checkpoint Æ Select Cell Æ Enter your expected data in constant Æ Click Ok Æ Stop Recording Æ Run Æ Analyze Results manually.
Note:

For Web Table
Browser(“Browser Text Object Name”).Page(“Page Name”).WebTable(“Table

Name”).Check CheckPoint(“Check Point Name”)

For Page Check Point

Browser(“Browser      Text      Object      Name”).Page(“Page      Name”).Check

CheckPoint(“Check Point Name”)

8)  Image Check Point

To   verify   the   properties   of   an   Image,   we   can   use   Image
Checkpoint.
Browser(“Browser   Text   Object   Name”).Page(“Page   Name”).Image(“Image

Name”).Check CheckPoint(“Check Point Name”)

Navigation

Start Recording Æ Insert Menu Æ Check point Æ Select Standard Checkpoint
Æ    Select Image with Hand Icon Æ Click Æ Click Ok Æ Enter name of the Checkpoint Æ Select Property (Alt) [give your expected value to that property]

Æ   Click Ok Æ Stop Recording Æ Run Æ Analyze Results manually.
How can we check Tool Tips Æ Alt Property.

9)  XML Check Point

To verify the content of an XML file we can use this check point.
Navigation

Insert Menu Æ Check point Æ XML Check Point (From File) Æ Browse your XML File path Æ Click Ok Æ Enter name of the Checkpoint Æ Select Element Name Æ Specify your expected value Æ Click Ok Æ Run Æ Analyze Results manually.

10)           Accessibility Check Point

We can use this checkpoint to verify whether the specified Web Page meets W3C (WWWC) Standards or not (World Wide Web Consortium Standards)


Navigation

Tools Menu Æ Options Æ Web Tab Æ Advanced Æ Select / Check in the check point [ActiveX Check, Alt Property Check, Applet Check, Frame Titles Check, Multimedia Links check, Server-side Image Check, Tables Check] Æ Ok Æ Ok Æ Start recording Æ Insert Menu Æ Check Point Æ Click on Accessibility Check Point Æ Show Web Page with Hand Icon Æ Click Æ Ok Æ Enter Name of the Checkpoint Æ Click Ok Æ Stop Recording Æ Run Æ Analyze Results manually.
Note

Page Checkpoint, Table Checkpoint, Image Checkpoint, Accessibility Checkpoint, XML Checkpoint are applicable for Web Pages only.

OBJECT REPOSITORY

It is an interface between Tool and Application Build. Object Repository consists of Recorded Objects description.
1                                                AUT






3





5

4


2
















Automation Testing                                                                                                                         19



Run Time Object is the object which is present in the AUT (Application under Test)
Test object is a reference of Run Time Objects which is created by QTP in Object Repository.
(1)Start Recording
During Recording

(2)Learn Object (Storing the object in Object Repository)

(3)Script Generation


(4)Catch Entry in Object Repository
During Run

(Object Properties in Object Repository )

(match the properties in AUT)




(5)Identify Object in AUT




AUT means Application Under Test.


To open Object Repository

Resources Menu Æ Object Repository (or) Ctrl+R
There  are  (2)  Types  of  Objects  such  as  (1)  Run  Time  Object  (2)  Test

Object.

Run Time Object:



Test Object:



How to Add objects in Object Repository.

Navigation
Open Object Repository Æ Click on Add Object Icon       Æ Show Object with

Hand Icon Æ Click Ok Æ Select Option [Select Object Only, Default Object Types, All Object Types, Selected Object Types] Æ Click Ok.

TYPES OF OBJECT REPOSITORY

1)    Local Repository (Pre-Action Repository [Related to corresponding Action]

2)    Shared Repository [Specific to multiple actions]
How to create Shared Repository?

Open Object Repository Æ File Menu Æ Click Export Local Objects Æ Enter File Name Æ Click Save (It will save as *.tsr)

What is the extension of the Shared Repository?

.tsr (Test Shared Repository)

How to associate Shared Repository?
Resources  Menu  Æ  Associate  Repository  Æ  Click  on  Add    Æ Select  /

Location of Repository file path Æ Click Open Æ Associate with Action Æ Click Ok.



How to associate Repository file during Runtime repositoriescollection.Add “Repository file path” Ex: repositoriescollection.Add “F:\loginrep.tsr”
Note: In QTP every action will have one local repository, apart from that local repository one can associate more than one shared repository to the action.





*.tsr









*.tsr










*.tsr







Module Test Script




Module Test Repository

(*.mts)


(*.mtr)



Some people are calling it as mercury test script   ,mercury test repository
How to edit Shared Repository? Navigation
Resources Menu Æ Object Repository Manager Æ File Menu Æ Open Æ Select the Shared Repository File to be edit Æ Open Æ File Menu Æ Enable Editing Æ then select which object to be edited Æ Save.





Automation Testing                                                                                                                         21




Object Repository Comparison Tool:

We can use this tool to compare two shared object repository files.
Navigation:

Resources Menu Æ Object Repository Manager Æ Tools Menu Æ Object Repository Comparison Tool Æ Select the (2) Shared Object Repository Files you want to compare Æ Ok Æ Analyze statics.

Object Repository Merge Tool

We can use this tool to merge Two shared object Repository files.

Ex:

*.tsr

*.tsr

*.tsr

Insert

Update

Insert

+
=
Cancel

Cancel
Cancel



Reset

Reset

Reset




Update


Navigation

Resources Menu Æ Object Repository Manager Æ Tools Menu Æ Object Repository Merge Tool Æ Select the (2) Shared Object Repository Files you want to Merge Æ Click Ok Æ Save

Object Spy

We can use this option to know the properties and methods of specified object.

Navigation
Tools Menu Æ Object Spy Æ Click on Æ Show your specified object with Æ ClickÆAnalyze properties and methods.
OBJECT IDENTIFYING:

Object Identification Mechanism is based on FOUR Types of properties and Ordinal Identifier.

Mandatory
Assistive


Properties
Properties
Normal Identification Mechanism




Native Class:
Enable:
Matching Mechanism

Text:
Focused:


Base Filter
Optional Filter


Properties
Properties
Smart Identification Mechanism

Abs-X:
Window ID:

Filtering Mechanism

Abs-Y:
X:




Y:







22                                                                                                                        Automation Testing


Ordinal Identifier
Location

Index
Creation Time
QTP Will Follow below process to learn the object during Recording Time.

First of all QTP will learn all the mandatory properties and verify whether these properties are sufficient or not to identify the object uniquely. If it feels these properties are sufficient to identify the object uniquely, then it will stop learning, otherwise it will learn first Assistive Property and verify whether these properties are sufficient or not to identify the object uniquely. If it feels these properties are also not sufficient to identify object uniquely, then it will learn 2nd Assistive Property and verify whether these properties are sufficient or not to identify object uniquely. If it feels these properties are also not sufficient to identify object uniquely, then it will learn 3rd Assistive Property and verify whether these properties are sufficient or not to identify the object uniquely, like this the process continuous till the QTP satisfy to identify the object uniquely or until completion of all the properties learning present in the Assistive Property list.

After completion of all Assistive Properties learning present in the Assistive Property list, still QTP not satisfy to identify the object uniquely, then finally it will learn “Ordinal Identifier” and stop learning.

SMART IDENTIFICATION

If you select “Smart Identification” QTP follows below process during Recording.
First of all it will learn all the Mandatory Properties along with “Base Filter Properties” and “Optional Filter Properties” at a time. But Mandatory Properties will be stored in “Object Repository”, where Base Filter Properties and Optional Filter Properties will be stored in a secrete location. Apart from this the process of learning remains same as above.

QTP Will follow below process to identify the object during Run Time

First of all QTP will take all the properties present in the Object Repository except “Ordinal Identifier” and try to identify the object. If it fails to identify the object, then it will forget / leave the Object Repository and take the alternative description (Base Filter Properties and Optional Filter Properties). In this first of all, it will take all the base filter properties and try to identify the object. If it fails to identify the object then it will take first Optional filter Property and try to identify the object. If it fails to identify the object then it will take 2nd Optional Filter Property and try to identify the object. If it fails

Automation Testing                                                                                                                         23




to identify the object with that property also, then it will take 3rd Optional Filter Property and try to identify the object, like this the process continue till the QTP identify the object uniquely or until completion of all the properties present in the optional filter properties list.

After completion of all the properties present in the Optional Filter Properties list still QTP not able to identify the object uniquely, then it will come back to Object Repository and search for Ordinal Identifier, if it is available, using that QTP roughly identify the object.

ORDINAL IDENTIFIER

(a) Location
If you select Location as Ordinal Identifier, then QTP generates sequence of numbers like 0, 1, 2, 3 ……. based on the location (Place) of the object in a screen.

(b)Index
If you select Index as Ordinal Identifier then QTP generates sequence of numbers like 0, 1, 2, 3 …… based on the sequence of the programs of the object.
(c)  Creation Time (For Browsers only)

If you select Creation Time as Ordinal Identifier then QTP generates sequence of numbers like 0, 1, 2, 3 …… based on loading of a page in browser time.
Navigation
Tools Menu Æ Object Identification Æ Select (Standard Window) as Environment Æ Select Test Object Class which you want to configure Æ Take required mandatory properties / Assistive Properties by clicking Add / Remove Button Æ Select Enable Smart Identification Properties Æ Click Configure Æ Take Base Filter / Optional filter Properties by clicking Add / Remove Button Æ Click Ok Æ Select Ordinal Identifier Æ Click Ok Æ Start Recording Æ Record required Operation Æ Stop Recording Æ Run Æ Analyze Results manually.

Virtual Objects

It is used to recognize specified screen area as standard object.

Navigation

Tools Menu Æ Virtual Objects Æ New Virtual Object Æ Next Æ Select Standard Class under Select Combo Box Æ click Next Æ Mark object Æ Select the Object Æ Next Æ Next Æ Finish.

Drawbacks of Object Repository

It takes lot of time for identifying the object, when the object is changing dynamically during Run time.



24                                                                                                                        Automation Testing


DESCRIPTIVE PROGRAMMING (VB SCRIPTING)

If we specify the description of the object in the program it self that can be called as Descriptive Programming.

Using Descriptive Programming we can execute test script without objects in Object Repository / we can execute the test script without Object Repository.

Advantages of Descriptive Programming

i)       Fast execution.
ii)    Easy to identify the objects, when the objects are  dynamic in nature.
iii)  We can prepare Script without having build.

Disadvantages of Descriptive Programming

i)                   It takes lot of time to design test design (Time consuming for test script design)

To design Descriptive Programming, there are (2) ways such as (1) Specifying the properties and its values directly in the statement (script) (2) Description Object.

Syntax / Code

window(“P1:=Value”, “P2=Value”, ….).Object(“P1:=Value”, “P2=Value”, ….).Operation / Method.

Ex(1):

Prepare descriptive Programming for “Login” Operation in Flight Reservation

Dialog(""text:=Login", “width:=320”").Activate Dialog("text:=Login", “width:=320”).WinEdit("attached text:=Agent Name:"). Set "suresh"

Dialog(""text:=Login", “width:=320”").WinEdit("attached text:=Password:"). SetSecure "4941cfd5b7a0bf66f6e9ded8bacb20164598f9ec" Dialog(""text:=Login", “width:=320”").WinButton("text:=OK").Click

(2) Description Object.

To create Description Object we can follow below syntax.

Syntax / Code

Set Object Name = Description.Create

Object Name (“Property Name”).Value = Property Value

Automation Testing                                                                                                                         25




Ex(2):

Prepare descriptive Programming for “Login” Operation in Flight Reservation

Set dia = description.Create dia ("text").value="Login" dia ("width").value = 320

Set uid = description.Create uid ("attached text").value="Agent Name:"

Set pwd = description.Create pwd ("attached text").value="Password:"

Set but = description.Create but ("text").value = "OK"

Dialog(dia).Activate

Dialog(dia).WinEdit(uid).Set "suresh"
Dialog(dia).WinEdit(pwd).SetSecure "4941d5a45019d0ff89dabd026735808c9030b1f0"

Dialog(dia).WinButton(but).Click

Ex(3):

Prepare descriptive Programming for Open a Record in Flight Reservation

Set win = description.Create win ("text").value="Flight Reservation"

Set menuobj = description.Create menuobj ("menuobjtype").value=2

Set dia = description.Create dia ("text").value="Open Order"

Set cbox = description.Create cbox ("text").value = "&Order No."

Set editobj = description.Create editobj ("window id").value = 1016

Set but = description.Create but ("text").value = "OK"




26                                                                                                                        Automation Testing


Window(win).Activate

Window(win).WinMenu(menuobj).Select "File;Open Order..."
Window(win).Dialog(dia).WinCheckBox(cbox).Set "ON"
Window(win).Dialog(dia).WinEdit(editobj).Set "15"

Window(win).Dialog(dia).WinButton(but).Click

VB Script Statements


(1)     Left
We can use this function to get a specified number of characters from the left side of a string.
Syntax: left (String, number) Ex: x="sairam"
msgbox left(x,3)

(2)             Right

We can use this function to get a specified number of characters from the

right side of a string. Syntax: right (String, number) Ex: x="sairam"
msgbox right(x,3)

(3)             Len

We can use this function to find length of a string
Syntax: len (String) Ex: x="sairam" msgbox len(x)

(4)             Mid

We can use this function to get a specified number of characters from the

given string.

Syntax:       mid (String, Start Position, length)
Ex: x="$1245" msgbox mid(x,2,len(x)-1)
Ex: x="Rs.14258/-" msgbox mid(x,4,len(x)-5)



(5)             LTrim

We can use this function to remove spaces from the left side of a string.

Syntax:
ltrim (String)
Ex: x="
Sai"
msgbox ltrim(x)



(6)             RTrim

We can use this function to remove spaces from the right side of a string.

Syntax:       rtrim (String)
Ex: x="Sai                "

msgbox rtrim(x)

(7)             Trim

We can use this function to remove spaces from both the sides of a string.

Syntax:       trim (String)
Ex: x="              Sai                  "

msgbox trim(x)

(8)             UCase

We can use this function to convert Lower Case into Upper Case

Syntax:       ucase (String)
Ex: x="sairam" msgbox ucase(x)

(9)             LCase

We can use this function to convert Upper Case into Lower Case
Syntax:       lcase (String)

Ex: x="SAIRAM" msgbox lcase(x)

(10)        Strreverse

We can use this function to reverse the string.
Syntax:       strreverse (String)

Ex: x="SAIRAM" msgbox strreverse(x)

(11)        Strcomp

We can use this function to compare two strings

Syntax:       strcomp (String1, String2, Compare)
0
1
Binary Comparison
Textual Comparison
Ex:

x="SAIRAM"

Y="sairam"

If strcomp(x,y,0)=0 then

msgbox "Both are Equal"

else

msgbox "Both are not Equal"

end if

(12)        Cint

We can use this function to convert given value into Integer.

Syntax:       cint (expression)
Ex: x="10.54" msgbox cint(x)

(13)        Cdbl

We can use this function to convert the given value into double.

Syntax:       cdbl (expression)



(14)        Cstr

We can use this function to convert given value into String.

Syntax:       cstr (expression)



(15)        Round

We can use this function to rounding the value.
Syntax:       round (expression, No. of decimal places)

Ex: x="10.123456789" msgbox round(x,3)


(16)        Split

It is used to return “0” Zero Based one dimensional array containing a

specified no. of substrings.
Syntax:

Split (expression, delimiter) Ex:
s="India is a great country"
arr=split(s, " ")



msgbox arr(0)
Æ
India

msgbox arr(1)
Æ
is

msgbox arr(2)
Æ
a

msgbox arr(3)
Æ
great

msgbox arr(4)
Æ
country



(17)
Join









It is used to return a string created by joining a specified no. of substrings contained in an array.
Syntax:

join (list, delimiter) Ex:
s="India is a great country" arr=split(s, " ")

msgbox arr(0)
Æ
India



msgbox arr(1)
Æ
is

msgbox arr(2)
Æ
a

msgbox arr(3)
Æ
great

msgbox arr(4)
Æ
country

msgbox join(arr, " ")



Note
How to add two variables values. a="Sai"

b="Ram" msgbox a&space(10)&b


(18)        Space

It is used to create a specific No of spaces 
Syntax:

space (Number)


(19)        Rem

It is used to insert comment.

Syntax rem statement

Note

Ctrl + M Æ Comment Block
Ctrl +Shift + M Æ Uncomment Block

(20)        Date

It is used to return current system date.
Syntax: msgbox date

(21)        Time

It is used to return current system time.

Syntax msgbox time
(22)        Now Syntax msgbox now


(23)         Weekdayname Syntax
msgbox weekdayname(weekday(date))
Note

The default variable type in VB Script is “Variant”

For Loop

Syntax
For i=1 to n step1

.........................

.........................

statement
.........................

.........................

Next

While Loop

Syntax
While condition
.........................

statement
.........................
Wend

If Condition

Syntax                                                                      Ex:
If condition Then                                           a=10

statement                                              b=20
else                                                          If a>b Then
statement                                                          msgbox "a is greater"

End If                                                                             else
msgbox "b is greater"

End If

Else If

Syntax                                                                      Ex:
If condition Then                                           a=10
statement                                              b=20
else if condition then                        c=30

statement
else
statement
end if                                                      If a>b and a>c Then
End If                                                                             msgbox "a is greater"
else if b>c then
msgbox "b is greater"

else
msgbox "c is greater"
End If

End If

Select Case

It is similar to Switch Statement
Syntax                                                                      Ex:

Select Case Variable                                     x=inputbox("Enter alphabet")

Case "value1", "value2", ………             Select Case x

Statement                                             Case "a", "e", "i", "o", "u"
Case “Value”                                                               msgbox "It is Vowel"

Statement                                             Case else

Case else                                                                       msgbox "It is not Vowel"
Statement                                             End Select

End Select


How to declare variables in VB Script?

To declare variables in VB Script we are using one script.

(i) Option Explicit

To forcibly declare variables (This statement display error message for undeclared variables)

(ii)Dim Variable1, Variable2, Variable3, …….. Variables

(To declare variables)

METHODS

GetVisibleText
We can use this method to capture visible text.
Code:
Variable=Window("Window Name").Object("Object Name").GetVisibleText()

Ex:









x = Dialog("Login").WinEdit("Agent Name:").GetVisibleText() msgbox x

Output











GetROProperty

We can use this method to capture run time property value into variables. Or
We can use this method to capture object property “from the application”
Code
Variable = Window("Window Name").Object("Object Name").GetROProperty ("Property Name")

Ex:









Dialog("Login").Activate

x = Dialog("Login").WinButton("OK").GetROProperty("Enabled") msgbox x

Output








GetTOProperty

We can use this method to capture text object value into variable. Or

We can use this method to capture object property value from the object Repository.
Code
Variable = Window("Window Name").Object("Object Name").GetTOProperty ("Property Name")
Ex:









Dialog("Login").Activate

x = Dialog("Login").WinButton("OK").GetTOProperty("Enabled") msgbox x

Output







Report Event:

We can use this method to report an event to the Test Result Window.
Syntax:
reporter.ReportEvent EventStatus, ReportStepName, Details

micPass (0) micFail (1) micDone (2) micWarning (3)

Print

It is used to display your specified message in Quick Test Print log.
Syntax:
Print “Message”

Ex: a=10 b=20
If b=a+10 Then
msgbox "b is equal to a"
print "b is equal to a"
reporter.ReportEvent micPass, "b is equal to a", "Test is Pass" else

msgbox "b is not eqaul to a"
print "b is not equal to a"
reporter.ReportEvent micFail, "b is not equal to a", "Test is fail"

End If





Step Generator (F7)

It is used to generate steps in the Test pane without click on start Recording.
Step Generator consists of statements in three categories such as
(i)               Functions
(ii)             Utility objects
(iii)          Test Objects.

(i)      Functions

This category specifies all general and mathematical operations such as left, right, len, time, cint, cdbl, cstr, ltrim, rtrim, trim etc.,
(ii)     Test Object
This category specifies the operations which are performed on the objects such as Set, Select, Activate, SetSecure, Click, GetVisibleText, GetROProperty, GetTOProperty, GetItem, GetItemCount, GetContent …. Etc.,
(iii)          Utility Objects
This category specifies all miscellaneous operations such as DataTableOperations, SystemUtil Operations, QCUtil Operations, Recovery Operations etc.,

Ex

Prepare script for calculation Test in Application Flight Reservation
Option explicit Dim x,y,tot,i
For i = 1 to 5 step 1 Window("Flight Reservation").Activate

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
x  = Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText()

y  = Window("Flight Reservation").WinEdit("Price:").GetVisibleText() y=mid(y,2, len(y)-1)
tot = Window("Flight Reservation").WinEdit("Total:").GetVisibleText() tot=mid(tot,2, len(tot)-1)

If cdbl(tot)=cdbl(x) * cdbl(y) Then

reporter.ReportEvent micPass, "Calculation is correct", "Test is Pass" else

reporter.ReportEvent micFail, "Calculation is not correct", "Test is fail"

End If Next



Expected Activate Window

Enter User Name and Password Click Ok

If Next is enabled, User is authorized. If next is disabled, User is unauthorized.

Prepare Test Script for above expected. Option Explicit
Dim x Dialog(“Login”).Activate

Dialog(“Login”).WinEdit(“User Name”).Set “suresh” Dialog(“Login”).WinEdit(“User Name”).SetSecure “xxxxxx” Dialog(“Login”).WinButton(“Ok”).Click
X= Dialog(“Login”).WinButton(“Next”).GetROProperty("Enabled")
If x = “True” Then
reporter.ReportEvent micPass, "Next is Disabled", "Test is Pass"
else
reporter.ReportEvent micFail, "Next is Enabled", "Test is fail"
End If

(I have prepared the same in VB and tested on the same)
Option explicit
Dim x, y
VbWindow("frmLogin1").VbEdit("txtUserName").Set "suresh" VbWindow("frmLogin1").VbEdit("txtPassword").SetSecure "49422cd7dcd270949c6d92cc9fbcc1fcb1d0795d6e15"

x = VbWindow("frmLogin1").VbButton("Next").GetROProperty("Enabled") If x = "False" Then
reporter.ReportEvent micPass, "Next is Disabled", "Test is Pass" else

reporter.ReportEvent micFail, "Next is Enabled", "Test is fail"

End If VbWindow("frmLogin1").VbButton("OK").Click

y = VbWindow("frmLogin1").VbButton("Next").GetROProperty("Enabled")
If y = "True" Then
reporter.ReportEvent micPass, "Next is Enabled", "Test is Pass"
 else

reporter.ReportEvent micFail, "Next is Disabled", "Test is fail"

End If





Automation Testing                                                                                                                         37


Ex:
Expected Activate Window Enter Name as “Suresh” Click Display Check Output

Display the results in Quick Test Print Log



Script

Option explicit Dim x, Myarray
VbWindow("Sample").VbEdit("Test1").Set "Suresh" VbWindow("Sample").VbButton("Display").Click

x = VbWindow("Sample").VbEdit("Output").GetVisibleText() Myarray = split(x, " ")
If Myarray (3) = "Suresh" Then print "Test is Pass"
else
print "Test is fail"

End If

Output






Data Driven Testing

The repetition of the same test for more than one time with multiple test data is called Data Driven Testing. It is also known as Re-testing or iteration testingTesting. There are different ways.
1)    Dynamic Test Data Submission (Key Board)
2)    Through Data Table (Excel Sheet / Data Base)
3)    Through Flat File (Notepad)

1)    Dynamic Test Data Submission

Some times we are conducting data driven test depending on multiple test data through Key Board.



…………..

AUT
Key Board

Test Script

(Application


…………..

Under Test)



38                                                                                                                        Automation Testing



Ex

If you open record in “Flight Reservation” Application, Update Button is Disabled

Option explicit Dim i, x, y For i=1 to 3 Step 1
y=inputbox ("Enter Order No.") With Window("Flight Reservation")

.WinMenu("Menu").Select "File;Open Order..."
.Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
.Dialog("Open Order").WinEdit("Edit").Set y

.Dialog("Open Order").WinButton("OK").Click End with
x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled")
If x="False" Then
reporter.ReportEvent micPass, "Update is disabled", "Test is Pass"
 else
reporter.ReportEvent micFail, "Update is enabled", "Test is fail"

End If Next

Ex:
Expected
1)     Input 1 & Input 2 Values
2)     Click OK
3)     Check Results
4)     Display Results in Quick Test Print ID
5)     10 Times
Script

Option explicit Dim i, x, y, z For i=1 to 10 step 1
x=inputbox ("Enter Input1") y=inputbox ("Enter Input2") VbWindow("Multiply").VbEdit("Input1").Set x VbWindow("Multiply").VbEdit("Input2").Set y VbWindow("Multiply").VbButton("OK").Click

z = VbWindow("Multiply").VbEdit("Result").GetVisibleText() If cint(z) = cint(x) * cint (y) Then

print "Test is pass"
 else

Automation Testing                                                                                                                         39





print "Test is fail"

End If Next












2)  Through Data Table

Some times we are conducting Data Driven Test depending on multiple Test data through data Table. They are (2) ways such as
(i) Tester Test Own Data
(ii)Import Data from database or other files.
(i)               Tester Test Own Data
Test Script











AUT









Script

With Window("Flight Reservation")

.WinMenu("Menu").Select "File;Open Order..."

.Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

.Dialog("Open Order").WinEdit("Edit").Set datatable("test_data", dtGlobalSheet)

.Dialog("Open Order").WinButton("OK").Click End with




x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled")
If x="False" Then print "Update is disabled" else

print "Test is fail"
End If

Navigation

(1)
Start recording Æ Record required operation (Open Record) Æ Enhance test script like as shown in above program Æ Open data table Æ Double Click on Data table Column Name Æ Enter Column Name Æ Click Ok Æ Enter value in the data table Æ Tools menu Æ Click on Data Driver Æ Select value which you want to parameterize Æ Click Parameterize Æ Select option [(i) Step by step parameterization (ii) Parameterize all] Æ Click Next Æ Click on Parameter Option Æ Select Data table column Name Æ click Ok Æ Click Finish Æ Click Ok Æ Click Run Æ Analyze results manually.
(2)
Record required operation Æ Enhance Test Script like as shown in the above program Æ Open Data Table Æ Double Click on Data table Column Name Æ enter Column Name Æ click Ok Æ Enter values in Data Table Æ Replace input values in the script with below statement.

Data table (“Parameter Name”, dtGlobalSheet / dtLocalSheet) (Data table column Name
Or
Data table (parameter Id, Sheet ID)

(ii)     Import Data from database or other files. (Before execution)







Design Time

Data table

2

Run the script








datatable.GetSheetCount
 msgbox datatable.GetSheetCount

datatable.AddSheet (“Sheet_Name”) datatable.AddSheet (“input”)
Navigation
Record required Operation Æ Open Data table       Æ Right Click on Data table

Æ Sheet Æ Import Æ From db Æ Select specific SQL Statement Manually Æ Select Maximum number of rows if required Æ Next Æ Click on Create to Select DSN Æ Machine data Source Æ Select DSN Æ Ok Æ In SQL Statement (Your specific statement Ex.: select * from Orders) Æ Finish Æ Replace Input value in the script with below statement Æ Run Æ Analyze Results manually.

Datatable(Parameter ID, Sheet ID)

Difference between Design Time Data Table & Run Time Data Table


Design time Data Table

Run Time Data Table
1)
It  is  viewed  in  the  QTP  Main
1)
It  is  viewed  in  the  QTP  Test

Test.

Results.
2)
It  is  created  prior  to  the  test
2)
It is created in Test Results after

execution.

test execution.
3)
It  represents  data  from  external
3)
It  represents  a  live  version  of

sources.

design Time Data table.

Data Table Methods

(1)Add Sheet:
We  can  use  this  method  to  “add”  one  new  sheet  to  the  run  time

data table.

Syntax:
Ex:

(2)Delete Sheet:

We can use this method to “delete” one specified sheet from the Run Time Data table.
Syntax: datatable.DeleteSheet (Sheet_ID) Ex: datatable.DeleteSheet (3)

(3)GetSheetCount

We can use this method to count number of sheets in the run time data table.
Syntax: Ex:












42                                                                                                                        Automation Testing


(4)     GetRowCount
We can use this method to count number of rows in the 1st sheet

(longest column) of the Run time data table.






Output

Syntax: datatable.GetRowCount
Ex: msgbox datatable.GetRowCount

(5)     GetSheet

We can use this method to return a specified sheet from the Run Time data table.
Syntax: datatable.GetSheet(SheetID)
Ex: msgbox datatable. GetSheet(1).GetRowCount

(6)     Value

We can use this method to set or get value of cell in the specified parameter and the current row of the Rum time data table.
To set data
Syntax: datatable.Value(Parameter_Name, Sheet_Name) = Value / variable Or

datatable(Parameter_Name, Sheet_Name) = Value / variable

To get data

Syntax: Variable = datatable.Value(Parameter_Name, Sheet_Name) Or

Variable = datatable(Parameter_Name, Sheet_Name)

Ex:

Option explicit Dim a, b, c
a=datatable.Value (1,1) b=datatable.Value (2,1) c=cint(a)+cint(b) datatable.Value (3,1) = c

Note: Default property of Datatable is value




Automation Testing                                                                                                                         43




(7)     SetCurrentRow

We can use this method to take a specified row as current row in the Run Time Datatable (By default it is 1st Row of 1st Sheet)

Syntax:       datatable.SetCurrentRow(Row_Number)

Ex: s="sairam"

datatable.SetCurrentRow (3) datatable.Value (1,1) = s
(8)     SetNextRow
We can use this method to take the row after the current Row as New Current Row in the Run time data table.
Syntax:       datatable.SetNextRow

Ex: s="sairam"

datatable.SetCurrentRow (3) datatable.SetNextRow datatable.Value (1,1) = s

(9)     SetPrevRow

We can use this method to take the row before the current Row as New Current Row in the Run time data table.
Syntax:       datatable.SetPrevRow

Ex: s="sairam"

datatable.SetCurrentRow (3) datatable.SetPrevRow datatable.Value (1,1) = s

(10)   Import

We can use this method to import Microsoft Excel File to the Runtime Data Table (Including all sheets)
Syntax:       datatable.Import “Path of File”

Ex: datatable.Import “F:\Inputdata.xls”

a.    ImportSheet

We can use this method to import a specified sheet of Microsoft

Excel Sheet to the Runtime Data table.
 Syntax: datatable.ImportSheet “Path of File”, “Source Sheet”, “Destination Sheet”

Ex: datatable.ImportSheet “F:\Inputdata.xls”,3,1



(11)   Export

We can use this method to export a copy of Run Time Data table to another location (Including all sheets)

Syntax:       datatable.Export “Path of File”

Ex: datatable.Export “F:\Outputdata.xls”

a.     ExportSheet

We  can  use  this  method  to  export  a  copy  specified  sheet  of  Run

Time Data table to the existing or new Excel File. Syntax: datatable.ExportSheet “Path of File”, “Sheet Name / Source Sheet”

Ex: datatable.ExportSheet “F:\Outputdata.xls”, 2


Ex: Prepare script for Update operation in Flight Reservation Application by taking data from Excel file during Runtime.

Option explicit

Dim rowcount, i, ordnum, strname, x,y datatable.AddSheet ("data")
datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\QTP\sample.xls", 1, "data"

rowcount = datatable.GetSheet ("data").GetRowCount With Window("Flight Reservation").Dialog("Open Order")
For i=1 to rowcount step 1 datatable.SetCurrentRow (i) ordnum=datatable.Value (1, "data") strname = datatable.Value (2, "data")

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

.WinCheckBox("Order No.").Set "ON"

.WinEdit("Edit").Set ordnum

.WinButton("OK").Click

Window("Flight Reservation").WinEdit("Name:").Set strname

Window("Flight Reservation").WinButton("Update Order").Click

wait (10)

x    =    Window("Flight    Reservation").ActiveX("Threed    Panel    Control").

GetVisibleText()

y="Update Done..."

If strcomp(x,y,1) = 0 Then

Automation Testing
45









reporter.ReportEvent micPass,"Update done", "Test is pass"



else


End If
reporter.ReportEvent micFail, "Update fail", "Test is fail"





Next


End With





Database Connection:

(i)
Connection



We  can  use  this  class  to  establish  a  connection  to  the  specified


database during Runtime

Syntax:

Set ConnectionObject = CreateObject (“ADODB.Connection”) conobj.open “Provider=Provider Name”

Ex:

MS Access
conobj.open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Path of Database”

SQL Server

conobj.open “Provider=sqloledb.1; Server=IP Address; uid=Username; pwd=xxx; database=Path of database”

Oracle

conobj.open      “Provider=oraoledb.1;      Server=xxx;      userID=Username(scott);

password=xxx(tiger)”

Note:
To get provider Name
Open Notepad Æ Save empty file with .udl Æ Open that udl File Æ Provider Tab Æ Select Provider Æ Next Æ Select Database Æ Test Connection Æ Click Ok Æ Click Ok Æ Open the same file in Notepad
(ii)     Command

We can use this class to execute specified DML Statements (Insert, Update, Delete) on connected database.
Code:
Set comobj=createObject (“ADODB.Command”) Comobj.ActiveConnection = conobj Comobj.CommandText = “SQL Statement” Comobj.Execute






(iii)
Recordset



We  can  use  this  class  to  execute  specified  select  statement  on

Code:
connected database and retrieve the results.





Set rsobj = createObject (“ADODB.recordset”)


Rsobj.open “SQL Statement”, conobj









Ex



Option explicit


Dim comobj, conobj


Set conobj=createobject("ADODB.Connection")


conobj.open  "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents

and Settings\Sai Sarvani\Desktop\sample.mdb" Set comobj=createobject ("ADODB.Command") comobj.activeconnection = conobj

comobj.commandtext = "Insert into emp values ('Appa Rao', 101, 10000)" comobj.execute

conobj.close
Set comobj = nothing Set conobj = nothing

(iv)    Nothing

Noting is a keyword in VB Script, which is used to disassociate an object variable from the actual object.
Code
Set objectname = nothing

Ex:

How to set multiple records into database table by taking the data from Excel file




Option explicit

Dim comobj,conobj,rcount,i,ename,eno,esal

Set conobj=createobject("ADODB.Connection")

conobj.open "PRovider=Microsoft.jet.oledb.4.0;

data Source = C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb"

Set comobj=createobject("ADODB.Command")

comobj.activeconnection=conobj

datatable.AddSheet ("data")

datatable.ImportSheet    "C:\Documents    and    Settings\Sai    Sarvani\Desktop\

testdata.xls",1,"data"


47


rcount=datatable.GetSheet("data").getrowcount For i=1 to rcount step 1
datatable.SetCurrentRow (i) ename=datatable.Value (1, "data") eno=datatable.Value (2, "data") esal=datatable.Value (3, "data")

comobj.commandtext = "insert into emp values ('"&ename&"', "&eno&", "&esal&")"

comobj.execute

Next conobj.close

Set conobj = nothing Set comobj=nothing

Ex:
How to get data from database table?

Option explicit Dim conobj,rsobj,username,password Set conobj=createobject("ADODB.connection") conobj.open "PRovider=Microsoft.jet.oledb.4.0;

data Source = C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb"
 Set rsobj=Createobject("ADODB.recordset")
rsobj.open "select * from login", conobj rsobj.movefirst
While not rsobj.eof username=rsobj("uid") password=rsobj("pwd")
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe" Dialog("Login").WinEdit("Agent Name:").Set username
 Dialog("Login").WinEdit("Password:").SetSecure crypt.Encrypt (password) Dialog("Login").WinButton("OK").Click

If window("Flight Reservation").Exist Then
reporter.ReportEvent micPass, "Login success", "Test is Pass" Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
else

reporter.ReportEvent micFail, "Login Fail", "Test is fail" Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click Dialog("Login").WinButton("Cancel").Click
End If rsobj.movenext
Wend

rsobj.close conobj.close
Set rsobj=nothing
Set conobj=nothing

Ex:

Database Testing

Option explicit

Dim con, con1, rs, rs1, DOF, FF, FT, PN, NOTC,TOF,x Set con=createobject("ADODB.connection") con.open "DSN=QT_Flight32"
Set rs=createobject("ADODB.recordset") Set con1=createobject("ADODB.connection")

con1.open "Provider=microsoft.jet.oledb.4.0; data source=C:\Documents and Settings\Sai Sarvani\Desktop\sample.mdb" Set rs1=createobject("ADODB.recordset")
rs1.open "select * from data",con1 rs1.movefirst
While not rs1.eof DOF=rs1("dof") FF=rs1("flyfrom") FT=rs1("flyto") PN=rs1("pname") NOTC=rs1("not") TOF=rs1("tof")

Window("Flight Reservation").WinMenu("Menu").Select "File;New Order" Window("Flight Reservation").ActiveX("MaskEdBox").Type DOF Window("Flight Reservation").WinComboBox("Fly From:").Select FF Window("Flight Reservation").WinComboBox("Fly To:").Select FT Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select TOF

Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Set PN Window("Flight Reservation").WinEdit("Tickets:").Set NOTC Window("Flight Reservation").WinButton("Insert Order").Click

wait(10)

x = Window("Flight Reservation").WinEdit("Order No:").GetVisibleText() rs.open"select * from orders where Order_Number="&x,con

If
rs("Customer_Name")=PN
and
trim(rs("Tickets_Ordered"))=trim(NOTC)
Then









reporter.ReportEvent micPass, "Data inserted", "Test is passed" else
reporter.ReportEvent micFail, "Data is not incered", "Test is fail"

End If rs1.movenext rs.close wend rs1.close con1.close con.close

Set rs1=nothing Set rs=nothing Set con1=nothing Set con=nothing



3)                Through Flat File

Some times we are conducting data driven testing depending on multiple
test data from “Text” files.
To manipulate flat file content for testing we can prepare script like as below.
Set fso = createobject(“Scrpiting.filesystemobject”)
Set f=fso.opentextfile (“Path of text file”, mode[Read-1, Write-2, Append-8])
while f.atendoflile = false

s=f.readline
………..
………….

……….. .set s
…………
……………

Wend f.close

Ex

Option explicit Dim fso,f,s,x

Set fso=createobject("Scripting.filesystemobject")

Set f=fso.opentextfile ("C:\Documents and Settings\Sai Sarvani\Desktop\ input.txt",1)

f.skipline

With Window("Flight Reservation").Dialog("Open Order")
While f.atendofline = false
s=f.readline

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
.WinCheckBox("Order No.").Set "ON"
.WinEdit("Edit").Set s

.WinButton("OK").Click

x = Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled")

If x="False" Then
reporter.ReportEvent micPass, "Update is disabled", "Test is Pass" else
reporter.ReportEvent micFail, "Update is enabled", "Test is fail" End If
Wend End With f.close


GetItemsCount

We can use this method to count number of items in the combo box.
Code

Variable  =  Window("Window  Name").WinComboBox("Combo  Box  Name").

GetItemsCount()

Ex:

s = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount() msgbox s

GetItem

We can use this method to get a specified item from the Combo Box
Code

variable = Window("Window Name").WinComboBox("Combo Box Name"). GetItem(Item Number)

Ex:

s = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(4) msgbox s


GetContent

We can use this method to get content of the Combo Box.
Code
variable = Window("Window Name").WinComboBox("Combo Box Name"). GetContent()

Ex

s = Window("Flight Reservation").WinComboBox("Fly From:").GetContent() msgbox s


Ex:

How to count number of items in the Fly From Combo Box and how to display their name one by one.

s = Window("Flight Reservation").WinComboBox("Fly From:"). GetItemsCount()
msgbox s
For i=0 to n-1 step 1

y = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) msgbox y

Next

How to display FlyFrom Combo Box items one by one into Notepad

Option explicit Dim fso,s,x,n
Set fso=createobject("Scripting.filesystemobject")
Set s=fso.opentextfile ("C:\Documents and Settings\Sai Sarvani\Desktop\ sample.txt",2)
x = Window("Flight Reservation").WinComboBox("Fly From:"). GetItemsCount()

For i=0 to n-1 step 1

n = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) s.writeline n

next s.close

How to display Flyfrom Combo box items one by one into Runtime Data table and the same data table export to Excel Sheet datatable.AddSheet ("output").Addparameter "From", " "

n = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount()

For i=0 to n-1 step 1

x = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) datatable.SetCurrentRow (i+1)

datatable.Value ("From", "output") =x
 Next
datatable.ExportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\ output1.xls", "output"

If you select one item from Fly From Combo Box, that item should be disappeared in Fly To Combo Box

n = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount()

For i=0 to n-1 step 1

x   = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i) Window("Flight Reservation").WinComboBox("Fly From:").Select x
m   = Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount()
For j=0 to m-1 step 1
y  = Window("Flight Reservation").WinComboBox("Fly To:").GetItem(j)

If strcomp(x,y,0)<>0 Then
reporter.ReportEvent micPass,"Items are not same", "test is Pass"
 else
reporter.ReportEvent micFail,"Items are same", "Test is fail"
End If Next Next

How to count number of subfolders and files in a specified folder and how to display their names one by one? Prepare script for above expected?

Option explicit Dim fso,f,sf,n,g,ft,m,k
Set fso=createobject("Scripting.filesystemobject") Set f=fso.folder ("F:\XP")

Set sf=f.subfolders n=sf.count msgbox n
 For each g in sf

msgbox g.name
Next
Set ft=f.files m=ft.count msgbox m
 For each k in ft

msgbox k.name

Next



Synchronization Point

The time map between tool and application build. To give waiting time to the tool there are (3) ways such as
(i)               Synchronization Point
(ii)             Wait
(iii)          Increase timeout
(i)      Synchronization Point

We can use this option to give waiting time to the tool based on specific object property value.
Code
Window("Window Name").Object("Object Name").WaitProperty "Property Name", “Property Value”, Timeout in Milliseconds.
Navigation

Place the cursor in your required place of test script Æ Click on Start recording Æ Insert Menu Æ Synchronization Point Æ Show object with Hand Icon Æ Click Æ click Ok Æ Select property Name (Enable) Æ Enter Property Value (True) Æ Set timeout in Milliseconds Æ Click Ok Æ Stop Recording.

Note

1 Second = 1000 Milliseconds

(ii)     Wait

We can use this statement to give fixed waiting time to the tool.
Code

Wait (Time in seconds)
Ex: wait (10)

(iii)          Increase timeout

QTP maintain “20” Seconds as default object synchronization Time out.

That time out is not sufficient, then we will increase Timeout in settings.

Navigation

File Menu Æ Settings Æ Run Tab Æ Change Object Synchronization time out Æclick Ok.

Start Transaction & End Transaction

It is used to calculate the time taken to execute a block of statements or to estimate the speed of processing.
Syntax
Services.StartTransaction <"Transaction Name">

…………….

Statements
………..

Services.EndTransaction <"Transaction Name">



54                                                                                                                        Automation Testing


Navigation

Place the cursor in the required position Æ Insert Menu Æ Start Transaction Æ Enter Transaction Name Æ Click Ok Æ place the cursor at end position (or) where you want to stop transaction Æ Insert Menu Æ End Transaction Æ Click Ok Æ click run Æ Analyze results manually.

With

We can use this statement to decrease the length of the program.
Navigation

Record required Operation Æ Edit Menu Æ Advanced Æ Apply with to script (or) Ctrl + W (To remove with statement Ctrl + Shift + W)

Ex:

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

With Window("Flight Reservation").Dialog("Open Order")

.WinCheckBox("Order No.").Set "ON"

.WinEdit("Edit").Set s
.WinButton("OK").Click End with

Invoke Application

It invokes an executable application only.
Syntax

invokeapplication "Path of application"

SystemUtil

We can use this object to control applications and processors during Run session.
Syntax
SystemUtil.BlockInput

(Prevents keyboard & Mouse Input events from reaching the application)

CloseDescendentProcesses

Closes all processes opened by QuickTest

CloseProcessByHwnd

Closes a process that is the owner of a window with the specified handle.

CloseProcessById

Closes a process according to its Process ID (PID).







CloseProcessByName

Closes a process according to its name.

CloseProcessByWndTitle

Closes all processes that are owners of windows with the specified title.

Run

Runs a file or application.

UnblockInput

Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.


How to close a specified file

Ex:

x = Window("Solitaire").GetROProperty("Hwnd") systemutil.CloseProcessByHwnd (x)

Note
After every object . After every variable “ ”
How to invoke specific webpage through specific browser?

Set ie=createobject("Internetexplorer.application") ie.visible = true
ie.navigate "www.google.com"

How to close all the browsers at a time Navigation

Tools Menu Æ Options Æ Web Tab Æ Advanced Æ Select Browser cleanup under Run Time settings Æ Ok Æ Ok Æ Put any script Æ Run

How to close Popups during Run Time a=10

b=20 Set obj=createobject("wscript.shell")
 If b=a+10 Then

obj.popup "b is equal to a", 2 (Time in Seconds) else
obj.popup "b is not equal to a", 5

End If







How to count number of links in a specific webpage and how to display their names one by one.

Set x=description.Create x("micClass").value = "Links"

'set l = Browser("AXIN BANK").ChildObjects(x)

Set l = Browser("AXIN BANK").Page("AXIN BANK").).ChildObjects(x) n=x.count

For i=0 to n-1 step 1 y=x(i).getroproperty("text") msgbox y

Next

Spell Checks

Set mw=createobject("Word.application") mw.visible = true
 Set wl=description.Create wl("micClass").value="Link"

m = Browser("AXIN BANK").Page("AXIN BANK").ChildObject(wl) y=m.count
For i=0 to y-1 step 1 op=m(i).GetROProperty("Text") mw.wordbasic.filenew mw.wordbasic.insert str s=mw.activedocument.spellingerrors.count If s=0 Then

reporter.ReportEvent micPass,"No Mistakes were found","test is pass"
else

reporter.ReportEvent micFail,"Mistakes in"&str, "Test is fail"

End If mw.documents.close(false) Next

mw.quit




















Automation Object Model

To pre-configure QTP Test settings, we can use Automation Object Model

Open Notepad prepare the script like as below and save the file with *.vbs extension

set qtp = Createobject("QuickTest.Application") qtp.visible = true

qtp.launch
qtp.activateview "expertview" qtp.showpanescreen "datatable", false qtp.showpanescreen "debugviewer", True qtp.showpanescreen "activescreen", True

qtp.open "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\test7" qtp.test.run

qtp.quit

Actions

Action means a group of meaningful statements or a set of meaningful operations.
They are (3) Types, such as
(i)      Non-reusable Action
An action can be called by the test with which it is stored and it can be called only once.
(ii)     Reusable Action
An action can be called multiple times by the test with which it is stored and by other tests.
(iii)    External Action
A reusable action becomes External Action when we call that action from one test to another test.

Call to New Action

We can use this option to call a new action.
Navigation

Insert Menu Æ Call to New Action Æ Enter Action Name [Optional] Æ Check Reusable Action or Uncheck Reusable Action Æ Click Ok.

How to Delete Action

To delete action we can follow below navigation.
Navigation:

Open Action which you want to delete Æ Edit Menu Æ Action Æ Delete Action Æ Click Ok



How to rename Action Navigation

Open Action which you want to rename Æ Edit Menu Æ Action Æ Rename Action (Shift + F2) Æ Enter name of the Action Æ Click Ok.

Call to Copy of Action

We can use this option to call a copy of action from the current test or from any other test.
Code:
RunAction “Copy of Action Name”, oneiteration
Navigation

Insert Menu Æ Click on Call to Copy Action Æ Select Test Æ Select Action Æ Click Ok
Note: If you call action using “Call to Copy of Action” option you can get action with Read and Write permission.
Call to Existing Action

We can use this option to call Reusable Action from the current test or from another test.
Note: If we call Reusable Action using “Call to Existing Action” option we can get action with Read Only permission.
Navigation

Insert Menu Æ Click on “Call to Existing Action” Æ Select test Æ Select Action Æ Click on Ok.
Syntax

RunAction “Action Name[Test Name]”, oneiteration

Call to Win Runner

We can use this option to call Win Runner Test or function to QTP Main
Test.
Navigation

Insert Menu Æ Call to Win Runner Æ Action Æ Browse Win Runner Test Path ÆClick Ok.

Split Action

We can use this option to divide one action into 2 Actions.
Navigation

Open Action which you want to divide into 2 Actions Æ Place the cursor at required position Æ Edit Menu Æ Action Æ Split Action Æ Enter meaningful Action Names with description Æ Select Option [Independent or each other or Nested] Æ Click Ok.

Automation Testing                                                                                                                         59








Case Study (Frame Work)




Test 1
Test 2
Test 3


Login

Insert
Update










Log in to App

Log in to App

Log in to App




Insert Order

Open Record



Logout




Logout

Update Record







Logout











Navigation

Record your required operations (Login; Open Record; Logout) Æ Save the Reusable Actions in Specified location Æ Take New test Æ Prepare the script for above scenarios using those reusable actions Æ Start Menu Æ Programs Æ QTP Æ Test Batch Runner Æ Batch Menu Æ Add [Ins] Æ Specify your required Tests Æ Click Run (F5).

Action Template

To create Action Template we can follow Navigation. Open Notepad Æ Enter your required information like as below. ‘Project Name:
‘Module Name: ‘Created By: ‘Created On:

‘*************************************************************** Save the file in dat Folder with file name as “actiontemplate.mst” Æ Take New test (when ever you are using new test the above information will be added in the top of the test as shown below.



Action Parameters

There are two types of Parameters (i) Input Parameter (ii) Output Parameter
Case 1:          How to pass data to the external action.

Test 1

RunAction “Action1[Test2]”.oneiteration “Nagesh”,“mercury”





Test 2

.setparameter (“uid”)

.setsecure crypt.encrypt (Parameter(“pwd”))


Navigation

Record Required operation Æ Replace constant values in Parameter Æ Edit Menu Æ Action Æ Action Properties Æ Parameters Tab Æ Add Parameter [Enter Input Parameter Name same as in script] Æ Ok Æ Save Action Æ New Test Æ Call that reusable Action using calling to existing action option Æ Pass values like as shown in the diagram.

Case 2:          How to pass data from one action to another action.

Action 1 Parameter (“a”) = 10
Action 2

.set parameter (“a”)

Navigation
Take Two Actions like as shown in the diagram in a same Test Æ Open 1st Action Æ Edit Menu Æ Actions Æ Action Properties Æ Parameters Tab Æ Add Output Parameter Name with Type (a, Any)Æ Click Ok Æ Open 2nd Action Æ Edit Menu Æ Actions Æ Action Properties Æ Parameters Tab Æ Add Input Parameter Name with type (a, Any) Æ Click Ok Æ Keyword View

Æ    Right Click on 1st Action (Output) Æ Action Call Properties Æ Parameter Values Tab Æ Enter variable in “Store In field” Æ Click Ok Æ Right Click on 2nd Action (Input) Æ Action Call properties Æ Parameter Values Tab Æ Enter variable in Store in field in input parameter Æ Click Ok Æ Expert View Æ Run

Æ   Analyze Results manually





Environment Variables

Environment Parameters especially useful for localization testing (If you want to test the application when the user interface strings are changing depending on selection of different languages)
Environment parameters can be used for testing the same application on different browsers.
Environment Variables are (2) Types such as (1) Built-in-variable (2) User defined variable.
(1)Built-in-variable
It represents the information about the Test and the system in which the test is running.

Ex: Environment.Value ("OS") Æ It will display Operating System Environment.Value ("OSVersion") Æ It will display operating system version Environment.Value ("LocalHostName") Æ It will display Local Host Name Environment.Value ("Test Name") Æ It will display Test Name

(2)User defined variable

There are (2) Types such as
(i)      Internal Variables
Internal Variables can be created in the Test and can be used in any Action of the same test.

Ex: struid=environment.Value ("uid")
strpwd=environment.Value ("pwd")

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\ samples\flight\app\flight4a.exe"
With Dialog("Login")
.Activate
.WinEdit("Agent Name:").Set struid
.WinEdit("Password:").SetSecure crypt.Encrypt (strpwd)

.WinButton("OK").Click End With

Navigation

Records your required operation Æ File Menu Æ Settings Æ Environment Tab Æ Select variable type as “User Defined” Æ Add Environment Name with Value Æ Click Ok Æ Click Ok Æ Replace constant values in the script with environment variables likes as shown in the above script Æ Click Run Æ Analyze results manually



(ii)     External Variables

External Variables will be present in the “.xml” file and we can associate this ‘xml’ file to the test to use those variables in any action of that test.
To create ‘xml’ file with required variables we can prepare script likes as below.

Open Notepad Æ Prepare script like as below Æ Save the file with ‘.xml’ extension.

<Environment> <Variable>
<Name>uid</Name> <Value>suresh</Value>

</Variable> <Variable>
<Name>pwd</Name> <Value>mercury</Value>
</Variable> </Environment>

How to load variables and values from external file before execution Navigation
File Menu Æ Settings Æ Environment Tab Æ Select Variable type as “User defined” Æ Select load variables and values from external file Æ Browse the file path Æ Click Ok.

How to load variables and values from external file during Runtime Code

Environment.LoadFromFile “Path of file”

Note:
Built in variables are Read Only variables.
Random Number

We can use this option to pass Random Data.
Syntax
…………

…………
………… .set RandomNumber (1,10)
…………

…………

Automation Testing                                                                                                                         63




Functions

User defined Functions

Like as programming language ‘VB Script’ is also allows you to create ‘User Defined Functions’ for repeatable operations.

To create User Defined Functions we can follow below syntax.

Public / Private Function Function_Name (Arguments)

…………
…………

Statements
…………
…………

End Function

Ex

Public function addition (x,y) z=x+y
addition = z End Function
'**************************************** a=10

b=20 c=addition (a,b) msgbox c

How to create Library File Navigation

Create required function for the required repeatable operations Æ Select the script Æ Copy the Script Æ Paste the script in Notepad Æ Save the file with “.vbs” extension

How to associate library file to Test before execution Navigation

File Menu Æ Settings Æ Resources Tab Æ Add Associated function library Æ Browse file path Æ Click Ok.

How to associate library file during Runtime Syntax

executefile “Path of file”






64                                                                                                                        Automation Testing


Case Study

Navigation

Record required operation as per scenario Æ Create functions for them Æ Take the script into Notepad Æ Save the file with ‘.vbs / .qfl’ extension Æ Resources Menu Æ Object Repository Æ File Menu Æ Export local objects Æ Save the file in specified location Æ Save Æ Take required Environment variable in ‘.xml’ file Æ New test Æ Associate all files like library file, environment variable file [File Menu Æ Settings Æ Resources Tab Æ Click on Add file Æ Browse that library file Æ Environment Tab Æ Select User Defined as variable type Æ Select load variables and values from external file Æ Browse File path

Æ     Click Ok] Repository file [Resources Menu Æ Associate Repositories Æ Click on Add file Æ Browse the Repository file path Æ Associate with action]

Æ   prepare the script using functions like as below.

Ex: How to associate all files before execution struid=environment.Value ("uid") strpwd=environment.Value ("pwd") res=login(struid,strpwd)

msgbox res res1=insert() msgbox res1 logout()


Ex 2: How to associate all files during Runtime

Option explicit Dim struid,strpwd,res,res1
executefile "C:\Documents and Settings\Sai Sarvani\Desktop\flightres.vbs" environment.LoadFromFile "C:\Documents and Settings\Sai Sarvani\Desktop\ QTP\environment.xml"
repositoriescollection.Add "C:\Documents and Settings\Sai Sarvani\Desktop\ QTP\objectrepository.tsr"

struid=environment.Value ("uid") strpwd=environment.Value ("pwd")
res=login(struid,strpwd) msgbox res

res1=insert() msgbox res1 logout()



Automation Testing                                                                                                                         65





flightres.vbs

Function login (struid,strpwd)
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\ samples\flight\app\flight4a.exe"

With Dialog("Login")
.WinEdit("Agent Name:").Set struid

.WinEdit("Password:").SetSecure crypt.Encrypt(strpwd)
.WinButton("OK").Click End With

If Window("Flight Reservation").Exist Then
 reporter.ReportEvent micPass,"Login Successful","Test is Pass"
 login = "Pass"

else
reporter.ReportEvent micFail,"Login Unsucessful","Test is fail"
login=”fail”

End If End Function

'****************************************************************
Function insert()

With Window("Flight Reservation")
.Activate

.WinMenu("Menu").Select "File;New Order"
.ActiveX("MaskEdBox").Type "090909"

.WinComboBox("Fly From:").Select "Denver"

.WinComboBox("Fly To:").Select "Frankfurt"
.WinButton("FLIGHT").Click

.Dialog("Flights Table").WinList("From").Select 3
.Dialog("Flights Table").WinButton("OK").Click

.WinEdit("Name:").Set "Suresh"
.WinEdit("Tickets:").Set "3"

.WinButton("Insert Order").Click End with
wait (10)

x = Window("Flight Reservation").ActiveX("Threed Panel Control").GetVisibleText() y="Insert Done..."

If strcomp(x,y,1)=0 Then

reporter.ReportEvent micPass,"Data inserted sucessfully","Test is Pass"
insert=”Pass”
else

reporter.ReportEvent micFail,"Data not inserted","Test is fail"
insert=”fail”

End If
EndFunction

'****************************************************************
Function logout()

Window("Flight Reservation").Activate Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
End Function

Debug

i)                   Pause
ii)                Step Into(F11)

iii)              Step Over (F10)

iv)              Step Out (Shift + F11)

v)                 Run to Step (Ctrl + F10)

vi)              Debug from Step

vii)            Add to Watch (Ctrl + T)

viii)         Insert / Remove Breakpoint (F9)

ix)              Enable / Disable Breakpoint (Ctrl + F9)

x)                 Clear all Breakpoint (Ctrl + Shift + F9)

xi)              Enable / Disable all Breakpoints






















i)         Step InTo (F11)

We can use this option to execute one line of statement, if the statement is function call or action call, then it will step into Function or Action.





ii)       Step Out (Shift + F11)

We can use this option to execute remaining statements in the function of Action from the position of pointer [ ]








L







Recovery Scenario Manager
To recover from unexpected events and errors that are occurred in the test
environment during run session, we can use Recovery Scenario Manager.
For good recovery, error must be known the occurrence is unknown.
There are (4) Types of events such as
(i) Application Crash
An open application fails during Test Run.

Navigation
Resources Menu 􀃆Recovery Scenario Manager 􀃆Click New 􀃆Click Next 􀃆
Select Application Crash as Trigger event 􀃆Next 􀃆Select selected executable
application 􀃆Next 􀃆Select Recovery Operation [Keyboard, Mouse Operation,
Close Application Process, function Call, Restart, Microsoft Windows] 􀃆Next 􀃆If
you want to check Add another operation else uncheck 􀃆Next 􀃆Next 􀃆Enter
Scenario Name 􀃆Next 􀃆Select Option 􀃆Finish 􀃆Close 􀃆Save the scenario in
specified location with “.qrs”
qrs stands for QuickTest Recovery Scenario.


 (ii) Popup Window.
To handle unwanted popups.
Navigation
Resources Menu 􀃆Recovery Scenario Manager 􀃆New 􀃆Next 􀃆Select “Popup
Window” as Trigger event 􀃆Next 􀃆Click on Hand Icon 􀃆Show unwanted
window with Hand icon 􀃆Next 􀃆Next 􀃆Select function call as Recovery
Operation 􀃆Next [Open Notepad 􀃆Save empty file with .vbs extension] 􀃆Browse
the .vbs fie path 􀃆Next 􀃆Uncheck Add another Recovery Operation 􀃆Next 􀃆
Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to
Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test
run, Stop the Test Run] 􀃆Next 􀃆Enter Scenario Name 􀃆Next 􀃆Select Option 􀃆
Finish 􀃆Save the scenario with “.qrs” 􀃆Record required Recovery Operation [Click
ok, Click Cancel] take the script into function 􀃆Save the library file 􀃆Click Run
(iii) Test Run Error.
A step in your test does not run successfully then Test Run Error
can be raised.
Navigation :
Resources Menu 􀃆Recovery Scenario Manager 􀃆New 􀃆Next 􀃆Select “Testrunerror
Window” as Trigger event 􀃆Next 􀃆select any error  o 􀃆􀃆Next 􀃆Next 􀃆Select function call as Recovery
Operation 􀃆Next [Open Notepad 􀃆Save empty file with .vbs extension] 􀃆Browse
the .vbs fie path 􀃆Next 􀃆Uncheck Add another Recovery Operation 􀃆Next 􀃆
Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to
Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test
run, Stop the Test Run] 􀃆Next 􀃆Enter Scenario Name 􀃆Next 􀃆Select Option 􀃆
Finish 􀃆Save the scenario with “.qrs” 􀃆Record required Recovery Operation [Click
ok, Click Cancel] take the script into function 􀃆Save the library file 􀃆Click Run



(iv) Object State.
The property values of an object in your application match
specified values. You can specify property values for each object in the
hierarchy.


Resources Menu 􀃆 Recovery Scenario Manager 􀃆 New 􀃆 Next 􀃆 Select “Object state
Window” as Trigger event 􀃆 Next 􀃆 Click on Hand Icon 􀃆 Show object with hand icon
 􀃆 Next 􀃆 Next->select object property with value (enabled ,false)->click next 􀃆 Select function call as Recovery
Operation 􀃆 Next [Open Notepad 􀃆 Save empty file with .vbs extension] 􀃆 Browse
the .vbs fie path 􀃆 Next 􀃆 Uncheck Add another Recovery Operation 􀃆 Next 􀃆
Select Post-Recovery Test Run Option [Repeat current step and continue, Proceed to
Next step, Proceed to Next Action, Proceed to next test iteration, Restart current test
run, Stop the Test Run] 􀃆 Next 􀃆 Enter Scenario Name 􀃆 Next 􀃆 Select Option 􀃆
Finish 􀃆 Save the scenario with “.qrs” 􀃆 Record required Recovery Operation [Click
ok, Click Cancel] take the script into function 􀃆 Save the library file 􀃆 Click Run

Exception handling or Error Handling:
On error resume next
With Dialog("Login")
.Activate
If err.number<>0 Then
reporter.ReportEvent micWarning,err.description, "Test is fail"
End If
.WinEdit("Agent Name:").Set "suresh"
If err.number<>0 Then
reporter.ReportEvent micWarning,err.description, "Test is fail"
End If
.WinEdit("Password:").SetSecure "4944761a08cd30679de0bf816fd529bc"
If err.number<>0 Then
reporter.ReportEvent micWarning,err.description, "Test is fail"
End If
.WinButton("OK").Click
End With


AUTOMATION FRAMEWORK
Framework means a set of concepts, assumptions and practices support fro
Automated Software testing.
There are (4) Types of frameworks, such as
(i) Liner Framework
(ii) Modular Framework
(iii) Keyword driven Framework
(iv) Hybrid Framework







(i) Liner Framework
In this Framework we are preparing script for scenarios using Record
and Playback method
Navigation
Record required operation 􀃆 Enhance Test Script as per Scenario 􀃆 Save test 􀃆 take
the help of Test Batch Runner Tool to execute group of tests sequentially


(ii) Modular Framework
In this framework we are preparing script for scenarios using Reusable
components / Reusable Actions.
Navigation
Record required repeatable operations 􀃆 Save them in a specific location as reusable
action 􀃆 Prepare script for scenarios using those reusable actions 􀃆 Save them 􀃆
Take the help of Test Batch Runner Tool to execute group of tests sequentially.

(iii) Keyword driven Framework (Important)
In this framework we are preparing script for scenario using functions
and driven the script with keywords.







Navigation
Record required operation 􀃆 Create functions for them 􀃆 Take the script into
Notepad 􀃆 Save the file in corresponding location with (.vbs) extension 􀃆 Open
Object Repository 􀃆 File Menu 􀃆 Export Local Objects 􀃆 Save the file in
corresponding location 􀃆 File Menu 􀃆 Settings 􀃆 Environment Tab 􀃆 Select
variable type as ‘User-defined’ 􀃆 Take required variable with values 􀃆 Export 􀃆
Save the file in corresponding location 􀃆 Take required recovery scenarios 􀃆 Save
the file in corresponding Location 􀃆 Open Excel File 􀃆 Enter Data in Excel File like
as below.































􀃆 Save the Excel File in specified location 􀃆 Open New Test 􀃆 Associate all files
[.vbs, .xml, .qrs, .tsr] [File Menu 􀃆 Settings 􀃆 Environment Tab 􀃆 Variable type as
User Defined] 􀃆 Select load variables and values from external file 􀃆 Browse the
file path 􀃆 Resources Tab 􀃆 Add Resources file 􀃆 Browse library file path 􀃆
Recovery Tab 􀃆 Add Recovery File 􀃆 Browse Recovery File path 􀃆 Add Scenario
􀃆 Click Ok 􀃆 Resources Menu 􀃆 Associate Repositories 􀃆 Click on “+” to add
repository file 􀃆 Select action to be associated Action 􀃆 click Ok 􀃆 prepare driver
script as below.
Ex:
Datatable.addsheet(“module”)
datatable.AddSheet ("testcase")
datatable.AddSheet ("teststeps")
datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword
FW\data.xls",1,"module"

datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword
FW\data.xls",2,"testcase"
datatable.ImportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword
FW\data.xls",3,"teststeps"
mcount=datatable.GetSheet ("module").GetRowCount
For i=1 to mcount step 1
datatable.SetCurrentRow (i)
If mexe="Y" Then
moduleid=datatable.Value (1,"module")
tcount=datatable.GetSheet ("testcase").getrowcount
For j=1 to tcount step 1
datatable.SetCurrentRow (j)
moduleid1=datatable.Value (4,"testcase")
tcexe=datatable.Value (3,"testcase")
If moduleid=moduleid1 and tcexe="Y" Then
tcid=datatable.Value (1,"testcase")
tscount=datatable.GetSheet ("teststeps").getrowcount

For k=1 to tscount step 1
datatable.SetCurrentRow (k)
tcid1=datatable.Value (6,"teststeps")
If tcid=tcid1 Then
keyword=datatable.Value (3,"teststeps")
Select Case keyword
Case "li"
struid=environment.Value ("uid")
strpwd=environment.Value ("pwd")
res=login(struid,strpwd)
datatable.Value (5,"teststeps") = res
Case "lo"
res=logout()
Case "ins"
res=insert()
datatable.Value (5,"teststeps")=res
Case "or"
order=environment.Value ("Order")
res=openrec(order)
datatable.Value (5,"teststeps") = res
Case "up"
strname=environment.Value ("name")
res=update(strname)
datatable.Value (5,"teststeps") = res
End Select
End If
Next
End If
Next
End If
Next
datatable.ExportSheet "C:\Documents and Settings\Sai Sarvani\Desktop\Keyword
FW\result.xls","teststeps"
(iv) Hybrid Framework
It is a combination of 2 or more frameworks.





 

 

 

 

 

Whats New In QTP 9.5

·  Maintenance Run Mode :

Whenever object properties are changed after a new build then run the script in maitenance run mode to update object repository according to changes  during run time

 

·  Process Guidance :

This is little more than more accessible help files. Maybe this is good for when you are first learning to record a test, but it doesn’t seem to add much utility.
·  Flow Pane

·  Available Keywords Pane

All Test Objects and functions in one handy location.Rapid test development with drag & drop.Object repository now also supports drag & drop

·  Resources Pane :

All resources associated with the test. You can see all your library file in this pane

·  Missing Resources Pane
·  Relative Path Helper
·  Improved Bitmap Checkpoint
·  Web Extensibility :
1.Anyone can add support for new web controls
2.Rapid development in JavaScript
3.Solid infrastructure supplied by the Web add-in
4.Extensibility objects are first class citizens
 5.Built-in toolkit: ASPAjax
·  Tabbed browsing :
Tabs identified as separate browsers.Same test compatible with tabbed and non tabbed browsers.

·  New Technologies :
1.PowerBuilder
2. Oracle − Forms 10 −Apps 12
3.StingRay Objective Grid 10, 114. PeopleSoft 9.0•
4.New Terminal Emulator versions
5.NET 3.5 (beta)
·  New environments  :
1.Windows Vista 64 bit
2. Eclipse 3.2, 3.3
3.Record on SWT
4. Firefox 3.0
5.Netscape 9

 

 

Script for practice if u interested

Remove Attachment from QC Through QTP

‘The following function will Remove the specified attachment  from the current test of QC when  the file name provided
Function RemoveQCAttachements(NameOfTheFile)
var_count= QCUtil.CurrentTest.Attachments.NewList(”").count
For i= 1 to var_count

 If   QCUtil.CurrentTest.Attachments.NewList(”").Item(2).Name =NameOfTheFile Then
         AttachmentID = QCUtil.CurrentTest.Attachments.NewList(”").Item(1).ID
   QCUtil.CurrentTest.Attachments.RemoveItem(AttachmentID)
 Else
     Reporter.ReportEvent micFail,”Please provide the valid filename with extention”,”Please provide the valid filename with extention”
 End If

Next
End Function

NameOfTheFile=”abc.vbs” ‘Provide the file name with extension
call RemoveQCAttachements(NameOfTheFile)

Copy an excel sheet to another excel

Following is the code to copy the conntents of a sheet in one excel to another excel sheet
Set objExcel = CreateObject(”Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(”C:\Documents and Settings\mohan.kakarla\Desktop\1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(”C:\Documents and Settings\mohan.kakarla\Desktop\2.xls”)
objWorkbook1.Worksheets(”Sheet1″).UsedRange.Copy
objWorkbook2.Worksheets(”Sheet1″).Range(”A1″).PasteSpecial Paste =xlValues
objWorkbook1.save
objWorkbook2.save
objWorkbook1.close
objWorkbook2.close
set objExcel=nothing

Function UpLoadAttachmentToQC(FilePath)
Set ObjCurrentTest = QCUtil.CurrentTest.Attachments
Set ObjAttch = ObjCurrentTest.AddItem(Null)
ObjAttch.FileName = FilePath
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh

End Function
FilePath=”C:\abc.vbs”
Call UpLoadAttachmentToQC(FilePath)

Search for a particular value in Excel

Set appExcel = CreateObject(”Excel.Application”)
appExcel.visible=true
 Set objWorkBook = appExcel.Workbooks.Open (filepath)’opens the sheet

 Set objSheet = appExcel.Sheets(”Sheet1″)’ To select particular sheet
With objSheet.UsedRange ‘ select the used range in particular sheet
    Set c = .Find (”nn”)’ data to find
For each c in objSheet.UsedRange’ Loop through the used range
 If c=”nn” then’ compare with the expected data
            c.Interior.ColorIndex = 40′ make the gary color if it finds the data
End If
            Set c = .FindNext(c)’ next search
     
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing


                                      PREPARED BY
                                               
SURESH BUGATA



Is there any spelling mistakes please ignore?

1 comment:

  1. HiAdmin,
    I go through your blog and it’s really awesome. Keep updating your site with such useful post. Also include Rss feed of your blog
    Loadrunner Training
    Loadrunner course in Chennai

    ReplyDelete