QTP Descriptive Programming Unplugged Book

18,704 views

Published on

QTP Descriptive Programming Unplugged is an in-depth reference and guide on using HP QTP Test Objects. A must-have for every user, from beginner to expert, this comprehensive book will help you to master a range of Object Identification techniques in QTP. Written by two seasoned QTP experts – Anshoo Arora and Tarun Lalwani – the book discusses and demonstrates both basic and advanced topics and is presented in a clear and easy-to-follow format. With this book, you will learn about:
- Object Identification
- Object Repository (Shared and Local)
- Descriptive Programming
- Visual Relation Identifiers
- ChildObjects
- HTML DOM
- Internationalization Testing
- CSS- and XPATH-based Identification
- Web Services
- Writing QTP Scripting in .NET
- Web Extensibility and much more…

About Authors

Anshoo Arora:
Anshoo Arora is a Test Architect and Software Developer, best known for his Test Automation website, www.RelevantCodes.com. He is continuously researching to find better ways of working with QTP, simplifying automation maintenance and creating extensible test suites/frameworks. A regular contributor at AdvancedQTP and SQAForums, he is also the Technical Editor and Reviewer of QuickTest’s first conceptual book, ‘And I thought I knew QTP!’

Tarun Lalwani:
Tarun Lalwani is a Test Automation and Solutions Architect and the author of the two most widely read books on QTP, the award-winning ‘QuickTest Professional Unplugged’ and ‘And I Thought I knew QTP!’ As well as working on various automated testing projects, he is the Founder of KnowledgeInbox, a company focused on the research and design of Automation products, as well as providing Test Automation services and consultation.

Published in: Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
18,704
On SlideShare
0
From Embeds
0
Number of Embeds
63
Actions
Shares
0
Downloads
1,355
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

