81

QTP Unplugged 2nd Edition Updates eBook

Embed Size (px)

DESCRIPTION

QuickTest Professional Unplugged, the first book written by author Tarun Lalwani and the first ever book on QTP as well, has already turned out a bestseller since its publication in 2009. Tarun Lalwani has won the Best Automation Book award in 2nd ATI Automation honors for the sameThis book is good for those starting out a career in Testing Automation or even for those with few years of QTP experience. It is the culmination of 3 years of research and effort in this field.The book gives a pragmatic view of using QTP in various situations. And is recommended for those aspiring to be experts or advanced users of QTPQTP Unplugged 2nd Edition comes with all the updates till QTP 11 in a new chapter and few minor fixes in the code. The new chapter covers many features that got added over the previous version of QTP. The chapter also discusses the Object Repository feature in details which had seen a major change from QTP 8.X to QTP 9Quotes from the Reviewers“I find this to be a very pragmatic, hand's on book for those who want to extend their QTP skills beyond basic expert view programming. This book is written by a QTP master for those who wish to eventually become masters themselves.” – Terry“Tarun Lalwani has singlehandedly helped thousands of people to expand their knowledge of QuickTest Professional. Here is a book the automated testing community has been crying-out for. This book will help QTP practitioners, from beginner to expert. I have used QTP from V6.0 and during the review I learnt something from every chapter.” – Mark

Citation preview

Page 1: QTP Unplugged 2nd Edition Updates eBook
Page 2: QTP Unplugged 2nd Edition Updates eBook

QuickTest ProfessionalUnplugged

SECOND EDITION

Page 3: QTP Unplugged 2nd Edition Updates eBook

QuickTest  Professional  Unplugged

By  Tarun  Lalwani

Editor:  Siddharth  N  Kanoujia

Technical  Editor:  Terry  Howarth

Reviewer:  Mark  Smith  and  Terry  Howarth

ISBN:  978-­0-­9836759-­1-­4

Printing  History:

First  Edition:  May  2009  (ISBN:  978-­0-­5780257-­9-­7)

Second  Edition:  September  2011

No  part  of  this  publication  may  be  reproduced,  stored  in  a  retrieval  system  or  transmitted  in  any  form  or  by  any  means,  electronic,  mechanical,  photocopying,  recording,  scanning  or  otherwise  without  either  the  prior  written  permission  of  the  Author,  or  authorization  through  payment  of  the  appropriate  per-­copy  fee  to  the  Author.  For  permission  please  contact  author  at  KnowledgeInbox.com/contact-­us.

author  or  the  publisher  by  including  the  below  mentioned  reference‘Source code taken from “QuickTest Professional Unplugged” By Tarun Lalwani

‘The link for downloads is KnowledgeInbox.com/demos/QTPUnplugged_SourceCodes.zip.

‘Website: KnowledgeInbox.com/books/quicktest-­professional-­unplugged

This  document  also  contains  registered  trademarks,  trademarks  and  service  marks  that  are  owned  by  their  respective  companies  or  organizations.  The  Publisher  and  the  author  disclaim  any  responsibility  for  specifying  which  marks  are  owned  by  which  companies  or  organizations.

Copyright  (2008)  Mercury  Interactive  (Israel)  Ltd.  Reproduced  with  permission

LIMIT  OF  LIABILITY/DISCLAIMER  OF  WARRANTY:  THE  PUBLISHER  AND  THE  AUTHOR  MAKE   NO   REPRESENTATIONS   OR  WARRANTIES  WITH   RESPECT   TO   THE  ACCURACY  OR  COMPLETENESS  OF  THE  CONTENTS  OF  THIS  WORK  AND  SPECIFICALLY  DISCLAIM  ALL   WARRANTIES,   INCLUDING   WITHOUT   LIMITATION   WARRANTIES   OF   FITNESS  FOR  A   PARTICULAR   PURPOSE.  NO  WARRANTY  MAY  BE  CREATED  OR  EXTENDED  BY  SALES   OR   PROMOTIONAL   MATERIALS.   THE   ADVICE   AND   STRATEGIES   CONTAINED  HEREIN  MAY  NOT  BE   SUITABLE   FOR   EVERY   SITUATION.   THIS  WORK   IS   SOLD  WITH  THE  UNDERSTANDING  THAT  THE  PUBLISHER  IS  NOT  ENGAGED  IN  RENDERING  LEGAL,  ACCOUNTING,   OR   OTHER   PROFESSIONAL   SERVICES.   IF   PROFESSIONAL  ASSISTANCE  IS  REQUIRED,  THE  SERVICES  OF  A  COMPETENT  PROFESSIONAL  PERSON  SHOULD  BE  SOUGHT.  NEITHER  THE  PUBLISHER  NOR  THE  AUTHOR  SHALL  BE  LIABLE  FOR  DAMAGES  ARISING  HEREFROM.  THE  FACT  THAT  AN  ORGANIZATION  OR  WEBSITE  IS  REFERRED  TO  IN  THIS  WORK  AS  A  CITATION  AND/OR  A  POTENTIAL  SOURCE  OF  FURTHER  INFORMATION  DOES  NOT  MEAN  THAT  THE  AUTHOR  OR  THE  PUBLISHER  ENDORSES  THE  INFORMATION  THE   ORGANIZATION   OR   WEBSITE   MAY   PROVIDE   OR   RECOMMENDATIONS   IT   MAY  MAKE.  FURTHER,  READERS  SHOULD  BE  AWARE  THAT  INTERNET  WEBSITES  LISTED  IN  THIS  WORK  MAY  HAVE  CHANGED  OR  DISAPPEARED  BETWEEN  WHEN  THIS  WORK  WAS  WRITTEN  AND  WHEN  IT  IS  READ.

Page 4: QTP Unplugged 2nd Edition Updates eBook

Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiiiWho  This  Book  Is  For    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . xivWhat’s  New  in  the  Second  Edition    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . xivSource  Code  in  the  Book .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . xivFeedback  and  Queries    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . xivOrdering  this  Book.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . xiv

Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvQuotes  From  Reviewers.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .xv

1. Introduction (Updated) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1What  is  Test  Automation?    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1When  Should  Test  Automation  Be  Used?    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1When  Should  Test  Automation  Be    Avoided?    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1

The  Automated  Testing  Process.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .2What  is  HP  QuickTest  Professional  (QTP)    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .3Getting  Started  with  QTP.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .4Downloading  QTP  from  HP  website .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .4Installing  QTP    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .5

QTP  Licensing  Model    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .8Seat  License .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .8Floating  License.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .9

2. Using QTP Help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Contents  Tab    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .14Properties  returned  by  the  GetROProperty  Function.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .14Methods  provided  by  a  Test  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .14

Index  Tab    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .15Search  Tab    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .16

Page 5: QTP Unplugged 2nd Edition Updates eBook