QTP Descriptive Programming Unplugged Book

  1. 1. Bo ok Pr ev ie w
  2. 2. http://KnowledgeInbox.com/store/ w ie QTP Descriptive ev Programming Unplugged Pr by Anshoo Arora and Tarun Lalwani ok Bohttp://KnowledgeInbox.com/store/
  3. 3. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ QTP Descriptive Programming Unplugged Publisher: KnowledgeInbox Author: Anshoo Arora & Tarun Lalwani Editor: Vicki Watson ISBN: 978-0-9836759-2-1 © 2012 KnowledgeInbox. All rights reserved. Printing History: Nov 2012: 1st Edition 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, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per- w copy fee to the KnowledgeInbox. Contact online at KnowledgeInbox.com/contact-us/ ie author/publisher by including the below reference comment header. ev Source code taken from "QTP Descriptive Programming Unplugged" By Anshoo Arora & Tarun Lalwani Pr Download source from KnowledgeInbox.com/demos/QTPDPUnplugged_SourceCodes.zip Website: KnowledgeInbox.com/books/qtp-descriptive-programming-unplugged/ This document also contains registered trademarks, trademarks and service marks that are owned by ok their respective companies or organizations. Publisher and the author disclaim any responsibility for specifying which marks are owned by which companies or organizations. Bo LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRE- SENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WAR- RANTIES 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 PUB- LISHER 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 PRO- VIDE 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. ii http://KnowledgeInbox.com/store/ii
  4. 4. http://KnowledgeInbox.com/store/ About the AuthorsAbout Tarun Lalwani Tarun Lalwani is a Test Automation and Solutions Architect and the author of the two most widely-read books on QTP, ‘QuickTest Professional Unplugged’ and ‘And I Thought I knew QTP!’. He has worked on various automated testing projects, utilizing technologies such as VBScript, VB6, VB.Net, C#.NET, Excel and Outlook Macros. Tarun is the founder of Test Automation Research and Labs (TARLABS); a company focused on Test Automation Products and Services. He is also the owner and lead author for wKnowledgeInbox; a blog and publication house focused on Test Automation. Tarun was ieawarded with the ‘Best Feedback Award’ by HP for QTP 11 Beta testing and his book‘QuickTest Professional Unplugged’ was named the Best Automation Book in the 2nd ATI evAutomation Honors awards. A regular contributor on AdvancedQTP and SQA forums,Tarun’s work has been showcased on several websites, including www.relevantcodes.comand www.advancedqtp.com. PrIn Dec 2011, HP invited Tarun to its R&D center in Israel for a 4 day conference. Theconference was aimed on taking his feedback on various aspects of QTP & BPT. This okinvitation highlights HP’s interest in getting the user community involved in enhancing Botheir tools.Tarun can be contacted at www.linkedin.com/in/tarunlalwani orwww.knowledgeinbox.com/contact-us. iii iiihttp://KnowledgeInbox.com/store/
  5. 5. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ About Anshoo Arora Anshoo Arora is an author, Test Architect and software developer, best known for his Test Automation website, www.relevantcodes.com. He is continuously researching to maintenance and creating extensible test suites/frameworks. Apart from QTP, he also works with Quality Center, LoadRunner, .NET programming, Selenium WebDriver, TestComplete and Web Technologies. Anshoo is a regular contributor at AdvancedQTP and SQAForums and is also the Technical Editor and Reviewer of w Write to him at anshoo@relevantcodes.com or visit his website Relevant Codes at ie http://www.relevantcodes.com. ev Pr ok Bo iv http://KnowledgeInbox.com/store/iv
  6. 6. http://KnowledgeInbox.com/store/ Dedication w ie ev PrOur vision for this book is to share our knowledge and experience with the QTP community. okIt is a privilege for us to write this book and we hope that it will reach QTP Engineers acrossthe globe. But not everyone in this world has the same advantages, let alone the blessingof education. Millions of children around the world today live life without hope of meeting Botheir most basic needs, without any education, and without the promise of a brighter future.Education empowers. Education inspires. Education can help to lead the way out of poverty,and provide the tools to guide the less fortunate towards a better life.By purchasing this book, you will help a child break free from the cycle of poverty and giftthem a future full of hope. For each copy sold, we will donate 10 to organizations workingtowards the worthy cause of child education. Help us to learn and foster learning. vhttp://KnowledgeInbox.com/store/
  7. 7. http://KnowledgeInbox.com/store/ AcknowledgementsFrom Tarun LalwaniI actually started writing this book before my second book ‘And I thought I knew QTP’,to be my third book. Finally getting back to this book with another year of experience,however, meant even more polished content. This book has involved a lot of researchand experimentation with different approaches and has therefore proved even more time–consuming. This, however, means more polished content and greater attention to detail.I would like to thank Anshoo for accepting my request to co-author this book. He is one of wi.e. to share our knowledge with the Automation community. ieI would also like to thanks my family members who have always been there to support me evduring the writing process and even after publication. PrFrom Anshoo Arora okI would like to thank all my clients and colleagues for trusting in me and for giving me theopportunity to work with them. BoA huge credit goes to Tarun, who has always strived for a better QTP community byconstantly helping thousands of people over this course. Writing this book with him hasbeen an incredible experience and a lot of fun.I am grateful to everyone who visited and provided their feedback at Relevant Codes; itwas their comments and encouragement which drove me to create the content that existstoday.support; nothing would have been possible. viihttp://KnowledgeInbox.com/store/
  8. 8. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ About the Editor Vicki Watson is a writer, editor and book designer whose publications have ranged from business books, teacher resource guides and parental handbooks to children’s workbooks and poetry. After a career as a teacher and deputy headteacher, she decided to focus on her love of language and design and set up Callisto Green, a vibrant and dynamic writing and design venture and small publishing imprint. When she’s not scribbling in her notebook, her many interests include playing the clarinet, rock-climbing, stargazing and playing chess. w Vicki can be contacted by emailing vicki@callistogreen.com or through her website at ie ev Pr ok Boviii http://KnowledgeInbox.com/store/
  9. 9. http://KnowledgeInbox.com/store/ Foreword by Meir Bar-TalWhen Tarun Lalwani and Anshoo Arora asked me to assist in the review of this book,Automation; whose contribution to the worldwide community is immeasurable. So, thoughthe time schedule was tight, I undertook the challenge to make my humble contribution to wthis impressive project. ieAll through my reading I felt that QTP Descriptive Programming Unplugged is one of thesebooks which make you think: “I wish I had this reference available in my last project”. evWith this third book in Tarun Lalwani’s QTP Unplugged series, now co-authored by ourProfessional is handed to the Automation Developer like a cookbook. PrThe book, which could have been easily split into two volumes, leads the reader from theEngineer, to the practical solutions which are the fruit of a sound and thorough research. All okthese are accompanied by well suited real-life, easy to grasp and well annotated examples.The book is an extensive in-depth compilation with an emphasis on testing Web applications. BoIt covers both GUI and SOA automation, and it tackles many misconceptions and pitfallsensure that understanding does not remain only at the theoretical, conceptual level.To me, QTP Descriptive Programming Unplugged marks a very important event in theannals of automation knowledge. I am sure that the readers of this book will acquire skillsthat are rarely taught in QTP courses, and it will serve them as a reference and practicalguide.I wish to thank Tarun and Anshoo for giving me the opportunity to have a privilegedglimpse into their colossal work and wish you the reader an enjoyable and fruitful journey. ixhttp://KnowledgeInbox.com/store/
  10. 10. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ Automation Architect, AdvancedQTP * Meir Bar-Tal is an Automation Architect with over 12 years of technical, educational and leadership experience in Software Design, Development and Testing. Meir has helped companies establish solid foundations for their testing activities with a wide variety of software applications and systems and across different technologies and automation framework named Sunscrit, a huge project which is still underway. Meir is the owner of www. . w ie ev Pr ok Box http://KnowledgeInbox.com/store/
  11. 11. http://KnowledgeInbox.com/store/ Foreword by Colin W. Fries wI was keen to develop a working QTP skillset as quickly as possible. Interestingly enough,one of the things also driving this interest was that I was thrust into a situation where I was iethe automation expert, even though everyone above and around me knew that I knew aboutas much about the topic as they did. Nonetheless, I was expected to produce a working set evof automated test cases as to reduce the manual testing burden of the QA team. Prmy position would have done – I asked for (and received) vendor training. I spent a weekup my sleeve. But despite taking the basic and advanced courses, there were still a lot of okquestions and problems with our test suite that needed to be ironed out. BoTarun was already a seasoned expert in the test automation space and was particularlyadept at straightening out noobs such as myself. Over the years, he has answered hundredsof questions from the masses (I include myself here) and has given priceless advice andinsight on everything from resolving syntax errors to developing automation frameworks.Because of Tarun’s advice, the issues affecting us were resolved and we were able to createa working automated testing framework.had, at that point, recently acquired from Mercury. So I joined the chapter and eventuallybecame one of its leaders. It was through this avenue that I came to know the other author xihttp://KnowledgeInbox.com/store/
  12. 12. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ and we began collaborating on bringing them in to present at a chapter meeting. I then instantly knew that the audience would be in for a treat when he gave his presentation and that his employer was lucky to have such a swell guy like him working for them. When he mentioned that he was collaborating with Tarun for the next installment of the QTP Unplugged series, I could hardly contain my excitement. After all, nothing excites a techie more than a new deep dive into his or her favorite tool, right? I received word from Anshoo that Tarun was going to be at the conference. Anshoo offered to facilitate an introduction, and of course, I jumped at the opportunity. It was a pleasure to w So what does this have to do with the book you’re about to read and reference for the foreseeable future? When I met with Anshoo and Tarun, I realized that both of these men ie are passionate about their trade, and that their passion for test automation doesn’t stop at the end of the business day. In talking to them, it quickly became apparent that they wanted ev to share what they’ve learned about this tool and its inner workings with their peers. After several years and a diversion or two, they’ve accomplished their goal by publishing this Pr experience writing or maintaining test automation frameworks in that it allows them to ok respond to the challenges of test automation against modern software applications. After reading this book, I hope you will come to the same conclusion. So enjoy; I’m sure that Bo Quality Assurance Engineer III, Gateway EDI Vivit Board of Directors, Secretary years and has extensive experience in writing, maintaining, and expanding upon Data-Driven, Keyword Driven the past several years, Colin has been both a chapter leader and a member of the Board of Directors for Vivit. In this capacity, he has strived to provide education, community, and advocacy for its members. In his spare time, Colin enjoys running, cycling, researching test automation, and spending time with his wife and childrenxii http://KnowledgeInbox.com/store/
  13. 13. http://KnowledgeInbox.com/store/ Foreword by Christopher J. ScharerBefore writing the foreword to this book, I read it in its entirety, and although its contentbecomes increasingly more technical, each chapter builds on the previous one andincludes several real-life examples. This book is very well written and made me become wmore interested the further I read. This book is focused toward conceptual knowledge ofQuickTest Pro (QTP) with a deep dive into Descriptive Programming (DP). It is a must- iehave for anyone who is testing using QTP and complements Tarun’s previous books, evcompanies moving to an Agile development/testing approach and application developersworking side-by-side with automation engineers, it is becoming more common and evenmore important for an automation engineer to understand how to use DP. PrWith all the recent game changers in the IT industry, such as Cloud computing, Big Data,I really look forward to the next book that Tarun and Anshoo are working on currently, okwhich I believe is going to focus on testing methodologies and frameworks. I also hope tobe able to coordinate with them both to include a section on using Code Templates BoDirector (Vice President), Iowa, Nebraska & TQA-SIG Chapter LeaderVivit Worldwide (http://www.vivit-worldwide.org)* Christopher J. Scharer is an IT leader with over 15 years of technical experience in both the SoftwareDevelopment and Software Testing Lifecycles and Application Lifecycle Management (ALM). Christopher xiiihttp://KnowledgeInbox.com/store/
  14. 14. http://KnowledgeInbox.com/store/ ContentsPreface ............................................................................................ xxiii Who this Book is For ............................................................................................... xxv Questions or Feedback Related to the Book ............................................................ xxv Source Code in the Book ......................................................................................... xxv1. Introduction to Objects ..................................................................12. Object Repository .........................................................................11 .................................................................................... 15 Local Object Repository (LOR) ................................................................................ 16 w Shared Object Repository (SOR)............................................................................... 18 ....................................................................................... 20 ie ...................................................... 20 ........................................................................... 20 ev .................................................................. 22 ................................................................................................... 23 Pr Other Object-Related Features of OR........................................................................ 25 ................................................................................. 27 ......................................................... 27 ok ........................................................................ 28 .................................................................. 32 ...................................................................... 33 Bo ............................................................... 36 ................................................................................... 39 ......................................................................... 40 Local OR vs Shared OR ............................................................................................ 41 ................................................................................................ 42 ....................................................................... 49 ......................................................................................... 52 ..................................................................................... 533. Descriptive Programming ............................................................55 Introduction................................................................................................................ 55http://KnowledgeInbox.com/store/
  15. 15. http://KnowledgeInbox.com/store/ .................................................................................................. 55 Object Spy ......................................................................................................... 56 ......................................................................... 58 ..................................................................... 59 .............................................................................. 60 ................................................................................. 60 ...................................................................................... 63 ................................................................................. 63 ......................................................................................... 64 .................................................................................................. 66 .................................................................................... 67 w ....................................................................................................... 67 .......................................................................................... 68 ie ............................................... 69 ................................................................... 72 ev .............................................................................. 73 .............................................................................. 75 Pr ..................................................................................... 77 ........................................................................... 79 ............................................................ 82 ok .................................................................................................. 86 ........................................................... 86 ....................................................................................................... 87 Bo ........................................................................................................... 88 ................................................................ 88 ............................................................... 91 ................................. 93 ....................................... 94 ................................................................................. 96 ............................................................................. 97 ........................................................................... 98 .................................................... 99 ............................................................... 99 xvi http://KnowledgeInbox.com/store/xvi
  16. 16. Contents http://KnowledgeInbox.com/store/ .......................................................................................... 103 ......................................................................... 104 ................................................... 106 ........................................... 1074. ..........................................................113 ...................................................... 1215. ChildObjects ................................................................................123 ..................................................... 129 ................................................... 130 .................................. 130 .............................................. 131 w ................................. 132 ie6. HTML DOM ................................................................................133 Introduction.............................................................................................................. 133 ev ...................................................................................... 134 ............................................................................... 136 Pr ............................................................................................... 136 .................................................................................................... 136 ...................................................................................... 136 ok .................................................................................... 137 ............................................................................ 137 Link and Button (Click)................................................................................... 138 Bo ............................................................................................................ 139 ................................................................................... 140 Checkbox ......................................................................................................... 140 Radio Group .................................................................................................... 141 .................................................................................................... 141 ............................................................. 142 .................................................... 144 ................................................................................. 145 ................................................................ 147 .............................................................................. 147 xviihttp://KnowledgeInbox.com/store/
  17. 17. http://KnowledgeInbox.com/store/ ............................................................................ 150 7. ........................157 8. WebTables ....................................................................................167 .............................................................................. 167 .......................................................................... 171 ................................................ 172 ............................................................... 173 ..................................................................................... 176 .................................................................................. 177 .................................................. 178 9. Testing Complex HTML Tables .................................................181 w 10. Localization Techniques and Design Patterns ........................197 ie Introduction.............................................................................................................. 197 ................................................ 203 ev ........................................................................... 205 ............................................................................. 209 Pr .................................................. 213 ........................................... 217 11. ...........................................223 ok Introduction.............................................................................................................. 223 ................................................ 226 Bo ...................................................................................... 227 ...................................... 229 Wildcards ......................................................................................................... 229 Operators ......................................................................................................... 230 .............................................................................................. 231 ................................................................................... 232 ............................................................................................... 232 ........................................................... 237 ......................................................... 238 .............................................................................................................. 240 .............................................................................. 241 xviii http://KnowledgeInbox.com/store/xviii
  18. 18. Contents http://KnowledgeInbox.com/store/ ................................................ 249 ................................................................... 249 ...................................................................... 25212. ...............................................253 ....................................................................... 25813. ObjectRepositoryUtil ................................................................265 ...................................................... 266 ................................. 267 ........................................................... 268 ................................... 26914. ...................................................271 w .................................................................................... 277 ie ........................................................................ 278 ................................................................ 278 ev .................................................................... 281 ....................................................... 282 Pr ................................................................. 283 ............................................................................... 28315. .................................................................287 ok Introduction.............................................................................................................. 287 ..................................................... 289 Bo .............................................. 293 Installation ....................................................................................................... 293 .......................................................................... 297 .................................................................... 308 ........................................................................... 309 ................................................................. 311 ......................................................................................... 312 ..................................................................... 315 ................................................................. 316 ...................................................................... 32016. .............................................................323 xixhttp://KnowledgeInbox.com/store/
  19. 19. http://KnowledgeInbox.com/store/ ................................. 323 ........................................................... 325 .......................................................................................... 325 ............................................................................................. 329 ......................................................................................... 336 17. ......................................................................339 Introduction.............................................................................................................. 339 ................................................................................ 341 Installation ............................................................................................................... 344 ............................................... 347 ............................. 349 w .............................................................................................. 378 ............................................................................................. 390 ie 18. Creating Reserved Objects.......................................................393 ev Introduction.............................................................................................................. 393 ............................................................................. 394 ................................................................ 397 Pr Appendix A - Approaches for Issue Resolution ............................401 .............. 401 ok add-in ....................................................................................................................... 402 ..................................... 403 Bo ............................ 404 ................................................ 405 ...................... 406 ............... 407 ............... 408 of a popup opened by application ............................................................................ 408 ............................................................................................... 409 .................... 410 Appendix B - Performance Benchmarks ......................................413 xx http://KnowledgeInbox.com/store/xx
  20. 20. Contents http://KnowledgeInbox.com/store/ ...........................................................423 ..................427 .....................................................433 ................................................437 w ie ev Pr ok Bo xxihttp://KnowledgeInbox.com/store/
  21. 21. Preface http://KnowledgeInbox.com/store/ PrefaceTest Automation plays a crucial role in Software Development Lifecycle. With businessesaround the world pushing their IT teams to release software faster and sooner, TestAutomation has become an essential part of the testing lifecycle. Test Automation helpsperform redundant and repeatable tests against the application using an Automation tool.QuickTest Professional (QTP), otherwise known as Functional Testing (FT) is one suchtool being used in the Test Automation domain.QTP offers support for functional automation of various platforms: Web w VB ie Windows ActiveX JAVA ev Pr .NET WPF ok Siebel SAP Bo Peoplesoft Oracle PowerBuilder Stringray Terminal Emulators VisualAge Smalltalk xxiiihttp://KnowledgeInbox.com/store/
  22. 22. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ is performed by storing a set of known properties directly related to the type of object. For some of the common properties to identify such an object are html tag, type, id and name. exposes test objects in such a way that its add-ins identify the interface presented by the underlying technology. If the relevant add-in is not associated with the test or if the WinObject. In such cases, certain workarounds must be implemented to enable QTP to accurately identify objects. w ie the utmost importance to understand how to work around the features of the tool and to consider the options available to overcome the issue. ev Pr emphasis upon how to tackle the challenges one faces when implementing a real-life project. To illustrate, consider a page which presents a textbox generated at run-time and which has a dynamic NAME property; the property’s value changes during each run-session. This can ok Hence it is important to be able to understand the implementation and also to come up Bo with a robust description. This book will walk you through such real-life scenarios and The book also covers Descriptive Programming and Object Repository concepts in depth and walks the reader through some of the really innovative ways in which these can be used This book is written by two seasoned experts from the QTP community, Tarun Lalwani, who has published several other books (including the renowned ‘QuickTest Professional Unplugged’) on QTP and is the founder of the website KnowledgeInbox, and Anshoo Arora, the founder of Relevant Codes, a website with focus on Test Automation. Both authorsxxiv http://KnowledgeInbox.com/store/
  23. 23. Preface http://KnowledgeInbox.com/store/have worked for different international clients and have extensive real-time experience inTest Automation.Who this Book is ForWe recommend this book for those who use HP QTP (FT) or Business Process Testing(BPT). The book assumes that the reader has basic knowledge of both QTP and VBScript.Questions or Feedback Related to the BookEmail: feedback@knowledgeinbox.com wWebsite: www.KnowledgeInbox.com/contact-us/Facebook: ieSource Code in the Book evThe source codes used in the book can be downloaded from: www.KnowledgeInbox.com/ Prdemos/QTPDPUnplugged_SourceCodes.zipOrdering this Book okIndia: You can place an order online at www.KnowledgeInbox.com/store/Other countries: Please check online at www.KnowledgeInbox.com/books/ BoFor bulk orders, contact us at orders@KnowledgeInbox.com xxvhttp://KnowledgeInbox.com/store/
  24. 24. http://KnowledgeInbox.com/store/ 1 Introduction to Objects w ie ev PrBelieve it or not, our lives are surrounded by objects. From small to large, we encountera huge variety of objects of various types on a daily basis. The neurons in our brain use okinformation from our different senses, such as vision, smell, hearing and touch, to help usidentify an object. In fact, the human brain works pretty seamlessly in performing this task.But for a normal computer program to match that power is not easy. BoThis is one of the tough challenges that Automation Engineers face around the world withvarious automation tools; any application can pose a challenge different in nature to anyother application.In object-driven automation, events against objects can only be executed if the softwarethe technology that is used to implement the object. Consider the Window’s Run windowas shown in the image below: 1http://KnowledgeInbox.com/store/
  25. 25. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ Figure 1.1 – Windows Run command window Our aim is to click the Cancel button. When we spy the Cancel button using QTP’s Object w ie Cancel button as the child of the Run window. ev Pr ok Bo Figure 1.2 – Object Spy - Cancel Button2 http://KnowledgeInbox.com/store/
  26. 26. 1 – Introduction to Objects http://KnowledgeInbox.com/store/QTP is able to identify the Cancel button we wanted to click. Now we can add this objectto the Object Repository and perform the click using the following code:Dialog("Run").WinButton("Cancel").ClickThis works because QTP internally knows how to recognize a native Windows object. QTPdoes this through the use of the corresponding add-ins. Every technology is representedas an individual add-in. When QTP is launched, it provides a list from which to select therelevant add-ins through the Add-in Manager. w ie ev Pr ok Bo Figure 1.3 – QTP Startup Add-in Manager 3http://KnowledgeInbox.com/store/
  27. 27. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ NOTE: For Windows native objects, no special add-in is required. To demonstrate how the technology behind the GUI makes a difference, we have created a Java GUI for the same Run window we used earlier in this chapter: w ie ev Pr Figure 1.4 – Dummy Java based Run command window Now if we Spy the same Cancel button again using QTP’s Object Spy, we will notice one crucial difference as shown in Figure 1.5 – Object Spy - Java Run Command window. ok QTP is only able to identify the top level window and nothing inside the window. This Bo The reason this is because the Java add-in is not loaded during startup. There may be circumstances when QTP may fail regardless of the add-in selected. In such a case, we startup as shown in Figure 1.6 – Loading Java Add-in at startup When we use the Object Spy again on the Run window made in Java, we will be able to identify the objects inside the Run window as shown in Figure 1.7 – Object Spy for Java Run window after loading Java Add-in4 http://KnowledgeInbox.com/store/
  28. 28. 1 – Introduction to Objects http://KnowledgeInbox.com/store/ w ie ev Pr ok Bo Figure 1.5 – Object Spy - Java Run Command window 5http://KnowledgeInbox.com/store/
  29. 29. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ w ie ev Pr ok Bo Figure 1.6 – Loading Java Add-in at startup QTP Add-ins for Object Identification Very little has ever been written about how QTP add-ins work internally and HP has not openly provided documentation on the architecture of add-ins. Here we will throw some light on the topic to the best of our understanding. No two add-ins are the same in QTP; each add-in operates in a different manner. For example, the SAP add-in uses the SAP GUI Scripting API provided by SAP internally, so any bug in the SAP GUI Scripting API gets propagated to QTP.6 http://KnowledgeInbox.com/store/
  30. 30. 1 – Introduction to Objects http://KnowledgeInbox.com/store/ w ie ev Pr ok Bo Figure 1.7 – Object Spy for Java Run window after loading Java Add-inOne such example is the max length, where the SAP GUI scripting engine returns the maxlength of a control as the length of text present in the control. This causes QTP to fail whenperforming a set operation if the text being set is bigger than the text already present. TheSAP OSS note 1460861 - “Scripting: MaxLength property returns wrong value” describesthe issue.Similarly, the Siebel add-in uses the SIEBEL Automation API for interacting with the 7http://KnowledgeInbox.com/store/
  31. 31. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ Siebel High Interactivity client. Let’s launch QTP with the ActiveX and Web add-ins selected. Using Sysinternals Process are related to QuickTest Professional (QTP), as shown in Figure 1.8. Acx_trap.dll, Acx_srv.dll, AcxSettings.dll and AcxOutputChannel.dll are some of the DLLs that QTP loads into the IE process to work on the ActiveX objects loaded by IE. Loading these DLLs into the process actually alters the state of the system being tested and means that we are testing our application with the help of external DLLs loaded into IE which may not be present when an actual user would be using the same application. These DLLs can, in rare instances, cause the Application Under Test (AUT) to crash or have some undesired behavior such as poor performance. w ie Timing for Launching the Application ev You may have already heard that it is necessary to launch QTP before starting your Pr application is launched before QTP, then these hooks will not be present in the application and QTP will not be able to communicate with the application in the way intended. However, this is not true for all applications or add-ins. Consider a few of the known ok exceptions: The SIEBEL add-in uses SIEBEL Automation API, so if a SIEBEL application is Bo launched before QTP, QTP will still be able to identify the Siebel objects. This is because even though Siebel runs inside a web Browser, QTP will not identify the Browser properly but rather identify it as a normal native window. Any Windows application that uses just native Windows objects (Window, Dialog, WinEdit etc.) can be launched before QTP itself. QTP uses native system APIs (Let FindWindow, FindWindowEx etc.) to identify these objects and is therefore not dependent on the prior launching of QTP. Java applications also Windows environment variables (_JAVA_OPTIONS, IBM_JAVA_OPTIONS and JAVA_TOOL_OPTIONS) to inject its JVM hook and the application is hooked irrespective of whether QTP is launched or not.8 http://KnowledgeInbox.com/store/
  32. 32. 1 – Introduction to Objects http://KnowledgeInbox.com/store/ w ie ev Pr ok Bo Figure 1.8 - DLLs loaded into Internet Explorer with QTP open The SAP add-in uses SAP Scripting GUI and therefore a SAP GUI application will 9http://KnowledgeInbox.com/store/
  33. 33. http://KnowledgeInbox.com/store/ 2 Object Repository w ie ev Pr ok Bo 11http://KnowledgeInbox.com/store/
  34. 34. 3 – Descriptive Programming http://KnowledgeInbox.com/store/dpBtnLogin = "name:=Login,index:=0"common mistake that is often made by novice users of DP. Instead of using a string basedDP, we need to use object-based DP. We can update the library as follows:Set dpBtnLogin = Description.CreatedpBtnLogin("name").value = "Login"dpBtnLogin("index").value = 0The above uses a hybrid of string-based and object-based DP. Using string-based DP meansusing less memory and shorter code, while using object-based DP means higher memoryand lengthier code but less maintenance in scripts. This is because it allows adding multiple w ie evwe will create a Keyword-based Object Repository. PrKeyword-based Descriptive ProgrammingObject Repository okThis section describes how we can create a Keyword-driven Object Repository of Boprogrammatic descriptions. The following objects and properties are required for a customobject to implement this solution: WebEdit etc.). the parent object helps us in the following ways: It becomes possible to fetch all objects associated with any given parent. 93http://KnowledgeInbox.com/store/
  35. 35. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ It helps to obtain complete details about an object by simply using its associated keyword without the need to provide any additional information in code. This helps ensure the code remains generic. w ie Figure 3.7 – Sample Keyword-based Object Repository ev NOTE: In this example, we have used only 2 columns for unique descriptions. However, we recommend a maximum Pr should be 2-3. ok Next, we will explore a few different aspects of implementing this approach of building a custom Object Repository. Bo Implementing the Keyword based Object Repository As we saw in the Figure 3.7, we must store some information about each object: Name, create a new class called TestObject: Class to store object information Class TestObject Dim Keyword Dim ObjectType Dim Parent94 http://KnowledgeInbox.com/store/
  36. 36. 3 – Descriptive Programming http://KnowledgeInbox.com/store/End ClassTo maintain the object repository we will use a Dictionary object to store the informationabout each test object. Keys of the Dictionary will store the keywords whereas the itemswill store the target test objects as shown here:Create dictionary for storing objects in object repositoryDim ObjectRepositorySet ObjectRepository = CreateObject("Scripting.Dictionary")Public Function AddObjectToOR(ByVal sKeyword, ByVal sObjectType, ByValsParent, ByVal sID1, ByVal sID2) Set oTestObject = New TestObject w With oTestObject ie .Keyword = sKeyword .ObjectType = sObjectType .Parent = sParent ev Pr End With Create an object with sKeyword Overwrite if the object already exists ok Set ObjectRepository(sKeyword) = oTestObjectEnd Function BoIn order to make our object repository case-insensitive, we simply add the next line of codeafter creating the Dictionary:Set text compare mode for keyword for object to be incase-sensitiveObjectRepository.CompareMode = vbTextCompare NOTE: AddObjectToOR does not check whether the object already exists in the Object Repository. It creates and stores a new object if the object does not exist and overwrite allows updating the OR at Run-time using a single function call. However, this behavior can be changed by modifying the function’s code. 95http://KnowledgeInbox.com/store/
  37. 37. http://KnowledgeInbox.com/store/ 4 w ie ev Pr ok Bo Figure 4.1 – VRI Demo Page 113http://KnowledgeInbox.com/store/
  38. 38. http://KnowledgeInbox.com/store/ 5 ChildObjects w ie ev Pr okWe looked at the ChildObjects method earlier in the Descriptive Programming chapter.This chapter discusses ChildObjects in detail and highlights the key concepts that usersshould be aware of. BoLets look again at how we use ChildObjects.Dim oDescSet oDesc = Description.CreateoDesc("micclass").value = "WebEdit"oDesc("name").value = "txt_.*"Find all the childObjectsSet allTextBox = Browser("B").Page("P").ChildObjects(oDesc)Dim iFor i = 0 to allTextBox.Count - 1 123http://KnowledgeInbox.com/store/
  39. 39. http://KnowledgeInbox.com/store/ 6 HTML DOM w ie ev PrIntroduction okThe HTML DOM is a Document Object Model for representing HTML documents. DOM Boset of objects in a tree structure of elements. It provides a standard approach to access andmanipulate HTML documents. All elements, along with their text and attributes can beaccessed and manipulated through the DOM tree.The QTP Page object’s .Object property provides access to the HTML DOM:Get the DOM document objectSet oDocument = Browser("Browser").Page("Page").Object 133http://KnowledgeInbox.com/store/
  40. 40. http://KnowledgeInbox.com/store/ 7 w ie ev PrA limitation of ok Bo childNodes 157http://KnowledgeInbox.com/store/
  41. 41. http://KnowledgeInbox.com/store/ 8 WebTables w ie ev Pr okA huge amount of testing today is done on Web/HTML. A TABLE tag in HTML can beused to present data or perform layouts on the webpage. This chapter will focus on some ofthe key tasks that need to be performed when dealing with WebTables. But before we start Bo 167http://KnowledgeInbox.com/store/
  42. 42. 8 – WebTables http://KnowledgeInbox.com/store/We saw earlier how the GetRowWithCellText method provides us with a way to search for w ie ev Pr ok Figure 8.3If we want to search for the second edition of ‘QuickTest Professional Unplugged’, we BoDim bExit, bFound, iRow, iStartRowbExit = FalsebFound = FalseiStartRow = 1Do iRow = Browser("Browser").Page("Page").WebTable("Book").GetRowWithCellText("QuickTest Professional Unplugged",1, iStartRow) If iRow = -1 Then bFound = False bExit = True Else Next time we will search for one row further 173http://KnowledgeInbox.com/store/
  43. 43. http://KnowledgeInbox.com/store/ 9 Testing Complex HTML Tables w ie ev PrPreviously in web-design, UI Designers used the TABLE tags to create a tabular look andfeel. This TABLE tag implementation makes it easier for Automation Engineers to processdata and perform actions on objects inside the table. Consider the following table: ok Bo Figure 9.1 – Demo web pageThe HTML implementation is as follows:<html> 181http://KnowledgeInbox.com/store/
  44. 44. http://KnowledgeInbox.com/store/ 10 Localization Techniques and Design Patterns w ie ev PrIntroduction ok Bo Locale Description LCID (Locale ID) af 197http://KnowledgeInbox.com/store/
  45. 45. http://KnowledgeInbox.com/store/ Dim path LoadFunctionLibrary pathEnd SubLoadLocaleLib "login.vbs", "en-us" EnglishLoadLocaleLib "login.vbs", "es-es" Spanish w ie ev Pr okAdvantages BoUsing a Simple Locale Collection 205http://KnowledgeInbox.com/store/
  46. 46. http://KnowledgeInbox.com/store/Test: Action1main_Page.Runmain_Page.Run w ie ev PrAdvantages ok BoUsing a Class-based Centralized DelimitedCollection 217http://KnowledgeInbox.com/store/
  47. 47. http://KnowledgeInbox.com/store/ Class MainPageClass Scripting.Dictionary built from LocalizedRepository Private Content Public Sub Action() w With Browser("name:=" & Content("title")) OR style .Link("innertext:=" & Content("about-us")).Highlight DP style ie End With End Sub ev builds the Dictionary from LocalizedRepository Pr If Not TypeName(Content) = "Dictionary" Then Set Content = LocalizedRepository.MainPage() End If ok End Sub Private Sub Class_Terminate() Bo Set Content = Nothing End Sub End Class Dim MainPage Set MainPage = New MainPageClass Class LoginPageClass Scripting.Dictionary built from LocalizedRepository Private Content218 http://KnowledgeInbox.com/store/
  48. 48. http://KnowledgeInbox.com/store/ 11 w ie ev Pr okWith QTP 11, HP launched several new web testing capabilities to provide engineers Bo 223http://KnowledgeInbox.com/store/
  49. 49. http://KnowledgeInbox.com/store/ <td> <span>Row1 span1</span><br/> <span id="selectednode">Row1 span2 <!-- target --> <p>TEST</p> <p>REST</p> </span>ancestor-or-selfXPath selector: //SPAN[@id=selectednode]/ancestor-or-self::*<html> <body> <div id="forsomereason"> w <span>This is before table</span><br/> ie </div> <table border="1"> <tr> <td> ev <span>Row1 span1</span><br/> Pr <span id="selectednode">Row1 span2 <!-- target --> <p>TEST</p> <p>REST</p> </span><br/> okchild BoXPath selector: //SPAN[@id=selectednode]/child::*<span id="selectednode">Row1 span2 <!-- target --> <p>TEST</p> <p>REST</p></span>descendantXPath selector: //SPAN[@id=selectednode]/descendant::*<span id="selectednode">Row1 span2 <!-- target --> <p>TEST</p> 243http://KnowledgeInbox.com/store/
  50. 50. http://KnowledgeInbox.com/store/ 12 w ie ev Pr ok Bo:=Browser("CSS Chapter").WebButton("css:=input.btnTarget").Click 253http://KnowledgeInbox.com/store/
  51. 51. http://KnowledgeInbox.com/store/ 13 ObjectRepositoryUtil w ie ev Pr okQTP provides an Object Repository Automation API called ObjectRepositoryUtil. ThisAPI provides a set of functions that can be used to read and/or write contents to a SharedObject Repository (SOR). It can be used to update an external Object Repository except the Boone already loaded in the memory.There is a common misconception that this API can be used to add objects dynamically totheir script. This understanding is incorrect. It is possible, however, to create an OR usingthe API and load it in the script using the RepositoriesCollection utility object.ObjectRepositoryUtil. These are listed in the following table: 265http://KnowledgeInbox.com/store/
  52. 52. http://KnowledgeInbox.com/store/ 14 Working with QTP XML OR w ie ev Pr ok Bo 271http://KnowledgeInbox.com/store/
  53. 53. http://KnowledgeInbox.com/store/ 15 Testing Web Services w ie ev Pr okIntroduction BoAs web services become key areas of enterprise applications, the focus on testing them hasbecome increasingly important. A web service is used to provide a response to a client’srequest. The request and response are sent and received respectively using the SimpleObject Access Protocol (SOAP). To test a web service, an automation engineer must carryout the following steps: 1. 2. 3. Parse response to verify expected versus actual values.The process of sending a request and receiving a response is shown below: 287http://KnowledgeInbox.com/store/
  54. 54. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ Celsius (C) for the unit (string). w ie ev Pr Figure 15.2 – Sample Temperature Web Service The snapshot below is the output from invoking the WebMethod: ok Bo Figure 15.3 – Sample WebMethod Input and Output292 http://KnowledgeInbox.com/store/
  55. 55. http://KnowledgeInbox.com/store/ 16 Coding Scripts in .NET w ie ev PrThere are times when advanced users want the ability to code QTP scripts in a different okscripting language than VBScript. A few such instances include the need for betterexception handling (using Try-Catch-Finally), designing forms for user interaction,Object-Oriented features, need for Optional Parameters and better support for Win32 APIs Bo(VBScripts support through the Extern object is very limited) etc. It is not possible to useany language except VBScript inside QTP, yet it is still possible to create a COM-basedbridge for languages that support COM. We will be demonstrating such a bridge in thischapter built in C# and Visual Basic using .NET Framework 4.0. Before we see how thebridge is created, there are few concepts that we need to understand.QTPs Communication with an Out-of-ProcessCOM ObjectConsider the following code: 323http://KnowledgeInbox.com/store/
  56. 56. QTP Descriptive Programming Unplugged http://KnowledgeInbox.com/store/ Set oXlApp = CreateObject("Excel.Application") oXLApp.Visible = True Set oXLBook = oXLApp.WorkBooks.Open("C:Test.xls") Set oXLSheet = oXLBook.WorkSheets(1) oXLSheet.Cells(1,1) = "Anshoo" oXLSheet.Cells(2,2) = "Tarun" In this code an oXLSheet.Cells object is used to pass a value to an Excel Worksheet. Even though Excel runs as a separate process in the system, we can still pass values to it. This is called out-process communication. It works through use of a proxy object in the caller below: w ie ev Pr ok Bo Figure 16.1 – Out-Process Communication324 http://KnowledgeInbox.com/store/
  57. 57. http://KnowledgeInbox.com/store/ 17 Web Extensibility w ie ev Pr okIntroduction BoThe Web Extensibility Add-in coupled with the Extensibility Accelerator for HP FunctionalTesting provides a platform that enables Automation Engineers to extend support forcustom web controls and toolkits.A compelling case to opt for Extensibility is in a situation where some web controls whichare not supported out-of-the-box are recognized as generic WebElements; these genericobjects may implement the behavior of a TextBox, Link, Button or List etc. Since the Webclass. Every such generic object thus ends up supporting the functions/methods/events ofthe WebElement class.This is where the web add-in Extensibility plays an important role because a control can 339http://KnowledgeInbox.com/store/
  58. 58. http://KnowledgeInbox.com/store/ 18 Creating Reserved Objects w ie ev Pr okIntroduction BoA reserved object allows you to add a specialized keyword to QuickTest which unlike customclasses provides you with IntelliSense. For example, the Environment object is a reservedobject with the ProgId of “Mercury.MicEnvironment”. Similarly, a Description object(Description.Create) is another reserved object with ProgId of “Mercury.DescObjCreator”.Just like with these reserved objects, it is also possible to create custom reserved objects.At runtime, QuickTest creates a single instance of the reserved object as required by thetest code. Unlike instances of other objects, such as references to custom classes or classicCOM objects (Scripting.Dictionary or FileSystemObject objects created explicitly duringTest-run, for example), a reserved object is created on demand when referenced duringmade available with QTP Plus (QTP 8.2). 393http://KnowledgeInbox.com/store/
  59. 59. http://KnowledgeInbox.com/store/ A Appendix A - Approaches for Issue Resolution w ie ev PrProblem 1 – Application crashes when launched okwith QTP already open BoSome applications have problems with QTP’s ActiveX add-in. In such cases the application 1. If IE crashes with a Non-Silverlight application HKEY_CURRENT_USERSoftwareMercury InteractiveQuickTest ProfessionalMicTestActiveX Add-in 401http://KnowledgeInbox.com/store/

×