3. Object Repository (OR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19How  objects  are  added  to  the  OR    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .20Test  and  Run-­time  Objects.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .22TO  Properties .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .22Object  Repository  Modes    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .24Per-­Action  versus  Shared  Object  Repository.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .24The  Object  Spy    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .25

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .27    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .28

Object  Repository  Shortcomings      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .294. DataTables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Design  and  run-­time  data  table    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .35Design  time  data  table  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .35Run-­time  data  table   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .35

When  to  use  the  global  or  a  local  data  table    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .35Setting  data  table  iterations    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .36Data  table  object  model .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .38Data  table  formatting .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .38

5. Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Input  and  Output  Parameters .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .43Types  of  Actions    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .46Inserting  Calls  to  Actions.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .46Insert  Call  to  New…    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .47Insert  Call  to  Existing…    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .48Insert  Call  to  Copy….  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .49

6. QTP Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Types  of  Environment  variables    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .51Environment  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .52

7. Utility Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61The  Crypt  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .61The  OptionalStep  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .62The  PathFinder  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .62The  RandomNumber  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .63The  Setting  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .63The  WebUtil  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .65The  SystemUtil  Object.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .65The  RegisterUserFunc  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .66

8. Checkpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Types  of  checkpoints    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .69Problems  with  QTP  built-­in  checkpoints .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .70Alternatives  to  QTP  checkpoints .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .71

Page 6: QTP Unplugged 2nd Edition Updates eBook

Updating  Checkpoints  at  run-­time .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .719. Library Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Associating  a  Library  globally  with  a  Test    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .75Dynamically  Loading  libraries  locally  at  run-­time    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .76Dynamically  Loading  libraries  globally  at  run-­time    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .76Understanding  Execution  Scope    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .78Applicability  of  Option  Explicit   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .79Executing  code  in  Local  scope  from  within  Global  Scope    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .79

10. Descriptive Programming (DP). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .83

Implicit  Properties    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .84When  to  use  Descriptive  Programming .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .84Descriptive  Programming  Syntax    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .84Using  description  objects.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .84

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .86Using  Description  Strings    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .86Enumerating  ChildObjects.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .86Converting  an  OR-­based  script  to  a  DP-­based  script.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .87Using  a  VBScript  DP  object  repository .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .89

   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .90Working  with  Multiple  Browser    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .92

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .93    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .93

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .9311. Debugging in QTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .97Using  Breakpoints    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .98Working  with  the  Watch  Expression  Tab.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .98Working  with  the  Variables  Tab      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .99Working  with  the  Command  Tab      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .100

12. Recovery Scenarios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103When  not  to  use  recovery  scenarios?.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .103Situations  in  which  a  Recovery  Scenario  won’t  work .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .107Recovery  Scenario  for  IE  Authentication  window    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .109Default  Recovery  Scenarios.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .110The  Recovery  object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .111Recovery  Function  Calls    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .111Error  Handling .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .113

13. Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Regular  Expression  Characters    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .118When  to  use  Regular  Expressions  in  QTP.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .121

Page 7: QTP Unplugged 2nd Edition Updates eBook

Testing  a  Regular  Expression  Using  Code.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .123Using  a  Regular  Expression  to  Select  a  WebList  or  WebRadioGroup  Value    .  .  .  .  .  .124Extracting  Information  Using  a  Regular  Expression .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .124Replacing  Data  from  a  String  Using  a  Regular  Expression.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .125

14. VBScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Strings    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .129Conversion  function.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .137Date  and  Time  functions    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .138Misc  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .141TypeName    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .141VarType    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .141GetRef    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .141CreateObject    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .142GetObject .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .142

Working  with  Arrays    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .148Fixed  length  arrays.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .148Dynamic  Arrays .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .148

Execute  Statement    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .149Eval  function    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .150Optional  arguments  in  VBScript    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .150

15. Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157Synchronization  Points   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1571st  Method  –  Using  the  Sync  method    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1572nd  Method  –  Using  the  Wait  statement    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .1583rd  Method  –  WaitProperty  method.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .158

Checking  Object  Existence    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .158Browser  Vs  Page  Sync.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .159

Events.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .159Replay  Options.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .161

16. Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Filtering  Steps  in  a  Report .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .166Reporting  Custom  Steps    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .167Inserting  Files  in  Test  Results    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .167Inserting  Snapshots  in  Test  Results    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .168Converting  XML  Results  to  HTML.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .170

 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .170The  QTP  Reporter  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .171Accessing  Test  Results  at  the  end    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .173

17. Working with APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177Extern  object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .177

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .177

Page 8: QTP Unplugged 2nd Edition Updates eBook

   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .178QTP  API  Limitation .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .182API  using  COM  Objects  in  VB6 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .182

Running  API  using  Excel.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .185Dynamically  generating  an  Excel  Macro.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .187Working  with  Modal  dialog  boxes.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .190

18. QTP Automation Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195QTP  Automation  Object  Model  (AOM)    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .195Passing  arguments  to  Test  Cases    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .196

19. HTML DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201When  to  use  the  HTML  DOM.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .201When  not  to  use  the  HTML  DOM.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .202HTML  DOM  Objects.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .202HTML  Node.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .202The  Document  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .203The  HTML  Element  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .203The  HTML  Element  Collection .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .203Getting  the  Web  page  Element  using  the  DOM.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .204

Other  HTML  Elements    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .205Converting  a  DOM  object  to  QTP  Test  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .208Checking  Appearance  using  Style  Sheets    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .208Checking  Visibility  of  a  Object  on  a  Page .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .208

Selecting  a  Radio  button  by  Text .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .21020. Working with Web Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Web  Tables .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .217Accessing  the  WebTable    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .218Using  Index    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .219Using  Name  or  HTML  ID    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .219Using  innerText/outerText .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .219Using  OR .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .222Using  an  object  inside  the  table .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .224Getting  the  location  of  an  object  inside  the  table.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .225

Clicking  inside  a  WebTable .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .227Asynchronous  Table  loading  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .229Exporting  WebTable  to  a  DataTable    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .229Extending  WebTable  functionality.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .230Getting  a  QTP  Table  from  a  element      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .230Finding  a  cell  in  a  Table.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .231

21. Working with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237QTP  XML  Objects .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .238Reading  and  Modifying  XML    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .238

Page 9: QTP Unplugged 2nd Edition Updates eBook

Working  with  Multiple  environments  of  an  Application .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .241Exporting  XML  to  a  DataTable  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .243Comparing  XML    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .244

22. Working with Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249Connecting  to  a  Database.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .249Building  Connection  Strings    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .250Checking  the  State  of  a  Connection  or  Recordset .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .253

Exporting  the  Results  of  a  Query  to  Data  Table    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .254Executing  a  Stored  DB  procedure    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .255

23. Working with Microsoft Excel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259The  Excel  Automation  Object  Model    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .259Converting  VBA  to  VBScript    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .264Performance  Enhancements.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .270

24. Working with Microsoft Outlook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275Outlook  Object  model    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .275Launching  the  Outlook  Application.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .276Logging  in  to  the  Namespace    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .276Enumerating  the  top  level  folder    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .276Getting  a  Folder  interactively  from  a  user .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .278Getting  the  default  folders .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .278

Reading  e-­mail  Messages    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .279Accessing  e-­mail  Message  Properties    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .280Downloading  attachments    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .281

Sending  an  E-­mail  Message.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .281Outlook  Security  Dialogs.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .282

Getting  addresses  from  e-­mail  messages .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .285Extended  Email  Address    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .285

Clicking  links  inside  an  e-­mail  message    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .286Launching  QTP  using  an  email  trigger    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .287

25. Working with Microsoft Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291Word  Automation  Object  Model    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .291

26. Working with Microsoft Internet Explorer. . . . . . . . . . . . . . . . . . . . . 301Launching  Internet  Explorer  (IE).  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .301IE  COM  Methods  and  Properties.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .302Page  Synchronization.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .303Enumerating  all  IE  Windows .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .304Finding  an  IE  window    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .305Launching  a  new  browser    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .305Getting  Web  page  DOM    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .307Accessing  webpage  script  variables.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .307Using  IE  to  get  user  input   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .308

Page 10: QTP Unplugged 2nd Edition Updates eBook

IE  Popup  Dialogs .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .310Disabling  IE  dialogs.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .310Changing  IE  settings  using  the  Registry    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .310Popup  Blocker    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .311Disable  Script  Error  dialog    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .311Security  Alert  –  Redirection  popup    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .312

   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .313Security  Alert  –  Secure  Connection      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .313Security  Information  –  Secure  and  non-­secure  item    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .314Active  content/Java  Script  Prompt.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .315File  download  –  Information  bar .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .315

Handling  popup  dialog  by  using  a  code      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .316File  Download  –  Security  Warning  popup.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .317

Checking  for  Broken  images  on  a  Web  Page.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .320Using  a  Browser  Object  as  a  Window  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .320Custom  Browser  Applications .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .322

27. Working with HP Quality Center. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325Quality  Center    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .325Connecting  QTP  with  QC    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .325QC  Paths    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .327Relative  Paths  in  QC    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .327Resolving  Relative  Paths .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .327

QCUtil  Object    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .328QC  Open  Test  Architecture  (OTA)    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .330The  TDConnection  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .330The  Command  and  Recordset  Objects.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .333The  AttachmentFactory  Collection    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .334

   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .336Uploading  Attachments  to  QC.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .337

Getting  the  Current  Test  Location    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .338Enumerating  All  Tests  present  in  a  TestLab  folder    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .338Enumerating  all  the  Tests  in  a  Test  Lab  Tab    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .340Getting  the  Current  Test  Set  Location    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .341

28. Advanced QTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343Synchronizing  Script  Execution  between  different  machines .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .343Enumerating  the  Setting  Variables.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .344Setting  Persistence .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .349

Stop  and  Re-­Run  QTP  using  Code    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .350Adding  Recovery  Scenarios  at  Run-­time.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .351Executing  code  when  Script  ends    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .352Making  an  Object  visible  on  a  Web  Page    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .354

Page 11: QTP Unplugged 2nd Edition Updates eBook

Advanced  Text  Checkpoints    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .354Extending  Test  Objects  using  Classes    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .361Using  JScript  in  QTP .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .363Passing  variable  number  of  arguments  to  a  function .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .364Scope  differences .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .364Using  Try…Catch  block    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .365Working  with  JScript  Arrays    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .366Working  with  JS  classes.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .366

Object  Class  Mapping    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .36729. QTP 11 (New) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371IDE  Enhancement    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .371Comments    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .371Improved  IntelliSense    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .371Run  to  Step,  Debug  from  Step  and  Run  from  Step    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .372Enable/Disable  Breakpoints.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .372Renaming  CheckPoints    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .372

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .373Library  Support  Enhancements    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .374

Web  Drag  and  Drop  Support    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .374Middle  Click  and  Right  Click  methods .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .374Object  Property  Support  for  Firefox  Browser .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .374Recognizing  Web  objects  using  XPATH  or  CSS .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .375Regular  Expression  Evaluator    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .375Executing  JavaScript  Inside  WebPages .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .376Menu  updates .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .377

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .378Ignore  Browser.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .378Movie  Capture  to  Results.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .379

Added  and  Enhanced  Utility  Objects      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .379QCUtil    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .379SystemUtil  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .380The  Print  Log  Utility    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .380Hiding  the  Print  Window .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .381Showing  the  Print  window.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .382Clearing  the  print  window .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .382Programmatically  Capturing  the  Print  Log  text.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .383

Loading  and  Running  action  at  run-­time .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .383Repository  Utility  Object.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .383Local  System  Monitoring    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .384Reporting  Enhancements .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .385Reporting  Images .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .385Notes  in  Test  Results  Summary .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .386

Page 12: QTP Unplugged 2nd Edition Updates eBook

MercuryTimer    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .386RepositoriesCollection.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .387DotNetFactory    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .388Getting  Object  name  from  a  TestObject  in  OR    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .388Object  Repository  Enhancements    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .390Local  Object  Repository  (LOR).  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .390Shared  Object  Repository  (SOR).  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .392Associating  a  SOR  to  the  Test    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .392

Adding  objects  to  SOR    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .393Adding  object  using  Add  Object  button.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .393

   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .394Adding  object  through  Spy    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .394Navigate  and  Learn   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .396Other  Object  Related  features  of  OR.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .398Locating  the  object  in  OR    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .399Updating  an  Object  from  the  Application    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .399Object  Precedence  when  using  both  LOR  and  SOR    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .399Object  Repository  Parameters  (ORP)    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .401Importing  and  Exporting  OR  from  XML.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .404Update  from  Local  Object  Repository      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .405

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .407Object  Repository  Merge  tool    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .408Object  Repository  Comparison  Tool    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .409Local  OR  Vs  Shared  OR    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .411

Object  Spy    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .41130. Working with .NET Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415Using  the  DotNetFactory  Object .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .415Passing  Parameters  to  Class  Constructors .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .415Passing  Parameters  to  .NET  Objects  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .416Passing  Enums .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .417Working  with  .NET  Arrays    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .418Playing  a  Wav  File .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .419Working  with  the  Clipboard.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .419Getting  Computer  Information    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .419Accessing  the  Registry.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .420Ping  an  IP  Address .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .420Evaluating  Keyboard  Control  Key  Status    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .420.Net  Arrays  Revisited .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .421Working  with  .Net  Stacks    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .421Working  with  .Net  Queues.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .422Working  with  .Net  Date  and  Time  Formatting    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .422Sending  Emails  using  .NET.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .423

Page 13: QTP Unplugged 2nd Edition Updates eBook

Converting  Images  to  other  File  Formats    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .424Getting  user  Input  using  .NET  Forms    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .426

31. Designing Frameworks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433Design  guidelines.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .433Support  of  different  application  versions.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .434

QTP  Examples .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .436Reusability .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .436Support  for  different  application  versions .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .437

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .438Logging    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .438

   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .43932. Useful Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443QTP  Script  Editor.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .443VBSEdit .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .444Notepad++ .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .444QTP  Uninstaller .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .445ScreenCapture  API.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .446KnowledgeInbox  IE  Session  Cookies  Helper    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .447VB  2  QTP  API  Converter    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .447IE  WebDeveloper .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .447Test  Design  Studio  (TDS)   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .449RAD  Regular  Expression  Designer .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .450

Appendix A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1

Appendix B: Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1

Page 14: QTP Unplugged 2nd Edition Updates eBook

Preface

I  started  with  Web  testing  Automation  in  mid  2004  by  creating  a  project  in  Visual  Basic  6  using  the  Internet   explorer  COM  Automation.  The   project  was   a   great   success   but  with   every   change   to   the  

this  maintenance  issue,  I  stumbled  upon  QuickTest  Professional  8.0  (QTP).  

QuickTest  Professional  is  a  Test  Automation  tool  and  uses  VBScript  as  its  scripting  language.  QTP  is  a  record  and  playback  tool  which  can  record  events  we  perform  on  an  application  and  replay  them  back.  QTP  is  an  object  based  tool  which  recognizes  each  element  of  the  application  as  an  object  and  provides  various  methods  to  work  on  them.  All  this  makes  QTP  look  like  an  easy-­to-­use  test  tool.  The  myth  about  Record  &  Playback  is  that  it  makes  people  think  that  they  do  not  need  development  skills  for  QTP,  but  to  create  effective  Automation  Frameworks  one  needs  to  view  QTP  as  a  development  tool  and  not  as  a  testing  tool.  This  book  presents  QTP  as  a  development  tool  rather  than  a  mere  test  tool.

One  of  my  problems  while  evaluating  the  tool  led  to  me  to  join  www.SQAForum.com,  without  knowing  that  I  will  specialize  in  the  use  of  this  tool  in  future.  After  sometime  I  launched  KnowledgeInbox.com  for  sharing  my  articles  on  QTP  with  the  larger  group.  Dealing  with  day-­to-­day  automation  problems  faced  by  people  on  the  QTP  forums,  I  tried  solving  those  problems  for  them  and  learnt  a  few  new  things  

community  was  missing  is  a  book  which  can  guide  the  amateur  automation  engineers  in  becoming  a  professional  in  the  use  of  this  tool.  I  took  up  this  responsibility  and  started  writing  this  book  in  May  

of  QTP.  

But  knowing  what  difference  this  book  can  make  to  the  QTP  community  always  kept  me  motivated.  

I  have  organized  the  chapters  in  such  a  way  that  can  make  learning  QTP  an  easier  task.  Each  chapter  is  based  on  a  QTP  feature.  The  book  is  divided  into  two  sections,  Basics  and  Advanced.  Chapters  1  to  18  cover  features  related  to  QTP  while  the  chapters  in  the  Advanced  section  cover  integration/interaction  of  QTP  with  various  external  tools  like  Outlook,  Word,  Excel  and  Quality  Center.  The  book  discusses  a  lot  of  issues  that  are  commonly  faced  while  using  various  features  of  QTP  and  their  resolution.  This  

Page 15: QTP Unplugged 2nd Edition Updates eBook

Who  This  Book  Is  ForThis  book  is  for  Test  Engineers,  Test  Analysts,  Test  Consultants,  Test  Managers  and  anyone  who  is  

who  have  just  started  with  QTP  and  want  to  be  experts  in  its  use.  The  book  assumes  that  one  has  the  basic  knowledge  of  QTP  and  VBScript,  if  not  than  it  is  advised  that  one  should  go  through  the  basic  

does  not  teach  how  to  record  and  replay  script  in  QTP.  Also  the  book  does  not  discuss  about  the  Keyword  view  of  QTP,  which  is  for  non-­technical  people  who  don’t  want  to  code  in  QTP.

What’s  New  in  the  Second  EditionQuickTest  Professional  Unplugged,  2nd  Edition  comes  with  all  the  updates  till  QTP  11  in  a  new  

over  the  previous  versions  of  QTP.  The  chapter  also  discusses  the  Object  Repository  features  in  detail  which  had  seen  a  major  change  from  QTP  8.X  to  QTP  9.      

Source  Code  in  the  BookThe  source  codes  used  in  the  book  can  be  downloaded  from  the  below  url

KnowledgeInbox.com/demos/QTPUnplugged_SourceCodes.zip

Feedback  and  Queries  KnowledgeInbox.com/contact-­us

on  the  KnowledgeInbox  forums  –  Knowledgeinbox.com/forums

You  can  also  connect  with  us  on  Facebook.

facebook.com/pages/QuickTest-­Professional-­Unplugged/154615194628123

Ordering  this  BookFor  bulk  orders,  contact  us  at  [email protected]

India:  You  can  place  an  order  online  at  KnowledgeInbox.com/store

Other  locations:  Please  check  online  at  KnowledgeInbox.com/books

Page 16: QTP Unplugged 2nd Edition Updates eBook

Acknowledgements

The  following  individuals  deserve  a  special  mention  for  reviewing  my  work  in  progress,  and  providing  me  with  many  useful  comments  and  suggestions:

Mark  Smith,  Terry  Horwath  and  Siddharth  N  Kanoujia

Mark  works  as  a  freelance  consultant  and  can  be  contacted  on  [email protected]

Terry  has  not  only  worked  as  a  reviewer  but  also  as  a  Technical  Editor  for  this  book.  Terry  has  worked  with   automated   testing   tools   since   the   early  90’s  when  he   started  designing   solutions  with  Segue’s  QA  Partner  1.0.  He  transitioned  to  Mercury  Interactive  tools  in  1999  and  has  worked  exclusively  with  QuickTest  Professional  since  2005.  He  can  be  contacted  on  [email protected].

Siddharth  has  worked  as  an  Editor  for  this  book  and  has  done  a  great  job  making  sure  that  contents  of  this  book  are  lucid  and  unambiguous  for  the  beginners.  He  is  an  Assistant  Professor  in  the  Department  of  English  at  Hindu  College,  University  of  Delhi.  He  can  be  contacted  on  [email protected]

I  would  especially  like  to  thank  my  family  and  friends  who  have  always  motivated  me  while  I  was  working  on  this  book.

Quotes  From  Reviewers

.”  –  Terry  

“Tarun   Lalwani   has   single-­handedly   helped   thousands   of   people   to   expand   their  knowledge  of  QuickTest  Professional.  Here  is  a  book  the  automated  testing  community  

 –  Mark

I  realized  that  I  am  truly  in  the  presence  of  a  genius.  Tarun  has  with  his  dedication  

understand  the  ins  and  outs  of  QTP.”  –  Siddharth  

Page 17: QTP Unplugged 2nd Edition Updates eBook

Chapter 1

Introduction

What  is  Test  Automation?Test  automation  is  the  process  of  reducing,  and  when  possible,  removing  human  interactions  from  an  existing  manual  testing  process.

When  Should  Test  Automation  Be  Used?

Below  is  a  list  of  parameters  which  makes  a  manual  test  a  good  candidate  for  automation:

  The  test  must  be  repeated  often.

  The  test’s  workflow  and  its  validation  evolve  and  change  slowly  over  time.

  The  test  validates  a  business  process  or  workflow,  rather  than  look  and  feel,  color,  table  layout,  etc.

  The  test  is  very  repetitive  and/or  has  a  lot  of  steps,  and  it  is  important  that  those  steps  be  performed  exactly  the  same  each  time,  where  manual  tester  fatigue  must  be  avoided.

  The  test  produces  results  for  a  regulatory  body  that  demands  that  those  results  be  electronically  recorded  and  archived  as  formal  evidence  of  compliance.  

  The  test’s  pass/fail  results  are  reasonably  easy  to  determine  and  capture  with  the  selected  automation  tool.

  The  test  needs  to  drive  a  significant  amount  of  data  to  the  application

When  Should  Test  Automation  Be    Avoided?

  Ad  hoc  testing  where  a  subject  matter  expert  randomly  prowls  through  a  variety  of  combinatorial  workflows.

  One  time  testing  or  testing  repeated  only  a  few  times.

 of  virtually  all  of  the  product’s  functionality.

  Testing  where  look  and  feel,  color,  table  layout,  etc.  are  validated.

Page 18: QTP Unplugged 2nd Edition Updates eBook

2 QuickTest  Professional  Unplugged

 systems  and/or  applications.

The  Automated  Testing  ProcessIt  is  important  to  understand  the  various  phases  involved  in  the  automated  testing  process  in  order  to  develop  and  effective  framework  and  test  cases:

Figure  1-­1.  Automation  Process

  Selecting  the  “best  fit”  Automation  Tool:  Before  starting  to  automate  testing  in  any  application  it  is  important  to  pick  the  best  fit  tool  for  the  majority  of  your  applications.  The  choice  should  be  based  on  variety  of  factors  such  as  cost,  ease  of  use,  application  support  capabilities  and  product  support.

  Proof  of  Concept  (POC):  This  activity  involves  creating  a  few  sample  scripts  that  validate  a  few  important  business  workflows  in  one  or  two  of  your  most  important  applications.  This  helps  identify  any  major  issues  that  might  be  encountered  during  future  test  case  development.  A  proof  of  concept  should  also  be  used  to  select  the  best  automation  test  tool  for  your  applications.  

  Requirements  Analysisexisting  manual  test  cases  and  then  defining  the  scope  of  the  test  automation  project.

  Project  Estimates:  Once  the  scope  of  automation  is  defined,  estimates  can  then  be  formulated  based  on  various  factors  like  the  number  of  test  cases  to  be  automated,  their  level  of  complexity,  what  re-­usable  

  Framework  Design:  This  activity  involves  creating    shared  object  repository(s),  any  reusable  components,  writing  a  best  practice  guideline  document  and  completing  any  supplementary  activities  to  prepare  a  base  of  supporting  components  that  will  be  utilized  to  develop  automation  test  scripts.  

2

Page 19: QTP Unplugged 2nd Edition Updates eBook

3

  Test  Script  development:  Test  cases  are  created  by  calling  the  reusable  components  and  adding  appropriate  validations  to  each  workflow  specific  script.

  Debugging:  Completed  test  cases  are  debugged  to  make  sure  they  work  as  designed.  Make  sure  you  force  the  code  through  all  error  handling  paths  during  phase.

  Execution:  In  this  phase  test  cases  are  finally  put  to  work  through  regression  testing  and  validating  the  application  under  test.

  Result  Analysis:  Process  followed  by  the  results  created  by  each  executed  test  after  execution.

  Maintenance:  This  phase  involves  updating  scripts  to  fix  any  code  related  to  issues  found  during  execution.  These  issues  may  include  UI  or  markup  changes,  changes  in  flow  or  functionality  or  any  other  inevitable  changes  made  to  the  application  during  new  builds  or  releases.  A  well  designed  framework  and  set  of  tests  ensures  that  maintenance  costs  are  kept  to  a  minimum.

What  is  HP  QuickTest  Professional  (QTP)HP  QTP  is  a  Functional  Test  Automation  tool.  Out  of  the  box,  it  supports  a  Record  and  Playback  methodology  where  automation  Engineers  can  record  and  capture  events  with  the  application  under  test  and  then  replay  those  actions  during  the  testing  phase.

QTP  has  two  modes  in  which  it  is  possible  to  view  and  edit  a  test  script:

  Keyword  View

  Expert  View

The  Keyword  View  displays  the  script  in  the  form  of  keywords  (each  object  is  an  icon)  arranged  in  a  tree-­like  format  that  is  targeted  at  Subject  Matter  Experts  (SMEs)  with  little  or  no  programming  background.  A  snapshot  of  the  Keyword  View  is  shown  below:

3

Page 20: QTP Unplugged 2nd Edition Updates eBook

4 QuickTest  Professional  Unplugged

The  Expert  View  exposes  the    underlying  VBScript  code  shown  as  icons  in  the  Keyword  view  and  provides  access  to  substantial  capabilities  not  available  in  the  Keyword  view:

This  book  is  targeted  at  automation  engineers  who  want  to  exploit  the  power  that  QTP  offers  when  working  in  the  Expert  View.

NOTE: QTP uses VBScript as its programming language. Virtually all VBScript functionality is available in the QTP Expert View. Conversely, any VBScript limitations are also present in QTP. It is important to learn what are QTP VBScript related in a test’s structure. This book also helps clarify those aspects.

Getting  Started  with  QTPDownloading  QTP  from  HP  website

below  steps  to  download  the  latest  copy

  Go  to  http://support.openview.hp.com/

  Click  on  the  Products  link  on  the  Left

  Locate  “HP  Unified  Functional  Testing  software”  on  the  page  and  click  on  the  link

  Click  on  Trails  and  Demos  and  choose  “HP  FUNCTIONAL  TESTING  XX.00  EVALUATION”

  Create  a  new  HP  passport  in  case  you  don’t  have  one,  else  login  using  your  existing  passport  id

  Download  the  demo  the  file.  The  demo  file  will  be  in  ISO  format

4

Page 21: QTP Unplugged 2nd Edition Updates eBook

5

Installing  QTP

  Burn  the  ISO  file  on  the  a  DVD  using  a  DVD  Burner  tool

  Mount  the  ISO  file  using  any  Virtual  drive  tool.  You  can  use  freeware  tools  like  Virtual  CloneDrive  or  Daemon  tools  to  mount  the  ISO  file.

NOTE: The book doesn’t endorse or recommend any of above tools

Once  the  DVD  is  inserted,  double  click  on  the  drive.  This  should  launch  the  setup,  in  case  AutoRun  

menu  will  appear  as  shown  in  Figure  1-­5.  Click  on  the  “QuickTest  Professional  Setup”  option.  The  installation  home  screen  will  be  displayed  as  shown  in  Figure  1-­6.

After  accepting  the  license  agreement,  next  comes  the  Add-­in  select  screen.  By  default  only  ActiveX,  Web  and  VB  add-­ins  get  installed.  To  add  other  any  add-­in  select  the  same  and  choose  “Entire  feature  will  be  installed  on  local  hard  drive”  as  shown  in  Figure  1-­7.

After  choosing  the  add-­in  select  the  folder  where  QTP  needs  to  be  installed.  The  default  location  usually  is  “C:\Program  Files\HP\QuickTest  Professional”.  If  you  are  planning  to  install  the  JAVA  add-­in  then  I  would  recommend  changing  the  path  to  something  like  C:\QTP.  This  would  help  avoid  some  

recommend  to  use  the  default  path  itself.  Click  Next  and  start  the  installation.  Let  the  installation  

Page 22: QTP Unplugged 2nd Edition Updates eBook

6 QuickTest  Professional  Unplugged

Figure  1-­5.  Installation  Menu

Figure  1-­6.  Installation  Home  Srceen

Page 23: QTP Unplugged 2nd Edition Updates eBook

7

Figure  1-­7.  Selecting  Additional  Add-­ins  for  Installation

After  the  installation  process  we  get  an  installation  complete  screen  as  shown  in  Figure  1-­8.  After  we  

the  add-­ins  chosen  for  installation.  This  wizard  screen  is  shown  in  Figure  1-­9.

Figure  1-­8.  Installation  Completion

To  install  QTP  with  a  demo  version  license  make  sure  to  uncheck  the  “Run  the  Licenses  Installation  Wizard”.  

Page 24: QTP Unplugged 2nd Edition Updates eBook

8 QuickTest  Professional  Unplugged

NOTE: If the wizard is run and a concurrent license is selected then QTP does not install the demo license. This would be needed to accomplish manually at a later time.

QTP  Licensing  ModelQTP  licensing  model  allows  2  different  types  of  licenses

  Seat  License

  Floating  License

Seat  License

Seat  license  is  a  node  locked  or  machine-­based  license.  This  license  can  be  used  only  for  a  machine  

To  apply  for  a  seat  license,  select  the  “Seat  License”  radio  button  as  shown  in  Figure  1-­10  and  click  Next.  After  clicking  next  the  license  wizard  will  show  the  locking  code  of  the  machine  as  shown  

https://webware.hp.com/welcome.asp.  Once  you  receive  the  license  launch  the  wizard  again  and  click  Next  button  on  the  Locking  code  screen  and  paste  the  license  key  received  by  HP.  This  will  install  the  seat  license.

NOTE: Seat license uses some of the system components to generate a locking code. Changes in these components can change the locking code invalidate the installed license. Similarly, the locking code becomes obsolete if for any reason it becomes necessary to uninstall the system OS and reinstall it. It would be required to install QTP after a fresh OS install, which will generate a new locking code rendering the previously generated Seat license useless.

Page 25: QTP Unplugged 2nd Edition Updates eBook

9

Figure  1-­9.  Additional  Installation  Wizard

Floating  License

At  any  point  in  time  the  machines  using  the  QTP  licenses  cannot  exceed  the  maximum  license  count  on  the  server.  The  license  server  is  a  utility  that  needs  to  be  installed  separately  and  comes  with  the  QTP  installation.  The  license  server  can  be  installed  on  Windows  2000/2003/XP.  Floating  licenses  are  per  session  license  i.e.  they  are  only  used  when  QTP  is  open  on  a  machine.  

1-­10.  Click  on  the  next  button  and  enter  the  Server  IP  or  name  in  the  server.  Click  on  the  Check  Connection  button  and  if  successful  the  wizard  will  show  the  licenses  available  on  the  server  as  

NOTE: QTP uses UDP port 5093 for communicating with the license

NOTE: We can also create system environment variable with name LSHOST or LSFORCEHOST to specify the QTP License server IP or address.

Page 26: QTP Unplugged 2nd Edition Updates eBook

10 QuickTest  Professional  Unplugged

Page 27: QTP Unplugged 2nd Edition Updates eBook

11

Figure  1-­12.  Machine  Locking  Code

Page 28: QTP Unplugged 2nd Edition Updates eBook

Chapter 29

QTP 11

This  chapter  describes  additions  and  enhancements  added  between  QTP  8.2  to  QTP  11.  It  can  be  important  for  teams  to  know  the  reason  behind  upgrading  to  QTP  11  as  there  has  been  an  introduction  of  some  important  features  with  the  latest  version.  This  chapter  can  also  provide  a  reference  for  teams  that  are  unsure  whether  the  upgrade  will  be  a  worthwhile  process  for  them.

NOTE: Some of the features listed in this section may have been introduced in versions 9.x or 10.0. This chapter, however, provides a list of all features since QTP 8.2 to make sure your environment is using the latest version of QTP.

IDE  EnhancementQTP  11  IDE  enhancements  are  described  in  this  section.

Comments

You  can  now  comment  and  uncomment  select  blocks  of  code.  This  can  be  done  using  one  of  the  following  ways:

  Using  the  Edit  toolbar

  Using  the  shortcut  hot  keys  after  selecting  the  code  block:

  Comment  Block  (CTRL  +  M)

  Uncomment  Block  (CTRL  +  SHIFT  +  M)

Improved  IntelliSense

QTP  11  has  improved  IntelliSense  as  compared  to  its  previous  versions.  Now,  IntelliSense  also  works  when  creating  tests  using  Descriptive  Programming  (which  was  not  the  case  with  QTP  8.x).  QTP  11  also  provides  IntelliSense  for  COM  objects  created  using  CreateObject  as  shown  in  Figure  29-­1.

Page 29: QTP Unplugged 2nd Edition Updates eBook

372 QuickTest  Professional  Unplugged

Run  to  Step,  Debug  from  Step  and  Run  from  Step

QTP  11  provides  the  following  3  features  during  debugging  a  test  case:

  Run  to  Step:  This  option  allows  QTP  to  execute  the  script  upto  a  specific  line  of  code  and  Pause  where  the  option  ‘Run  to  Step’  was  selected  Shortcut  for  this  option  is  available  using  the  CTRL  +  F10  combination

  Debug  from  Step:  This  option  starts  the  script  in  Pause  mode  from  the  specified  line

  Run  from  Step:  This  options  start  the  script  in  Run  mode  from  the  specified  line

NOTE: The ‘Debug from Step’ and ‘Run from Step’ options performs an event in background which can’t be noticed through the QTP IDE. When we use these 2 options, QTP does nothing bit removes all the code before the current line executes the scripts from that point. This is a very crude way of implementing these options. Because of this behavior, a few limitations arise. For example, it is not possible to run the script within a conditional If statement since it would generate a syntax error because of the If statement being deleted.

Figure  29-­1.  IntelliSense  for  COM  Objects

Enable/Disable  Breakpoints

QTP  11  allows  you  to  disable  and  later  enable  existing  breakpoints.  In  QTP  8.x  you  had  to  clear  all  CheckPoints  to  disable  them  but  in  11  after  disabling  the  CheckPoint  the  CheckPoint  are  still  present  but  remain  inactive  until  re-­enabled.

Renaming  CheckPoints

QTP  11  allows  renaming  CheckPoints  which  was  not  allowed  in  QTP  8.x.  This  feature  allows  teams  to  easily  alter  their  code  once  its  created  without  recreating  the  CheckPoint.

372

Page 30: QTP Unplugged 2nd Edition Updates eBook

373

A  few  pointers  to  note  from  the  Figure  29-­2  and  the  result  after  accepting  the  changes  made  to  the  

  The  string  added  to  the  Description  text  box  appears  as  a  tool  tip  when  selecting  the  function  from  the  IntelliSense  list

  The  Documentation  text  is  displayed  in  the  documentation  column  when  working  in  the  Keyword  View

  The  function  parameters  <File>  and  <Folder>  are  replaced  with  actual  values  for  the  Documentation  text

  To  add  description  and/or  documentation,  it  is  not  necessary  to  declare  the  function  through  Function  Definition  Generator  only.  If  we  type  the  function  manually  into  the  IDE,  then  the  below  code  snippe  twill  work  in  the  same  manner:

'@Description  Copies  File  to  Specified  Folder

'@Documentation  Copy  File  -  <File>  to  Folder  -  <Folder>

Public  Function  CopyFileTo(ByRef  Folder,  File)

             '  TODO:  add  function  body  here

End  Function

373

Page 31: QTP Unplugged 2nd Edition Updates eBook

374 QuickTest  Professional  Unplugged

Library  Support  Enhancements

QTP  11  allows  editing  multiple  libraries  at  the  same  time.  It  also  allows  debugging  any  library  added  to  the  Test  Settings  Resource  tab.  However,  debugging  of  libraries  loaded  using  the  ExecuteFile  statement  is  still  not  supported.  To  overcome  this  limitation,  QTP  11  provides  a  new  method  called  LoadFunctionLibrary  to  load  a  library  at  run-­time  while  providing  debugging  support.

Web  Drag  and  Drop  SupportQTP  11  now  supports  performing  drag  and  drop  operation  on  web  objects.  This  can  be  done  by  use  the  Drag  and  the  Drop  method  on  the  test  object.

Middle  Click  and  Right  Click  methodsMost  of  the  Web  and  SAP  objects  now  support  methods  for  Middle  click  and  Right  Click.  These  

Click  method  with  micRightBtn  constant.

NOTE: RightClick and onContextMenu events in series to simulate right click when the ReplayType is set as Events. To use it as proper mouse right click change the ReplayType to Mouse Setting.WebPackage("ReplayType") = 2

Object  Property  Support  for  Firefox  BrowserQTP  11  allows  accessing  the  Object  property  for  Web  objects  in  FireFox.  This  allows  accessing  the  underlying  DOM  architecture  of  the  web  page.  So  the  below  code  statement  which  earlier  would  have  work  on  IE  browser  only  would  now  work  on  FireFox  as  well:

'Set  the  WebEdit  value  using  DOM

Browser("Google").Page("Google").WebEdit("q").Object.value  =  "Tarun  Lalwani"

NOTE: IE and FireFox both use a different set of HTML DOM. Though they have few things in common but not all DOM based code written in IE will work for FireFox. For Ex – FireFox DOM doesn’t have any property called outerHTML which is frequently used in IE. Though FireFox DOM does support the innerHTML property.

NOTE: The properties and methods when used in Firefox are Case Sensitive. For example: nextSibling can be used as NextSibling, nextsibling or any other way in IE. However, with Firefox, it can only be used in its correct Case: nextSibling.

374

Page 32: QTP Unplugged 2nd Edition Updates eBook

375

Recognizing  Web  objects  using  XPATH  or  CSSQTP  11  also  allows  identifying  web  objects  using  XPATH.  This  makes  it  easier  to  specify  few  objects  based  on  their  DOM  hierarchy.  Instead  of  identifying  a  web  object  using  different  properties,  we  can  just  use  one  XPATH  for  the  same.  Consider  the  below  HTML  object

<INPUT  class="hover"  id=s  size=45  value="Enter  your  search..."  name=s>

Now  we  can  identify  this  object  using  combinations  of  various  XPATHs.  Consider  few  of  them

  //INPUT[@class='hover']

  //INPUT[@id='s']

  //INPUT[@id='s',@class='hover']

By  using  such  XPATHs,  we  can  also  limit  our  object  search.  For  example:  if  we  want  access  to  an  object  inside  a  WebTable  cell,  we  know  that  the  object  will  have  a  parent  with  a  TD  html  tag.  In  that  case,    we  can  use  a  XPATH  like

//TD//INPUT[@name='s']

Regular  Expression  Evaluator

Expression  Evaluator.

The  tools  allows  testing  the  regular  expression  on  a  sample  text  as  shown  in  Figure  29-­4  

375

Page 33: QTP Unplugged 2nd Edition Updates eBook

376 QuickTest  Professional  Unplugged

Executing  JavaScript  Inside  WebPagesQTP  11  provides  4  methods  to  run  JavaScript  inside  a  web  page

  Browser().EmbedScript

  Browser().EmbedScriptFromFile

  Page().RunScript

  Page().RunScriptFromFile

The  EmbedScripr  or  EmbedScriptFromFile  methods  can  be  used  to  embed  a  JavaScript  in  a  web  page.  QTP  will  load  this  script  every  time  a  Page  or  Frame  refreshs.  These  methods  make  sure  the  JavaScript  is  always  available  in  the  browser  memory.  These  methods  should  be  used  to  inject  

The  RunScript  and  RunScriptFromFile  method  provides  a  way  to  execute  a  JavaScript  and  capture  its  results.  Consider  the  below  code:

'Embed  a  re-usable  function  that  we  can  use  on  any  pageBrowser("KnowledgeInbox").EmbedScript  "function  getPageTitle(){return  document.title;}"

'Get  the  current  page  titlestrTitle  =  Browser("KnowledgeInbox").Page("KnowledgeInbox").RunScript("getPageTitle()")Print  "Current  page  title  =  "  &  strTitle  

'Navigate  to  a  new  pageBrowser("KnowledgeInbox").Page("KnowledgeInbox").Link("QuickTest  Professional").ClickBrowser("KnowledgeInbox").Sync

'Get  the  current  page  titlestrTitle  =  Browser("KnowledgeInbox").Page("KnowledgeInbox").RunScript("getPageTitle()")Print  "New  page  title  =  "  &  strTitle  

376

Page 34: QTP Unplugged 2nd Edition Updates eBook

377

The  output  is  shown  below:

Menu  updatesQTP  11  has  added  several  changes  to  the  IDE  Menu  structure.    Table  29-­1  shows  these  changes  in  respect  to  version  8.2.:

Table  29-­1.  Menu  changes  from  QTP8.x  to  QTP  11

QTP  8.x QTP  11

Ø   Action  Properties…Ø   Action  Call  Properties…Ø   Split  Action…

Ø   Action  Properties…Ø   Action  Call  Properties…Ø   Split  Action…

Ø   Object  Properties…Ø   CheckPoint  Properties…Ø   Output  Value  Properties…

Ø   Object  Properties…Ø   CheckPoint  Properties…Ø   Output  Value  Properties…

377

Page 35: QTP Unplugged 2nd Edition Updates eBook

378 QuickTest  Professional  Unplugged

QTP  8.x QTP  11

Ø   Record…Ø   Run…Ø   StopØ   Run  From  Step…Ø   Update  Run…Ø   Analog  RecordingØ   Low  Level  RecordingØ   Record  and  Run  Settings…Ø   Results…

Ø   Record…Ø   Run…Ø   StopØ   Run  From  Step…Ø   Update  Run…Ø   Analog  RecordingØ   Low  Level  RecordingØ   Record  and  Run  Settings…Ø   Results…

-­er… Manager…

 dialog.  

Ignore  Browser

the  Options  Web  tab  as  shown  below  in  Figure  29-­6

Figure  29-­6.  Ignore  ALM/QC  Browser  Option

378

Page 36: QTP Unplugged 2nd Edition Updates eBook

379

Movie  Capture  to  Results

using  the  Options  Run  tab  as  shown  in  Figure  29-­7:

Added  and  Enhanced  Utility  Objects  This  section  describes  Utility  objects  that  have  been  added  and/or  enhanced  in  QTP  11.  

QCUtilYou  may  remember  that  this  object  was  used  in  the  “Working  with  Quality  Center”  chapter.  The  only  change  made  to  this  object  is  that  TDConnection  property  has  now  been  renamed  to  QCConnection.  So  any  places  where  we  were  using  QCUtil.TDConnection,  we  now  need  to  use  QCConnection.  If  you  want  to  create  version  independent  scripts  you  can  use  the  following  approach:

'Check  the  version  of  QTP  on  which  code  is  runningSelect  Case  Environment("ProductVer")    Case  "8.0",  "8.1"  ,  "8.2"        Set  TDConnection  =  QCUtil.TDConnection    Case  "9.0",  "9.1",  "9.2",  "10",  "11"        Set  TDConnection  =  QCUtil.QCConnectionEnd  Select

379

Page 37: QTP Unplugged 2nd Edition Updates eBook

380 QuickTest  Professional  Unplugged

SystemUtilQTP  11  adds  two  new  methods  to  the  SystemUtil  object:  BlockInput()  and  UnBlockInput().

The  BlockInput  method  allows  you  to  block  input  from  the  keyboard  and  mouse  while  the  script  is  running.  This  allows  you  to  avoid  any  accidental  keystrokes  or  mouse  events  which  can  disrupt  the  behavior  of  the  executing  test.  This  method  should  is  suggested  when  using  methods  like  Type  or  Set  (with  replay  type  set  to  mouse),  etc.  Input  is  blocked  until  one  of  the  following  events  occur:

  The  UnBlockInput  method  is  called

  CTRL  +  ALT  +  DEL  key  is  presses

  The  test  run  ends

  Any  error  is  encountered  during  the  test  run

  A  Breakpoint  is  reached

  A  System  error  occurs

The  code  below  shows  typical  use  of  these  methods:'Launch  the  calculator  appSystemUtil.Run  "calc.exe"

'Wait  Max  10  seconds  to  calculator  window  to  appearbWait  =  Window("title:=Calculator").Exist(10)

With  Window("title:=Calculator")    'Block  any  user  input    SystemUtil.BlockInput

   'Activate  the  application    .Activate

   'Type  a  event    .Type  "2"    .Type  "+"    .Type  "3"    .Type  "="    .Type  "-10="

   'Allow  user  inputs    SystemUtil.UnBlockInput

   'Display  the  output    Msgbox  .WinEdit("nativeclass:=Edit").GetROProperty("text")End  with

The  Print  Log  UtilitySimilar  to  some  of  its  previous  versions  (not  including  8.2),  QTP  11  retains  the  Print  Log  utility  that  allows  sending  messages  to  a  QTP  dialog  in  real-­time,  most  often  for  the  purposes  of  debugging.    It  can  be  used  as  shown  in  the  below  code:

'Print  something  on  to  the  Print  LogPrint  "Tarun  Lalwani"

This  code  opens  the  ‘QuickTest  Print  Log’  window  and  displays  the  Print  message  as  shown  in  Figure  29-­8

380

Page 38: QTP Unplugged 2nd Edition Updates eBook

381

Figure  29-­8.  Print  Log  window

Once  the  log  window  is  open,  each  additional  call  to  the  Print  function  adds  a  new  line  in  the  log  window.  The  only  control  available  in  the  Print  Log  window  itself  is  a  Clear  All  command.  This  new  utility  is  limited  as  follows:

  The  window  can’t  be  cleared  programmatically

  The  window’s  contents  can’t  be  saved  directly  to  a  file  (but  you  can  interactively  cut  and  paste  the  window  contents  to  a  text  editor  and  then  save  the  file)

  The  window  can’t  be  configured  to  run  hidden  

It  is  possible  to  overcome  the  above  limitations  by  using  pointers  described  in  the  next  section.

Hiding  the  Print  Window

We  can  use  the  ShowWindow  API  call  to  hide  and  show  the  Print  log  window  programmatically.  The  code  for  this  is  shown  below:

'API  declaration  for  ShowWindow  APIExtern.Declare  micLong,"ShowWindow","user32","ShowWindow",micLong,micLong

'ShowWindow  constantsConst  SW_HIDE  =  0Const  SW_SHOW  =  5

'Function  to  hide  the  print  log  windowPublic  Function  HidePrintWindow()   Set  QTPlogWindow  =  Window("regexpwndclass:=Mercury::Qtprn::PrintWindow")  

  'Check  if  the  LOg  window  exist   If  QTPlogWindow.Exist(0)  Then     hwnd  =  QTPlogWindow.GetROProperty("hwnd")     'Hide  the  window     Extern.ShowWindow  hwnd,  SW_HIDE   End  ifEnd  Function

Running  the  above  code  will  hide  the  log  window.

381

Page 39: QTP Unplugged 2nd Edition Updates eBook

382 QuickTest  Professional  Unplugged

Showing  the  Print  window

the  hidden  log  window  using  the  following  code:'Function  to  print  the  log  windowPublic  Function  ShowPrintWindow()   Set  QTPlogWindow  =  Window("regexpwndclass:=Mercury::Qtprn::PrintWindow")     'Check  if  the  LOg  window  exist

  If  QTPlogWindow.Exist(0)  Then     hwnd  =  QTPlogWindow.GetROProperty("hwnd")      'Show  the  window     Extern.ShowWindow  hwnd,  SW_SHOW   End  ifEnd  Function

However,  if  we  attempt  to  use  the  above  code  when  the  print  log  window  is  hidden  the  window  will  not  become  visible.  So  what  went  wrong?  If  we  observe  closely  we  notice  that  QTPlogWindow.Exist(0)  always  return  False.  This  happens  because  QTP  does  not  work  on  invisible  windows  unless  it  has  been  instructed  to  do  so  explicitly.  Therefore,  to  accommodate  for  the  behavior,  we  can  change  the  Window  object  in  the  function  as  described  below:

'Specify  using  visible:=False  that  we  are  looking  for  a  hidden  windowSet  QTPlogWindow  =  Window("regexpwndclass:=Mercury::Qtprn::PrintWindow","visible:=False")  

Now  though,  the  above  code  will  fail  if  the  window  is  currently  visible.  When  the  window  is  visible,  we  need  not  perform  any  steps.  But  in  case  we  want  to  check  the  existence  of  the  log  window  regardless  of  it  being  visible  or  invisible  then  we  can  use  the  following  approach:

'Specify  visible:=True|False  ensures  we  get  the  window'regardless  if  it  is  visible/invisibleSet  QTPlogWindow  =  Window("regexpwndclass:=Mercury::Qtprn::PrintWindow","visible:=True|False")  

Clearing  the  print  window

In  the  following  functions  we  use  the  “visible:=True|False”  approach  for  all  objects  so  that  our  functions  are  compatible  regardless  of  the  visibility  of  the  window.

'API  Declaration  for  SendMessageExtern.Declare  micLong,"SendMessage","user32","SendMessageA",micLong,micLong,micLong,micRef+micLong

'Message  to  Set  text  of  a  windowConst  WM_SETTEXT  =  &HC

'Function  to  clear  the  print  Log  windowPublic  Function  ClearPrintWindow()    'Check  if  the  print  Log  window  exists  or  not    Set  QTPlogWindow  =  Window("regexpwndclass:=Mercury::Qtprn::PrintWindow","visible:=True|False")    If  QTPlogWindow.Exist(0)  Then        'Get  the  handle  of  edit  box        'It  is  important  to  use  "visible:=True|False"  here  also  as  the        'for  a  hidden  window  the  edit  is  also  hidden        hwnd  =  QTPlogWindow.WinEdit("nativeclass:=Edit","visible:=True|False").GetROProperty("hwnd")

       'Send  a  message  to  clear  the  text  box  text

382

Page 40: QTP Unplugged 2nd Edition Updates eBook

383

       Extern.SendMessage  hwnd,  WM_SETTEXT,  0,  0    End  ifEnd  Function

'Use  the  function  to  clear  the  windowCall  ClearPrintWindow

'Print  on  to  the  logPrint  "Tarun  Lalwani"

Programmatically  Capturing  the  Print  Log  text'Function  to  get  the  text  from  the  QTP  Print  Log  WindowPublic  Function  GetPrintWindowText()    GetPrintWindowText  =  ""    Set  QTPlogWindow  =  Window("regexpwndclass:=Mercury::Qtprn::PrintWindow",  "visible:=True:False")      'Check  if  the  Log  window  exist

   If  QTPlogWindow.Exist(0)  Then        'Get  the  text  from  of  edit  box        GetPrintWindowText  =  QTPlogWindow.WinEdit("nativeclass:=Edit","visible:=True:False").GetROProperty("text")    End  ifEnd  Function

Msgbox  GetPrintWindowText

Loading  and  Running  action  at  run-­timeQTP  11  allows  loading  and  running  an  Action  at  run-­time.  This  eliminates  the  need  of  inserting  a  call  through  the  QTP  IDE  for  the  re-­usable  action.  The  syntax  of  the  method  is  as  shown  below:

LoadAndRunAction(TestPath,  ActionName,  [Iteration],  [Parameters])  

This  is  useful  when  the  Action  to  be  called  is  based  on  some  condition  evaluated  at  run-­time.  This  

decide  which  action  needs  to  be  executed  after  an  event  occurs.

Repository  Utility  Object

property  values.  Once  a  SOR  is  mapped  to  a  Test,  its  Repository  parameters  can  be  mapped  to  constant,  DataTable,  Environment  or  RandomNumber  as  shown  in  Figure  29-­9

383

Page 41: QTP Unplugged 2nd Edition Updates eBook

384 QuickTest  Professional  Unplugged

Figure  29-­9.  Object  Repository  Parameter  Mapping

These  parameters  can  be  accessed  and  updated  at  run-­time  using  the  Repository  object  as  shown  in  the  code  below

Repository("repBrowserTitle")  =  "QuickTest  Professional  Unplugged  |  KnowledgeInbox"

Local  System  Monitoring

the  memory  usage  of  Internet  Explorer  crosses  the  700MB  mark.

NOTE: This feature does allow some amount of performance monitoring with QTP but cannot be used for extensive performance monitoring where server parameters or multiple applications need to be monitored. This is actually a good way to track the performance of IE or any other application when the tests are run for longer durations.

384

Page 42: QTP Unplugged 2nd Edition Updates eBook

385

Reporting  EnhancementsReporting  Images

QTP  11  also  allows  reporting  images  into  the  Test  Results  summary.  Consider  the  below  code:'Capture  the  screenshotWindow("title:=QuickTest  Professional.*").CaptureBitmap  "C:\QTP.png",True

'Report  it  to  the  Test  ResultsReporter.ReportEvent  micPass,  "QTP",  "Reporting  Image",  "C:\QTP.png"

The  Test  Result  shows  the  image  as  shown  in  Figure  29-­11.  This  image  is  also  retained  when  the  

Figure  29-­11.  Image  Report  in  Test  Results  Summary

385

Page 43: QTP Unplugged 2nd Edition Updates eBook

386 QuickTest  Professional  Unplugged

Notes  in  Test  Results  Summary

With  QTP  11,  it  is  also  possible  to  add  notes  to  the  test  summary.  These  notes  can  be  used  for  reporting  the  key  highlights,  issues  or  important  information  which  may  help  analyze  the  test  results  easily.  Consider  a  scenario  where  we  execute  a  test  against  a  given  test  data  and  it  produces  an  error  

is  supposed  to  be  usedstrErrorExists  =  Browser("KnowledgeInbox").Page("KnowledgeInbox").WebElement("Error").Exist(0)

If  strErrorExists  Then   Reporter.ReportNote  "The  test  data  used  is  not  valid.  Please  use  a  account  which  has  access  to  the  premium  services"End  If

The  output  of  above  code  in  the  Test  results  summary  is  shown  in  Figure  29-­12

Figure  29-­12.  Notes  in  Test  Result  summary

MercuryTimerMercuryTimers  is  a  new  utility  objects  that  allows  you  to  create  various  timers.  A  timer  is  

following  code:'Get  a  timer  using  Timer  propertySet  newTime  =  MercuryTimers.Timer("Time1")

'Timer  is  the  default  property  of  MercuryTimers'so  we  don't  need  to  specify  TimerSet  newTime  =  MercuryTimers("Time1")

A  MercuryTimer  object  provides  following  methods:

  Start:  Start  the  timer

  Stop:  Stop  the  timer

Page 44: QTP Unplugged 2nd Edition Updates eBook

387

  Reset:  Reset  the  timer

  Continue:  Continue  a  stopped  timer

  ElapsedTime:  Time  elapsed  till  last  stop  (in  milliseconds)

The  following  code  shows  how  to  use  these  methods:'Start  the  timerMercuryTimers("Time1").StartWait  2'Stop  the  timerMercuryTimers("Time1").Stop

'Print  elapsed  time  -  On  my  machine  prints  '2012'Print  MercuryTimers("Time1").ElapsedTime

Wait  1

'Continue  with  the  timerMercuryTimers("Time1").ContinueWait  1'Print  the  Elapsed  Time  -  On  my  machine  prints  '3014'Print  MercuryTimers("Time1").ElapsedTimeWait  1'Stop  the  timer  -  On  my  machine  prints  '4025'Print  MercuryTimers("Time1").Stop

'Start  the  timer  (this  is  equivalent  to  using  Reset  and  then  start)MercuryTimers("Time1").StartWait  2'Stop  the  timerMercuryTimers("Time1").Stop

'Print  the  elapsed  timer  -  On  my  machine  prints  '2012'Print  MercuryTimers("Time1").ElapsedTime

'Reset  the  timerMercuryTimers("Time1").Reset

'Print  the  elapsed  time  -  prints  '0'Print  MercuryTimers("Time1").ElapsedTime

RepositoriesCollectionRepositoriesCollection  utility  object  allows  you  to  add  any  number  of  shared  object  repositories  at  Run-­time  to  the  current  action,  in  addition  to  any  object  repositories  associated  the  Action  as  well.  The  RepositoriesCollection  object  provides  following  methods:

  Add:  Add  a  shared  repository

  Find:  Find  a  shared  repository

  MoveToPos:  Move  shared  repository  to  a  give  position  in  the  priority  order

  Remove:  Remove  a  shared  repository

  RemoveAll:  Remove  all  shared  repositories

  Count:  Count  of  shared  object  repositories

Page 45: QTP Unplugged 2nd Edition Updates eBook

388 QuickTest  Professional  Unplugged

  Item:  Get  path  to  the  shared  object  using  a  specified  index'Remove  all  the  object  repositoriesRepositoriesCollection.RemoveAll

'Add  the  new  object  repositoryRepositoriesCollection.Add  "C:\CompleteObjectRepository.tsr"

Above  code  will  add  object  repository  to  the  Action  in  which  the  code  is  being  executed.  These  changes  are  run-­time  only  changes  and  are  reverted  back  when  the  test  run  ends.

WARNING: If you use the above mentioned code in an Associated

of the script and also the changes will not be reverted. Which mean the object repository will actually be added to the test and running the code again may throw an error as the object repository will already exists.

DotNetFactoryQTP  11  provides  DotNetFactory  utility  object  which  allows  creating  instance  of  .NET  classes  in  QTP.  The  object  provides  only  one  method,  CreateInstance:  

'Function  SyntaxSet  var_CreateInstance  =  DotNetFactory.CreateInstance  (TypeName  [,Assembly]  [,args])  

The  method  takes  the  following  parameters

 TypeName:  Type  name  of  class  to  be  instantiated,  for  example  "System.Windows.

Forms.Form",  "System.Net.Mail.MailMessage",  etc.

 Assembly:  Name  of  the  Assembly  class,  for  eample  "System.Windows"  etc.

 Args:  Parameters  to  be  passed  to  the  .NET  object  constructor.  This  is  needed  to  

create  object  instance  when  there  is  no  parameter-less  constructor.

The  DotNetFactory  utility  has  greatly  enhanced  what  can  achieve  in  QTP  and  that’s  why  this  book  has  a  chapter  dedicated  to  discussing  this  feature  in  detail.

Getting  Object  name  from  a  TestObject  in  OREach  QTP  Test  Object  now  support  two  new  properties

  TestObjName:  Returns  the  Name  of  the  object  in  repository.  

  In  case  the  object  is  not  from  repository  and  the  application  is  running  then  it  will  return  the  default  name  

  In  case  the  object  is  not  from  the  repository  and  the  application  is  not  running  then  the  micclass  of  the  

  TestObjGenType:  Returns  the  generic  type  of  the  object.  For  example    text  box,  list  box,  table,  text  label,  etc.

These  new  properties  prove  very  useful  for  debugging  and  logging  purposes.  The  TestObjName  property  gives  use  the  power  to  regenerate  the  whole  object  statement  from  an  object.  We  created  a  

Page 46: QTP Unplugged 2nd Edition Updates eBook

389

function  GetObjectSTR  in  the  “Recovery  Scenarios”  chapter  that  allowed  converting  an  object  to  its  

code:'Function  to  convert  a  QTP  test  object  into  its  string'description.  Public  Function  GetObjectSTR(pObject)   Dim  sProps()   ReDim  sProps(0)

  'Get  the  name  property  from  TestObjName   sProps(0)  =  pObject.GetTOProperty("TestObjName")

  'Get  the  type  of  the  objecy   sClass  =  pObject.GetTOProperty("micclass")

  'If  the  name  contains  [  in  the  start  and  ]  in  the  end   'then  it  is  not  from  object  repository   If  Left(sProps(0),1)="["  and  Right(sProps(0),1)="]"  Then     'The  object  is  not  from  the  OR.  Continue  the  normal  method       'to  get  the  description  of  the  object

    'Get  all  the  test  object  identification  properties     Set  oTOProps  =  pObject.GetTOProperties         iCount  =  oTOProps.Count  -  1     'Loop  through  and  create  a  array  for  string  description     For  i  =  0  to  iCount       sProps(UBound(sProps))  =  oTOProps(i).Name  &  ":="  &  oTOProps(i).Value       ReDim  Preserve  sProps(UBound(sProps)  +  1)       Next       ReDim  Preserve  sProps(UBound(sProps)-1)   End  If

  'Create  the  string  object  description  of  current  object   sObjectStr  =  sClass    &  "("""  &  join(sProps,""",""")  &  """)"

  'Check  if  the  object  is  a  top  level  object   If  TypeName(pObject.GetTOProperty("parent"))  =  "Empty"  Then     GetObjectSTR  =  sObjectStr   Else        'Get  the  parent  object  of  the  current  object     Set   oParent  =  pObject.GetTOProperty("parent")     'Recursivly  call  the  function  to  get  the  complete  description     GetObjectSTR  =  GetObjectSTR(oParent)  &  "."  &  sObjectStr   End  IfEnd  Function

'Prints  "Dialog("Run").WinEdit("Open:")"Print  GetObjectSTR(Dialog("Run").WinEdit("Open:"))

'Prints  "Dialog("Run").WinEdit("text:=Open:")"Print  GetObjectSTR(Dialog("Run").WinEdit("text:=Open:"))

Page 47: QTP Unplugged 2nd Edition Updates eBook

390 QuickTest  Professional  Unplugged

Object  Repository  EnhancementsWorking  of  Object  Repositories  in  QTP  changed  a  lot  from  QTP  8.2  to  QTP  11  (actual  change  being  from  QTP  9.0).  Instead  of  being  able  to  associate  a  single  shared  object  repository  (SOR)  to  a  test  now  QTP  allows  associating  multiple  object  repositories.  The  association  happens  at  the  Action  level  instead  of  the  Test  level.  

Local  Object  Repository  (LOR)

Every  Action  in  a  QTP  script  has  an  associated  Local  object  repository.  The  LOR  is  stored  as  a  

While  recording  scripts  in  QTP,  if  the  object  doesn’t  exist  in  the  associated  shared  object  repositories  (SOR)  or  LOR  then  QTP  adds  it  to  the  LOR.  This  behavior  of  QTP  adding  objects  to  LOR  cannot  be  changed.

R  key  combination.  By  default  the  LOR  shows  all  objects  present  in  LOR  as  well  objects  present  in  

on  to  just  Local  objects  by  using  the  Filter  dropdown  in  the  LOR  UI.

A  LOR  object  always  takes  precedence  over  the  same  object  from  SOR.  Consider  the  below  case  where  a  SOR  associated  with  the  test  has  5  objects.  We  can  copy  the  top  level  “KnowledgeInbox”  Browser  object  by  right  clicking  and  using  “Copy  to  Local”  option  as  shown  in  Figure  29-­10.  This  creates  the  copy  of  the  same  object  in  the  LOR.

Figure  29-­13.  Object  Copy  to  Local

Page 48: QTP Unplugged 2nd Edition Updates eBook

391

Figure  29-­14.  Local  Object  Repository

When  we  use  the  below  statement  in  the  codeBrowser("KnowledgeInbox").Page("Login").WebButton("Log In").Click

properties  will  be  taken  from  the  SOR.  This  is  one  key  reason  for  object  not  found  defect  as  well:  

problem  cannot  be  caught  by  looking  in  just  the  SOR  as  the  object  may  still  get  highlighted  in  the  application  through  SOR.  However,  during  execution,  it  may  not  work  as  expected.

LOR  UI  has  2  options  for  exporting  the  object  repository  

  “Export  Local  Objects…”  –  This  exports  all  the  objects  in  LOR  to  a  TSR  file.

  “Export  and  Replace  Local  Objects…”  –  This  exports  all  the  objects  in  LOR  to  a  TSR  file  and  removes  them  from  LOR.

NOTE: Exporting TSR and not merge with the existing objects.

Page 49: QTP Unplugged 2nd Edition Updates eBook

392 QuickTest  Professional  Unplugged

Shared  Object  Repository  (SOR)

Shared  Object  Repository  is  external  repository  which  can  be  shared  by  various  test  scripts.  Despite  its  name,  this  object  repository  cannot  be  shared  across  users  simultaneously  as  only  one  user  at  a  time  can  modify  it.  For  all  other  users  accessing  the  SOR,  it  is  viewed  only  in  read-­only  mode.  

A  SOR  is  associated  with  a  test  at  Action  level.  Actions  and  SOR  have  a  manytomany  relation  i.e.  an  Action  can  have  multiple  SOR  associated  and  an  SOR  can  be  associated  with  multiple  actions

NOTE: SOR or LOR cannot be associated with the startup code of global scope. So if we Browser("KnowledgeInbox") object in our LOR or SOR and we place the below code Browser("KnowledgeInbox").Sync in one of our associated library then the code will error out as the OR will have no meaning without any action being loaded in memory and during execution of global libraries none of the actions exists.

Manager  (ORM)…’  and  click  on  the  New  icon

NOTE: One cannot record and have the objects created in the SOR directly. Objects can only be added to SOR manually or through Navigate and learn feature of ORM.

Figure  29-­16.  Object  Repository  Manager

Associating  a  SOR  to  the  Test

button  to  add  a  new  repository  to  add  a  SOR.  After  adding  the  SOR  select  the  actions  with  which  the  

Page 50: QTP Unplugged 2nd Edition Updates eBook

393

SOR  needs  to  be  associated.  Multiple  actions  can  be  selected  at  the  same  time  by  holding  the  CTRL  key  and  clicking  the  actions  in  the  list.  After  selecting  all  the  actions  (as  shown  in  Figure  29-­17)  click  on  the  arrow  (>)  button  to  make  the  SOR  available  to  selected  actions.  Clicking  on  the  double  arrow  (>>)  selects  all  the  actions.

NOTE: A SOR cannot be associated with the Test. It can be associated with actions only. When a new action is added to the test it will not get associated with the SOR. But it is still possible to achieve auto association of the SOR to any newly created action. To do so browse to one of the Actions with the SOR already associated. Go to menu Edit Action Action Properties… Associated Repositories (Tab). Click on the Set as Default button, this will make all the SOR associated with current action as the default SOR for new actions.

Figure  29-­17.  Associate  Object  Repository

Adding  objects  to  SORObjects  can  be  added  in  a  few  different  ways  to  the  SOR.  

Adding  object  using  Add  Object  button

Objects  can  be  added  to  SOR  clicking  the    button  and  clicking  on  the  object  with  the  hand  pointer   .  After  clicking  the  on  the  object  QTP  show  the  “Object  Selection  –  Add  to  Repository”  dialog  as  shown  in  Figure  29-­18.  From  this  dialog  the  whole  hierarchy  of  the  object  is  shown  and  we  can  select  which  object  we  want  to  add.

Page 51: QTP Unplugged 2nd Edition Updates eBook

394 QuickTest  Professional  Unplugged

NOTE: QTP doesn’t add all the objects from the listed hierarchy. It only adds those which it needs to re-identify the object.

19.  In  this  dialog  we  need  to  select  the  Class  (the  test  object  type),  the  Name  (logical  name)  and  the  description  property  values

QTP  displays  the  list  of  Mandatory  properties  by  default  in  this  dialog.  To  add  additional  properties  

NOTE: This method is useful when the application is not ready to add objects. Also in certain cases QTP displays the object hierarchy but is not able to add the object to the OR. In such cases we can note down the property values and add them using this method.

Figure  29-­18.  Object  Selection  –  Add  to  Repository

Adding  object  through  Spy

We  can  add  objects  directly  from  the  Spy.  Click  on  the    Object  Spy  button  to  launch  object  spy.  In  the  object  spy  we  can  select  the  object  that  needs  to  add  to  the  OR  and  then  click  on  the    button  to  add  the  object  to  OR  as  shown  in  Figure  29-­20

Page 52: QTP Unplugged 2nd Edition Updates eBook

395

When  we  spy  again  on  objects  using  Object  Spy,  the  object  icon  shows  if  the  object  is  already  present  in  the  OR  as  shown  in  Figure  29-­21

Page 53: QTP Unplugged 2nd Edition Updates eBook

396 QuickTest  Professional  Unplugged

Figure  29-­21.  Object  Spy  -­  Objects  already  present  in  OR

NOTE: The feature of adding objects directly from the Object Spy to OR is only available from QTP 11.

NOTE: If Object Spy is launched from QTP IDE then objects will get added to the Local OR of the active Action and if the Object spy is launched through Object Repository Manager then the objects will be added to current active SOR.

Navigate  and  Learn  

This  feature  of  ORM  allows  navigating  in  an  application  and  learning  all  the  objects  in  between.  To  

the  small  “Navigate  and  Learn”  window  at  the  top  of  the  screen

Page 54: QTP Unplugged 2nd Edition Updates eBook

397

To  learn  objects  from  a  screen  select  the  main  window  and  click  the    Learn  button.  QTP    Filter  icon,  this  

Figure  29-­23.  Object  Filters

There  are  the  following  options  available  to  this  feature:

  Selected  object  only  (no  descendants):  will  learn  only  the  top-­most  or  the  window  we  have  activated

  Default  object  types  will  capture  only  a  predefined  sets  of  objects

  All  object  types  will  capture  all  the  objects  from  the  application.  This  option  should  be  used  cautiously  as  it  could  create  many  unwanted  objects  in  the  OR.  This  option  also  increases  the  size  of  the  Object  Repository  so  when  there  is  a  better  approach  available,  this  option  should  be  avoided.

  Selected  object  types  let  you  customize  the  filter.  Pressing  the  select  button  after  the  selecting  the  radio  button  launches  the  “Select  Object  Types”  dialog.  This  is  a  better  and  a  more  strategic  way  of  adding  target  Test  Objects  as  opposed  to  the  previous  approach.

Figure  29-­24.  Select  Object  Types

Page 55: QTP Unplugged 2nd Edition Updates eBook

398 QuickTest  Professional  Unplugged

  NOTE: Navigate and Learn can makes things easier by adding all the objects at once but if not used cautiously, it can also create a lot of unwanted objects in the SOR. This is not a good approach in case the screen has lot of controls and our scripts only covers few of them. In such a case it is better to add this manually.

Other  Object  Related  features  of  OR

Highlighting  the  object  in  Application  can  be  done  by  selecting  the  object  in  OR  and  clicking  the    highlight  button.  This  will  highlight  the  object  in  application.  If  QTP  is  not  able  to  identify  the  object  then  it  will  raise  one  of  the  two  possible  errors  as  shown  in  Figure  29-­25  and  Figure  29-­26.  

  The  first  error  is  due  to  the  fact  that  properties  used  for  identification  are  not  sufficient  to  identify  any  object  in  the  application.  

  The  second  error  occurs  due  to  multiple  matches  of  the  target  object  from  the  current  description.  In  this  

NOTE: If QTP is not able to identify an object then it doesn’t mean

possibility that QTP is not able to identify one of the parent objects in the hierarchy correctly. So one should check the entire hierarchys to

correctly.

  WARNING: If QTP highlights the object correctly and the Smart

To make sure that object is being highlighted correctly always set the

object again.

Figure  29-­25.  Object  not  found  error

Page 56: QTP Unplugged 2nd Edition Updates eBook

399

Figure  29-­26.  Multiple  object  matches  error

Locating  the  object  in  OR

We  can  also  locate  if  a  given  object  in  the  application  is  already  present  in  the  OR.  To  locate  an  existing  object  click  on  the    Locate  in  Repository  button  and  then  click  on  the  object  using  the  Hand  pointer.  If  object  already  exists  in  the  OR,  then  QTP  will  locate  and  activate  the  same  in  the  object  tree.  Otherwise,  QTP  will  raise  an  error  as  shown  in  Figure  29-­27.

Figure  29-­27.  Cannot  Locate  object  in  OR

Updating  an  Object  from  the  ApplicationIn  case  an  object  got  changed  after  adding  it  the  OR  we  can  update  the  properties  again  by  clicking  on  the    Update  from  Application  button

WARNING: We can update an object of the same object type though it might not be the same object we had earlier. Ex – An existing textbox for username can be updated with properties from a password textbox. This would create a object with logical name as username but would

Object  Precedence  when  using  both  LOR  and  SOR

Figure  29-­28  and  SOR  shown  in  Figure  29-­29.  Both  the  ORs  have  a  common  root  object  “Microsoft  Word”.  The  only  difference  being  the  value  of  regexpwndclass  property.  The  SOR  has  an  object  named  “Microsoft  Word  Document”  as  the  child  of  the  “Microsoft  Word”  object.  Now  when  we  use  the  below  statement

objExist  =  Window("Microsoft  Word").WinObject("Microsoft  Word  Document").Exist(0)

LOR

Page 57: QTP Unplugged 2nd Edition Updates eBook

400 QuickTest  Professional  Unplugged

WARNING: When using SOR only approach if the parent object gets added to the LOR by mistake then it can interfere with correct object

Figure  29-­28.  Object  in  Local  Object  Repository

Figure  29-­29.  Object  in  Shared  Object  Repository

Page 58: QTP Unplugged 2nd Edition Updates eBook

401

Object  Repository  Parameters  (ORP)

Object  repository  parameters  (ORP)  can  be  used  to  add  parameters  to  the  SOR.  These  parameters  

Repository  Parameters…  and  it  will  show  the  ORP  dialog  as  shown  in  Figure  29-­30

Clicking  on  the    “+”  button  launches  the  “Add  Repository  Parameter”  dialog  as  shown  in  Figure  29-­31.  In  this  we  can  add  the  name  of  parameter  and  its  default  value.

Figure  29-­31.  Add  Repository  Parameter

Once  the  parameter  is  added  we  use  it  to  map  to  the  property  values.  To  map  parameter  values  click  on  the    button  in  parameter  value  or  press  CTRL  +  F11

Page 59: QTP Unplugged 2nd Edition Updates eBook

402 QuickTest  Professional  Unplugged

Figure  29-­33.  Repository  Parameters

NOTE: In SOR we can’t directly map parameters to DataTable or Environment variable as we do in LOR that is why the need of Object Repository parameter arises.

When  a  SOR  with  object  repository  parameter  is  associated  to  the  test,  the  object  repository  parameters  are  available  for  mapping.  In  case  there  is  no  default  value  associated  with  a  repository  parameter  it  would  be  shown  in  the  missing  resources  tab  as  “unmapped  repository  parameters”.

The  mapping  of  parameters  can  be  done  for  Entire  Test  or  at  Action  level.  The  mapping  can  be  

Page 60: QTP Unplugged 2nd Edition Updates eBook

403

done  to  a  DataTable  parameter  or  Environment  variable  or  a  Random  Number.  We  can  also  do  this  mapping  at  Run-­time  using  the  Repository  utility  object

'Prints  KnowledgeInbox  (the  default  value)Print  Browser("KnowledgeInbpx").GetTOProperty("title")Repository("myBrowserTitle")  =  "Test"'Prints  Test  (the  update  value)

Print  Browser("KnowledgeInbpx").GetTOProperty("title")

NOTE: Value changed using Repository object in code will have effect for the whole test. The value doesn’t change to the default value from one action to another action.

Figure  29-­34.  Map  Repository  Parameters

Page 61: QTP Unplugged 2nd Edition Updates eBook

404 QuickTest  Professional  Unplugged

WARNING: One huge limitation of using Repository parameters is that we can’t specify the value as a regular expression pattern. I am not sure how HP missed this but this feature is not available with parameterize values in OR.

Importing  and  Exporting  OR  from  XML

  NOTE: Exporting and re-importing the OR can at times reduce the size of the SOR and is a good way to compact the same.

NOTE: Exporting SOR to XML includes CheckPoint information only in case of QTP 11. This is not true in case of QTP 10 or lower.

NOTE: Importing the XML always creates a new SOR and doesn’t merge the object with existing SOR.

Page 62: QTP Unplugged 2nd Edition Updates eBook

405

Update  from  Local  Object  Repository  

cal  Repository…  in  the  menu  and  click  on  the    button  to  select  the  test.  Once  the  test  is  selected  the  dialog  shows  all  the  Actions  available  in  the  test

Figure  29-­36.  Update  OR  from  Local  Object  Repository

NOTE: Multiple tests can be selected in the Update from Local Repository dialog.

NOTE: Only those Actions from the test can be added to list which have the SOR associated in the tests. So if a Test has two actions: Action1 and Action2, but the current SOR is only associated with Action1 then the dialog would only show Action1 and not Action2.

NOTE: Repositories for a Test which is currently open in QTP IDE cannot be merged without closing the test.

Clicking  on  the  Update  All…  button  shows  the  Merge  window  and  Merge  results

Page 63: QTP Unplugged 2nd Edition Updates eBook

406 QuickTest  Professional  Unplugged

Figure  29-­37.  Object  Repository  Merge  Results

Figure  29-­38.  Object  Repository  Merge  tool

Page 64: QTP Unplugged 2nd Edition Updates eBook

407

Click  on  the    button  to  save  the  merge  and  move  to  the  next  merge.  The  merge  dialog  will  ask  for  

  WARNING: The merge process deletes all the objects from the LOR of chosen scripts. Only those actions get impact which were shown in the Update from Local Object Repository Dialog.

resolution  would  either  to  take  the  description  from  LOR  or  SOR  or  Keep  both  the  objects  

Page 65: QTP Unplugged 2nd Edition Updates eBook

408 QuickTest  Professional  Unplugged

Duplicate  Objects  -­  In  this  case  a  duplicate  object  exist.  The  resolution  would  be  either  to  keep  the  LOR  or  SOR  object  or  both  the  objects

WARNING: Choosing ‘Keep both objects’ option could mean that your scripts may not work as the object description would have changed. In case the number of scripts used by a shared object repository is high the merge process should be avoided as the logical name changes during the merge process can break the scripts.

Object  Repository  Merge  tool

Object  Repository  Merge  tool  allows  merging  multiple  object  repositories  into  one.  To  launch  the  tool  

2  object  repositories  to  be  merged  and  press  Ok.  Merge  tool  shows  the  merged  repository  and  if  there  

Figure  29-­42.  New  Object  Repository  merge

Page 66: QTP Unplugged 2nd Edition Updates eBook

409

NOTE: One huge disadvantage of the merge process is that the merge

So in case we want to merge 10 object repositories, we will have to save merged OR to new OR every time and then use it as a primary OR for the next merge. This poor design of merge process makes it impractical to use such approach in real projects.

NOTE: In case of merge the object are NOT delete from the

NOTE: Checkpoints can never be added directly in a SOR. They can only be imported through a direct merge or indirect merge from local object repository.

Object  Repository  Comparison  Tool

Object  Repository  Comparison  tool  can  be  used  to  compare  two  object  repositories.  To  launch  the  

Shows  the  “New  Comparison”  dialog

Figure  29-­43.  Object  Repository  Comparison

Shows  comparison  stats

Page 67: QTP Unplugged 2nd Edition Updates eBook

410 QuickTest  Professional  Unplugged

Figure  29-­44.  Comparison  Statistics

Comparison  Results

Figure  29-­45.  Object  Repository  comparison  results

Page 68: QTP Unplugged 2nd Edition Updates eBook

411

Local  OR  Vs  Shared  OR

LOR  versus  SOR  has  always  been  huge  topic  of  discussion.  LORs  can  be  used  in  cases  where  the  test  

also  be  used  in  cases  of  use  and  throw  scripts.  Ex  –  Data  creation  scripts  which  are  only  used  once  

simple  one  can  go  for  recording  and  use  the  LOR.  

Object  SpyThe  QTP  11  Object  Spy  displays  test  object  properties  when  the  mouse  cursor  is  placed  over  a  GUI  object.  This  allows  interrogating  multiple  objects  in  a  single  spying  session  by  just  pointing  the  cursor  at  the  objects  of  interest.  QTP  11  also  introduced  few  new  features  in  Object  Spy  which  allows  adding  the  object  directly  from  the  Spy  window  to  the  Object  Repository  as  shown  in  Figure  29-­46.  

clipboard.  

NOTE: The properties.

NOTE: Sometimes QTP does spy the object through Object Repository Add Object button but doesn’t add the object to the OR. In such a case one should try adding the object directly from the Object Spy.

Page 69: QTP Unplugged 2nd Edition Updates eBook

412 QuickTest  Professional  Unplugged

Figure  29-­46.  Objects  Spy  Add  to  OR  and  Copy  feature

Page 70: QTP Unplugged 2nd Edition Updates eBook

A-1

Appendix A

Problem  3-­1.  Working  with  Test  Object  properties. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .22

Problem  3-­2.  Changing  Test  Object  properties  at  run  time. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .23

Problem  3-­3.  Getting  Run-­time  Object  properties  during  test  execution.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .23

Problem  4-­1.  How  to  access  a  parameter  from  the  global  data  sheet.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .38

Problem  4-­2.  How  to  access  a  parameter  from  a  Local  data  sheet.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .39

Problem  4-­3.  How  to  check  if  a  Sheet  exists. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .39

Problem  4-­4.  How  to  preserve  format  of  data  output  to  a  data  table..  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .39

Problem  4-­5.   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .39

Problem  4-­6.  row  of  the  data  table  contains  the  columns  heading.  We  then  add  those  as  parameters  of  the  data  table:.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .39

Problem  4-­7.      .  .  .  .  .40

Problem  4-­8.  How  to  execute  a  script  for  all  Global  Data  Table  iterations,  when  the  script  is  set  to  run  for  only  one  iteration:.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .41

Problem  4-­9.  How  to  get  the  number  of  columns  that  contain  data:. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .41

Problem  6-­1.  How  to  access  an  environment  variable?..  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .53

Problem  6-­2.  How  can  we  check  if  an  environment  variable  exists?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .53

Problem  6-­3.   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .53

Problem  6-­4.      .  .  .  .  .  .  .  .  .  .  .  .  .54

Problem  6-­5.  How  are  QTP  record  and  run  settings  changed  using    Environment  variables?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .55

Page 71: QTP Unplugged 2nd Edition Updates eBook

A-2

Problem  6-­6.  How  is  an  environment  variable  cleared  or  destroyed?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .57

Problem  6-­7.  How  an  object  is  passed  using  an  environment  variable?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .57

Problem  6-­8.  How  an  array  is  passed  using  Environment  variables?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .58

Problem  6-­9.      .  .  .  .  .  .  .  .58

Problem  8-­1.  How  can  we  check  if  a  checkpoint  passed  or  failed?..  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .70

Problem  9-­1.      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .78

Problem  12-­1.  How  can  we  get  the  status  of  an  Action  as  Pass/Fail  at  the  end  of  the  action?.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .108

Problem  13-­1.  What  will  the  regular  expression  be  for  a  domain  which  can  have    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .120

Problem  13-­2.  What  will  be  the  r.e.  matching  a  date  in  the  format  MM/DD/YY?.    .  .  .  .  .  .  .  .120

Problem  14-­1.  “Page  4  of  15”?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .131

Problem  14-­2.  How  can  we  count  the  number  of  “if”  phrases  in  the  “if  +  if  =  2  if”  string?.   131

Problem  14-­3.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .133

Problem  14-­4.  current  page  and  the  total  page  values  from  the  string  “Page  4  of  15”?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .134

Problem  14-­5.  How  can  we  split  a  string  into  words  or  lines?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .135

Problem  14-­6.  How  can  the  number  of  business/working  days  be  calculated  between  two  dates  (i.e.  difference  should  exclude  the  weekends)?  .    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .139

Problem  14-­7.   .  .  .  .  .  .  .  .  .  .  .142

Problem  14-­8.  Function  to  get  a  substring  from  a  start  character  in  a  string.  . .  .  .  .  .  .  .  .  .  .  .  .143

Problem  14-­9.  Write  a  function  that  reads  a  string  word  by  word  where  two  words  would  be  separated  by  one  or  more  spaces..    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .144

Problem  14-­10.  Create  a  function  TrimAll  which  trims  not  only  spaces  but  other  whitespace  characters  like  new  lines,  carriage  returns,  and  line  feeds  etc.:.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .144

Problem  14-­11.  Create  a  FilterStr  function  which  takes  a  string  and  character  set  as  input  and      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .145

Problem  14-­12.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .146

Problem  14-­13.  Write  a  function  that  compares  two  string  ignoring  new  line,  line  feeds,  tab  etc.  whitespace  characters:.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .147

Problem  14-­14.  Write  a  function  that  replaces  repeated  occurrences  of  a  given  character  by  

Page 72: QTP Unplugged 2nd Edition Updates eBook

A-3

another  character.  . .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .147

Problem  14-­15.  How  can  we  get  the  UBound/LBound  values  of  multi-­dimensional    array?..  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .149

Problem  14-­16.  How  can  we  declare  and  initialize  a  read  only  variable  at  run-­time?.    .  .  .  .  .150

Problem  17-­1.  How  can  we  determine  if  the  topmost  window  on  the  desktop  is  a  browser  window?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .178

Problem  17-­2.  How  can  we  get  the  value  of  a  Windows  Environment  variable?  (Note  that  QTP  environment  variables  differ  from  Windows  environment  variables)...  .  .  .  .  .  .  .  .  .  .  .  .178

Problem  17-­3.  How  can  we  check  (select)  an  item  in  a  List  box  using  a  Windows  API?. .  .  .178

Problem  17-­4.  How  can  we  get  the  background  color  of  a  text  box  (helpful  when  a  color  for  a      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .179

Problem  17-­5.  How  can  we  simulate  a  keyboard  event  using  the  Windows  APIs?..  .  .  .  .  .  .  .179

Problem  17-­6.  How  can  we  prevent  a  PC  from  being  locked  by  its  screen  saver?.  .  .  .  .  .  .  .  .181

Problem  17-­7.  How  can  we  maximize  a  window  or  a  browser?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .182

Problem  17-­8.      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .182

Problem  18-­1.  How  can  we  use  AOM  to  run  a  QTP  test  case?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .195

Problem  18-­2.  How  can  we  use  AOM  to  change  the  starting  and  ending  iterations  for  a  test  case?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .196

Problem  18-­3.  How  can  we  use  AOM  to  launch  QTP  on  a  remote  machine?..  .  .  .  .  .  .  .  .  .  .  .198

Problem  21-­1.   .  .  .  .  .  .  .  .  .238

Problem  21-­2.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .239

Problem  21-­3.  How  can  we  create  the  following  XML  code  at  run-­time  in  QTP,  and  then  save      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .239

Problem  21-­4.   .  .  .  .  .  .  .240

Problem  21-­5.      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .242

Problem  21-­6.  How  can  we  export  a  part  of  XML  to  a  DataTable?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .243

Problem  21-­7.  How  can  we  extract  XML  from  a  URL  or  Web  browser?.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .244

Problem  21-­8.   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .244

Problem  21-­9.   .  .  .  .  .  .244

Problem  22-­1.   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .252

Problem  22-­2.  How  can  we  determine  the  number  of  rows  altered  by  an  update  or  a  delete      .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .254

Page 73: QTP Unplugged 2nd Edition Updates eBook

A-4

Problem  23-­1.  How  can  we  invoke  and  terminate  an  instance  of  Excel?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .260

Problem  23-­2.  How  can  we  create  a  new  excel  sheet  and  then  save  it?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .260

Problem  23-­3.    how  to  create  one?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .261

Problem  23-­4.   .  .  .  .  .  .  .262

Problem  23-­5.  row?..  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .262

Problem  23-­6.  How  can  we  use  an  Excel  sheet  as  a  QTP  output  Data  Table?.    .  .  .  .  .  .  .  .  .  .  .263

Problem  23-­7.   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .264

Problem  23-­8.  How  can  we  access  an  Excel  spreadsheet  embedded  in    Internet  Explorer?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .268

Problem  25-­1.  How  to  instantiate  and  terminate  a  word  application?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .292

Problem  25-­2.  How  to  get  reference  to  an  already  open  word  application?.    .  .  .  .  .  .  .  .  .  .  .  .  .292

Problem  25-­3.  How  to  enumerate  all  the  open  word  documents?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .292

Problem  25-­4.  How  to  open  and  save  a  new  document  in  word?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .293

Problem  25-­5.  How  to  get  reference  toan  already  existing  word  document?.    .  .  .  .  .  .  .  .  .  .  .  .293

Problem  25-­6.  How  to  open  a  word  document  in  the  read  only  mode?..  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .294

Problem  25-­7.  How  to  print  an  open  word  document?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .294

Problem  25-­8.      .  .  .  .  .  .  .294

Problem  25-­9.  How  to  insert  an  image  in  a  word  document  and  scale  its  size  by  50%?..  .  .  .295

Problem  25-­10.      .  .  .  .  .  .  .  .  .  .  .  .  .  .295

Problem  25-­11.    How  to  insert  a  table  into  a  word  document?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .296

Problem  25-­12.  How  to  change  the  font  for  the  text  being  written  in  a    word  document?.    .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .297

Problem  25-­13.  How  to  preserve  the  text  already  present  in  a  word  document    while  writing?. .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .298

Page 74: QTP Unplugged 2nd Edition Updates eBook

B-1

Appendix B: Index

AActions 43

Input and Output Parameters 43Insert Call to Copy… 49Insert Call to Existing… 48Insert Call to New… 47

actionsspath 349AddAttachment 337AddParameter 40–41AddSheet 40ADODB.Command 249,  253,  255ADODB.Connection 249ADODB.Recordset 249,  252Advanced Text Checkpoints 354API using COM Objects in VB6 182API using Excel 185ApplyXSL 245Array 134Asc 137Automation Object Model (AOM) 195

BBrowser Vs Page Sync 159

CCBool 137CByte 137CCur 137CDate 137Check 70CheckBrokenImages 320Checkpoints

Alternatives to QTP checkpoints 71Types of checkpoints 69Updating Checkpoints at run-time 71

ChildObjects 86Chr 138CInt 137CleanBrowserPopups 316CleanText 147CLng 137CloseDescendentProcesses 65CloseProcessByHwnd 65CloseProcessById 65CloseProcessByName 65CloseProcessByWndTitle 65Comparing XML 244Converting a DOM object to QTP Test Object 208Converting VBA to VBScript 264CreateDescription 85CreateObject 142CreationTime 90Crypt Object 61CSng 137CStr 137CurrentRun 329currentStyle 209CurrentTest 329CurrentTestSet 329CurrentTestSetTest 329

DDatabase 249DataTable 33

Page 75: QTP Unplugged 2nd Edition Updates eBook

B-2

Data table formatting 38Data table object model 38Design time data table 35Run-time data table 35Setting data table iterations 36When to use the global or a local data table 35

Date 138DateDiff 139Day 138Debugging 97

Using Breakpoints 98Working with the Command Tab 100Working with the Variables Tab 99Working with the Watch Expression Tab 98

DefaultObjRepType 349DefaultTSRFilePath 349Descriptive programming 83

Property 93

Converting an OR-based script to a DP-based script 87Enumerating ChildObjects 86Implicit Properties 84

Using a VBScript DP object repository 89Using description objects 84Using Description Strings 86When to use Descriptive Programming 84Working with Multiple Browser 92

Desktop.CaptureBitmap 170DisableReplayUsingAlgorithm 348Document Object 203DotNetFactory

Accessing the Registry 420Converting Images to other File Formats 424Evaluating Keyboard Control Key Status 420Getting Computer Information 419Getting user Input using .NET Forms 426.Net Arrays Revisited 421Passing Enums 417Passing Parameters to Class Constructors 415Passing Parameters to .NET Objects 416Ping an IP Address 420Playing a Wav File 419Sending Emails using .NET 423Using the DotNetFactory Object 415

Working with .NET Arrays 418Working with .Net Date and Time Formatting 422Working with .Net Queues 422Working with .Net Stacks 421Working with the Clipboard 419

DownloadAttachments 335Dynamic Arrays 148

EEncrypt 61EnumerateAllTestSets 340EnumerateAllTestsinTestPlan 339EnumerateSettings 347Environment variables

BROWSER_ENV 55ExternalFileName 52LoadFromFile 52URL_ENV 55Value 52

Error Handling 113Eval 150Excel.Application 142,  187,  188,  260,  264,  353,  359Excel Automation Object Model 259Execute 57,  85,  149ExecuteFile 76ExecuteFileGlobal 77ExecuteGlobal 78ExecuteGlobalCode 78Executing a Stored DB procedure 255Executing code when Script ends 352Exist 159ExitAction 45Exporting XML to a DataTable 243Extend 362extendWebTable 362ExternalDataTablePath 348Extern.Declare 177Extern object 177

FFilter 137FilterStr 145FindAttachment 334FindWindow 190FindWindowEx 190FireEvent 160FirstGlobalIteration 348Fixed length arrays 148

Page 76: QTP Unplugged 2nd Edition Updates eBook

B-3

GGenericSet 66GetAddressesFromMail 285GetBusinessDays 140GetColumnName 271GetCurrentTestPath 338GetCurrentTestSetPath 341GetCursorPos 185GetDC 179GetDOMObjectByPath 211getElementsById 204getElementsByName 204getElementsByTagName 204GetEnvironmentVariable 178GetFileName 146GetFilePath 146GetForegroundWindow 177,  178GetIECOMByhWnd 305GetIECOMByURL 305GetIEObjectFromhWnd 268GetObject 142GetParameter 40GetParentOfElement 224GetPixel 179GetRandomNumberByLen 306GetROProperty 14,  23GetRowCount 41GetSheet 39GetSMTPAddress 286GetStrBetweenChar 143GetStrFromChar 143GetSubFolderByPath 277GetTOProperties 22GetTOProperty 23GetVarXML 54GetWindowDC 179GetWordFromPos 144GlobalIterationMode 348GlobalSheet 38

HHex 138Hour 138HowManyWeekDays 139HTML Button 205HTML Checkbox 206HTML ComboBox 205HTML Element Collection 203

HTML Element Object 203HTML Link 205HTML List Box 205HTML Node 202HTML Radio Button 206HTML Table 207HTML Text Box 205

IIEDownloadFile 318InStr 130InStrRev 132Internet Explorer 301

EnumerateIE 304Popup Blocker 311Using IE to get user input 308

InternetExplorer.Application 302,  303,  307IsConnected 328IsEnvExist 53isParameterExists 39

JJoin 134JScript 363

Passing variable number of arguments to a function 364Scope differences 364Try…Catch block 365Working with JS classes 366Working with JScript Arrays 366

Kkeybd_event 179KeyDown 180KeyPress 180KeyUp 180

LLastGlobalIteration 348launchreport 349Lcase 129Left 130Len 130

Associating a Library globally with a Test 75Dynamically Loading libraries locally at run-time 76,  79

LoadFromFile 58LocalSheet 39

Page 77: QTP Unplugged 2nd Edition Updates eBook

B-4

LTrim 133LTrimW 126

MMakeObjVisible 354MapVirtualKey 179micclass 86Mid 130Minute 138Modal dialog boxes 190Month 138

NNewSync 317Now 138

O,  83

Object Spy 25ObjRepType 348Oct 138On Error Resume Next 113OnReplayError 348Open Test Architecture (OTA) 330Optional arguments in VBScript 150

Using an Array of (Key, Value) pairs 152Using an Array of Key:=Value pairs 153Using an Array of values 151Using Null/Empty values 150

OptionalStep Object 62Outlook.Application 276Outlook Object model 275Outlook Security Dialogs 282

PPathFinder.Locate 63,  336PathFinder Object 62PostMessage 190

QQCUtil Object 328Quality Center 325

ResolveRelativePath 327QuickTest.Application 174,  195,  198,  331,  343,  344,  

351

RRandomNumber Object 63Recovery_LoginProxy 109Recovery object 111

RegExp 123RegisterUserFunc Object 66RegularExpression 23Regular Expressions 117ReleaseDC 179Replace 133ReplaceMultipleByOne 147ReplayType 162Reporter.Filter 166Reporter.LogEvent 172Reporter.ReportEvent 167Reporter.ReportPath 170rfDisableAll 166rfEnableAll 166rfEnableErrorsAndWarnings 166rfEnableErrorsOnly 166Right 130RTrim 133RTrimW 125RunAction 45

SScripting.Dictionary 77,  154,  155,  172,  175,  263,  

304,  355,  360Scripting.FileSystemObject 54,  167,  173,  174,  175,  

246,  261,  335,  351,  353,  439Seconds 138SelectRadioByTextIndex 212SendMessage 178SetActiveWindow 190SetCurrentRow 40,  41SetForegroundWindow 179SetSecure 62Setting Object 63SetTOProperty 23ShowWindow 182SnapshotOnErrorActiveUI 348SnapshotReportMode 169Space 134Split 134SplitEx 135StopAndReRunQTP 350StrComp 129String 134StrReverse 130Sync 157Synchronization Points 157SystemUtil Object 65

Page 78: QTP Unplugged 2nd Edition Updates eBook

B-5

SystemUtil.Run 92

TTDAPIOle80.TDConnection 332TDConnection 328,  330Test Arguments 197Test Results 165

Accessing Test Results at the end 173

Converting XML Results to HTML 170Inserting Files in Test Results 167Inserting Snapshots in Test Results 168

Time 138Timer 140Trim 133TrimAll 144TrimW 126TSRFilePath 349TypeName 141

UUBound 149Ucase 129URLDownloadToFile 182UseExternalDataTablePath 348Useful Tools 443

IE WebDeveloper 447Internet Explorer Session Cookies 447Notepad++ 444QTP Script Editor 443QTP Uninstaller 445RAD Regular Expression Designer 450ScreenCapture API 446Test Design Studio (TDS) 449VB 2 QTP API Converter 447VBSEdit 444

VValueByRow 40VarType 141

WWait 158WaitProperty 158WebRegSelectValue 124Web Tables 217

Access using OR 222Asynchronous Table loading 229

Clicking inside a WebTable 227Exporting WebTable to a DataTable 229Finding a cell in a Table 231FindTextBySearch 232GetTableFromElement 225Getting a QTP Table from a element 230Getting the location of an object inside the table 225GetWebTableFromElement 230Using an object inside the table 224Using Index 219Using innerText/outerText 219Using Name or HTML ID 219

WebUtil Object 65Weekday 139WScript.Shell 174,  189,  193,  288,  301,  311,  315,  

351,  439,  440

XXMLAttribute 238XML Attributes 238XMLAttributesColl 238XML Child nodes 238XMLData 238XMLElement 238XMLElementsColl 238XMLItemColl 238XML Node values 238XML Root node 237XMLUtil 238XMLUtil.CreateXML 238XMLUtil.CreateXMLfromFile 239

YYear 138

Page 79: QTP Unplugged 2nd Edition Updates eBook

And I thought I knew QTP!

How   many   times   have   you   wished   that   there   was  somebody  who  could  clear  some  niggling  doubts  about  

to-­grasp  concepts  and  smart  workarounds?  Or  show  you  some  of  the  lesser  known  features  of  QTP?  

Written   by   the   author   of   the   best   selling  QTP   book   –  “QuickTest   Professional   Unplugged”,   this   book   does  just  that  in  a  gripping  story  that  will  make  you  turn  every  page  in  anticipation.  “And  I  Thought  I  knew  QTP!  –  QTP  Concepts  Unplugged”  is  ‘different’   in  the  way  it  seeks  to   explain   the   various   concepts   through   an   interesting  and  innovative  story-­telling  style  (which  is  rarely  used  for   technical   books).   Instead   of   following   a   textbook  format,  this  book  is  more  like  a  technical  novel.  

Whether  it  is  to  brush  up  your  QTP  concepts  or  simply  to  satiate  your  curiosity  about  how  a  seasoned  IT  veteran   fared   in  a  no-­holds-­barred   ‘intellectual  duel’  on  QTP  –  whatever  your   reason   to  pick  up  this  book,  it  is  sure  to  leave  you  astounded  with  its  pace  of  narration,  expertise,  and  breadth  of  topics  covered.

ISBN:  978-­0-­9836759-­0-­7

For  more  details,  please  visit  KnowledgeInbox.com/books

Page 80: QTP Unplugged 2nd Edition Updates eBook

About the Author

named   “QuickTest   Professional  Unplugged”.  He   has  worked   on   various   automated   testing   projects  utilising  technologies  like  VBScript,  VB6,  VB.Net,  C#.NET,  Excel  and  Outlook  Macros.  He  founded  KnowledgeInbox.com  —  a  blog  targeted  towards  the  QuickTest  community.  He  uses  the  blog  to  share  his   custom  APIs,   products,   articles,   tips   and   tricks  with   his   readers   pro   bono.  He   is   also   a   regular  contributor  at  AdvancedQTP  and  SQA  forums.  Tarun’s  work  has  been  showcased  on  several  websites  such  as:

RelevantCodes.com

AdvancedQTP.com

Tarun  was  awarded  with  the  ‘Best  Feedback  Award’  by  HP  for  QTP  11  Beta  testing.  His  book  “QuickTest  Professional  Unplugged”  was  recognized  as  the  Best  Automation  Book  in  the  2nd  ATI  Automation  Honors  award.   It   is   the   industry’s   original   set   of   awards  dedicated   to   software   test   automation   recognizing  industry  leading  tools,  resources  and  practitioners.  The  ATI  Automation  Honors  awards  rely  on  industry  

upgrades   and/or  which   are   setting   the   trends   that  will   help   to   take   software   test   automation   to   the  next  level.

Tarun  can  be  reached  through  any  of  the  below  links:

KnowledgeInbox.com/contact-­us

LinkedIn.com/in/tarunlalwani

Page 81: QTP Unplugged 2nd Edition Updates eBook