69
GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

  • Upload
    gareddy

  • View
    5.534

  • Download
    0

Embed Size (px)

DESCRIPTION

GAReddy @ OneTestingCenter @ QTP Learning Made Easy Part1.• QTP• QTP Learning• Let's Learn QTP• QTP Easy Learning• QTP Guide• QTP Book• QTP Learning PDF• QTP - Fundamentals• QTP - Advanced • QTP - Topic by Topic• QTP Lessons• GAReddy @ QTP

Citation preview

Page 1: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter

www.OneTestingCenter.com

www.GAReddy.Blogspot.com

Page 2: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

1 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Quick Introduction to QTP

Quick Test Professional Are you new to HP Quick Test Pro 9 (QTP)? You are at the right place, at the right time. This article is for newbie's who want to start their carrier with QTP or have just started with QTP. The article will give you a brief overview of various features of QTP, and since it is for newbie's we won't be going into too much details of every feature. What is QTP? * HP Quick Test Pro is a functional automation and regression testing tool * QTP provides record and playback of events * Uses VBScript as the scripting Language * Provides keyword view and expert view to view test cases.

* Latest version of QTP is 11 (launched in 2010) * Prior versions of QTP are 9.5, 10 * Previous version of QTP: 6.5, 8.0, 8.1, 8.2, 9.0, 9.1 * QTP was previously owned by Mercury Interactive®

* Now, QTP is HP‘s Product

Installing QTP You can download a 14 day Trial version from HP site. QTP 14 day Evaluation With introduction of QTP 11, Trial version of QTP 11 can support 30 days with all the Addins.

So, we can download either QTP 10 (works for 14 days trial) or QTP 11 (works for 30 days trail) to start learning and to start using QTP

Launching QTP When you launch QTP for the first time, Add-in manager window is displayed

Page 3: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

2 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

What is Add-in? * QTP requires Add-in for recognizing object of a specific environment * By default QTP comes with 3 Add-ins: Web, ActiveX and VB * Some of the Add-ins available for QTP are 1. Terminal Emulator (TE) 2. .NET 3. Java 4. SAP 5. Siebel 6. Stingray 7. VisualAge 8. Web Services

And so on.. * QTP does not require any Add-in to work on Standard windows application * Add-ins can only be loaded when starting QTP Once the selected Add-ins are loaded, QTP window will show up Hit the record button to start recording. If you are recording for the first time, the Record and Run Settings dialog box opens. What all tabs are shown in above dialog would depend on Add-ins that is loaded. Using above dialog we can set on what all application should QTP record on. Note: If QTP does not record anything on your application then make sure you have the correct settings specified in Record and Run Settings… Keyword view The Keyword View enables you to create and view the steps of your test in a keyword-driven, modular, table format. This is the only view where complete Test flow can be viewed. Expert View In Expert View, QTP displays each operation performed on the application in the form of a script, comprised of VBScript statements. Complete test flow is not available /visible in this view.

Page 4: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

3 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Test and Run-time Object * QTP works on objects in Application Under Test (AUT) by storing object description * This object description is known as a Test Object * Each Test Object supports predefined sets of Methods and properties * The actual object in the AUT which is identified for a Test Object is called the Run-time object. * A Test Object can always be present without the AUT * Run-time object can only be present when AUT is up and running

Object Spy Object Spy is a tool that can be used to spy Test and run time object for looking at properties and methods supported by object being spied

Object Identification * QTP uses three types of properties when identifying an object 1. Mandatory – Always learn these properties for the object 2. Assistive – Learn in case Mandatory properties are not enough to identify the object uniquely 3. Ordinal identifiers – Learn in case both mandatory and assistive properties are not able to recognize the objects correctly

4. Smart Identification (Called as QTP’s sixth sense to identify objects) * Ordinal identifiers are of three types: 1. Index – index of object (0, 1, 2 …) 2. Location – Location of the object on the screen (0, 1, 2 …) 3. CreationTime – Used only for Browser. Launchtime of browser (0, 1, 2 …)

Object Identification Settings Launch from menu Tools->Object Identification… Here we can Add/Remove properties from/to Mandatory and Assistive properties. Objects in application represent certain special characteristics which allow QTP to map them QTP Test object. For window objects this characteristic is mostly define by "regexpwndclass" . In case application developers don't use standard class names while creating object QTP won't be able to identify the object correctly. Below is a checkbox in Search window recognized by QTP as WinObject

Page 5: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

4 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

By clicking on the "User Defined…" button on Object identification settings window, we can add such objects and map. Once added QTP will now be able to recognize the object correctly Object Hierarchy * QTP uses object hierarchy to identify object inside a AUT * QTP only adds those objects from hierarchy which are necessary for it to identify the object later. * In this case QTP will add Browser("Google" ).Page("Google" ).WebEdit( "q").Set "test" (WebTable object ignored) * QTP cannot be configured to record such objects automatically. Object Repository (OR) * QTP works on object in application by storing information about the object in Object repository * All objects on which user takes an action while recording are automatically added to object repository * "Browser", "Google", "q" are three different objects that would be present in OR for the below generated statement Browser("Browser" ).Page("Google" ).WebEdit( "q").set "Test" * Copying and pasting code from one script to another script does not work in QTP as the OR does not get copied to the new script

* There are two types of Object Repositories in QTP: 1. Shared OR: Can be used by multiple scripts. A central location to store all objects 2. Per-Action OR: Every action has its individual object repository Per-Action Object Repository * Default repository * Specific to actions (Will be used only for a particular action) * Preferable when application is not dynamic with respect to time * Cannot be reused Shared Action repository * Can be updated by all actions accessing it * Preferable when application is dynamic with respect to time * Used in most automation projects

Page 6: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

5 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

* Needs maintenance and administration Action * Provides way of grouping code into business logic * Are pretty similar to Functions in VBScript * Have their own Data Table and Object Repository (in case of per-action object repository) * Supports input and output parameters

* Actions are of two types:

* Reusable Actions

* Non-Reusable Actions

* Re-usable actions can be called in other Test. * QTP does not allow calling another test within a test * TestFlow represent the top level action. Complete test flow can only be viewed in Keyword views Inserting Actions * There are three ways to insert an Action in a test 1. Insert Call to New… 2. Insert Call to Copy… 3. Insert Call to Existing…

Insert Call to New… - Creates a new action and adds a call to the same. Pfrovide the name "Cancel Ticket" in the "Name" field and click on OK button. * Adds below line to the code RunAction "Cancel Ticket", oneIteration Actions - Insert Call to Existing… * Insert Call to Existing – User to insert call to a re-usable action located within the same test or some other test * This inserts the call to the existing action. In case the action in present in some other test case then a read only copy of action is inserted Actions – Insert Call to Copy… * Insert Call to Copy - Inserts call to an existing re-usable action and creates an editable copy of

Page 7: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

6 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

that action * Actions cannot be deleted from a Test from Expert view. To delete a action one must go to the keyword view and delete the action * An action call cannot be inserted directly by writing code in Expert View, it has to be added through the GUI first. Action Iterations An action can be run for 1 or more rows from its Local Data Table. * QTP supports there types of iteration modes: 1. Run one iteration only 2. Run on all rows 3. Run from Row to Row * Similar to Action, a test can also be run for multiple iterations from Global Data Table

Why Parameterization? * Parameterization allows us to pick different values at run time. * Reduces Time and Effort. * Usage of data drivers allows us to use the same data for various input boxes. * Parameterization can also be done for checkpoints. Data Table * Data Table is excel like spreadsheet which can be user for parameterizing a test case

* DataTable are of two types: 1. Global Data Table – Data table for Complete Test flow 2. Local data table – Data table for every action * Data table value can be accessed using the below method a) DataTable(" ",dtGlobalSheet) b) DataTable("" ,dtLocalSheet) c)DataTable( "","") Run-time Data table * Any changes made to Data table during run-time is stored in run-time data table. * Run-time data table is available in the test results summary of a test * DataTable values can be changed at run-time by using below mentioned code:

Page 8: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

7 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

DataTable("OrderCon f", dtGlobalSheet) = "ABCD1234" Environment Variables * Environment variables are global variables available to all Actions * They can be used to run a test case on different environment * To add a new Environment variable go to Test -> Settings…->Environment (Tab) * Environment variables are of two types 1. Built-in 2. User-Defined * Built in environment variables give information about the system and the current test * User-defined Environment variables added in the Environment tab of Test Settings are Read-only during the test run * Environment variables can be added during runtime also using code Environment. Value("OrderNumb er") = "ABCDEF" * Environment variables can be loaded at run-time from a XML file using the below code Environment. LoadFromFile "C:\TestEnvironment .xml" * The Environment XML file has to be in below format: APP_URL http://test1. appserver. com Parameters * Parameters provide another way of parameterizing the test cases * There are two types of parameters: 1. Test parameters 2. Action parameters * Test parameters can be set in Test->Settings…->Parameters (Tab) * Test parameters value can be provided when replaying the test * Test arguments can be accessed in the test using TestArgs(" ") Action Parameters * Used to pass parameters to Action * Output parameters can only be used when Action is being called for a single iteration * Ex – RunAction "Login", oneIteration, "TestUser", "TestPass", out * A parameter can be accessed using Parameter("ParamNam e " )

Page 9: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

8 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Resources * Scripts written in VBScript language can be add as a Resource to the test * All code written in the script is available across all Actions * A VBScript can also be loaded in an Action by using ExecuteFile function. Ex – ExecuteFile "C:\Init.vbs" * In case of multiple files QTP combines all the files into a single one and executes the code. The files are combined in bottom to top order

Checkpoints * Checkpoints are verification points in a test * Test without checkpoint would never have a pass status * Checkpoints can be of 2 types – Built-in checkpoints – Custom checkpoints * Types of Built-in checkpoints available are 1. Standard checkpoints: Verify properties of an object 2. Text checkpoints: Verify text presence between two strings 3. Text Area checkpoint 4. Bitmap checkpoint 5. Accessibility checkpoint 6. Database checkpoint 7. XML Checkpoint * Only Database and XML checkpoints can be inserted in idle mode. * Rest all checkpoints can only be added during Recording or through Active screens. * Checkpoint code Browser("Google" ).Page("Google" ).WebEdit( "q").Check CheckPoint(" Verify TextBox_Standard" ) Custom Checkpoints * Custom checkpoints can be created using Code loginExist = Browser().Page( ).Link("text: =Login"). Exist(0) If loginExist then Reporter.ReportEven t micPass, "Check Login", "Login link exists" Else Reporter.ReportEven t micFail, "Check Login", "Login link does not exists" End if

Page 10: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

9 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

* Custom checkpoint can be made flexible based on implementation and are preferred over Built-in checkpoints Test Results Test results provide an execution summary of the complete test case * There are different types of status in test results summary: 1. Passed 2. Failed 3. Done 4. Warning 5. Information Descriptive Programming * Alternate way of writing test cases without having objects in object repository * Descriptive programming can be done in two ways 1. Using object description 2. Using string description * In DP objects are identified by describing all the identification properties * String description DP Browser("title: =Google") .Page("title: =Google") .WebButton( "name:=Search" ).Click * Object Based DP Set btnSearch = Description. Create : btnSearch("name" ).Value = "Search" Set brwGoogle = Description. Create : brwGoogle("title" ).value = "Google" Set pgGoogle = Description. Create : pgGoogle("title" ).value = "Google" Browser(brwGoogle) .Page(pgGoogle) .WebButton( btnSearch) .Click * Description objects can also be used to get all child objects matching a criterion. Ex – Set oDesc = Description. Create oDesc("name" ).Value = "txt_.*" oDesc("name" ).RegularExpress ion = True Set allMatchingObjects = Browser().Page( ).ChildObjects( oDesc) Msgbox allMatchingObjects. Count Msgbox allMatchingObjects( 0).GetROProperty ("name") * By default all property values are considered as regular expression patterns * When using string description all regular expression must be used with escape character for literal meaning. Ex - …Link("text:= Logout \(Piyush\)") .Click

Page 11: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

10 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

* DP based Object repository can be created in any file * Code can be copied from one script to another without copying the object repository * Custom implementation of object is easier. Ex – objStrDesc = "Browser(""title: =Test""). Page(""title: =Test""). Link(""text: =Login"") " Execute "Set obj = " & objStrDesc obj.Click QTP Misc information * QTP and the AUT has to be on the same machine * QTP can be controlled remotely from another machine * QTP scripts cannot be run without QTP

I) What is the difference between an Action and a function? Action is a thing specific to QTP while functions are a generic thing which is a feature of VB Scripting. Action can have a object repository associated with it while a function can't. A function is just lines of code with some/none parameters and a single return value while an action can have more than one output parameters.

Where to use function or action? Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. If the functionality is not about any automation script i.e. a function like getting a string between to specific characters, now this is something not specific to QTP and can be done on pure VB Script, so this should be done in a function and not an action. Code specific to QTP can also be put into a function using DP. Decision of using function/action depends on what anyone would be comfortable using in a given situation.

When to use a Recovery Scenario and when to us on error resume next?

Recovery scenarios are used when you cannot predict at what step the error can occur or when you know that error won't occur in your QTP script but could occur in the world outside QTP, again the example would be "out of paper", as this error is caused by printer device driver. "On error resume next" should be used when you know if an error is expected and dont want to raise it, you may want to have different actions depending upon the error that occurred. Use err.number & err.description to get more details about the error.

How to use environment variable? A simple definition could be… it is a variable which can be used across the reusable actions and is not limited to one reusable action. There are two types of environment variables: 1. User-defined

Page 12: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

11 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

2. Built-in We can retrieve the value of any environment variable. But we can set the value of only user-defined environment variables.

To set the value of a user-defined environment variable: Environment (VariableName) = NewValue

To retrieve the value of a loaded environment variable: CurrValue = Environment (VariableName)

Example

The following example creates a new internal user-defined variable named MyVariable with a value of 10, and then retrieves the variable value and stores it in the MyValue variable.

Environment. Value("MyVariable")=10 MyValue=Environment .Value("MyVariable")

II) What are the files and subfolders of a QuickTest Professional test? The files and folders hold binary and text data that are required for the test to run successfully. The following table provides a description, the type, and comments regarding the files that make up a QuickTest Professional test.

File Name Description Type Comments Regarding File

Test.tsp Test settings Binary Do not edit

Default.xls Data table parameters

Excel similar Can be edited using Excel

Parameters.mtr Parameterization information

Binary Do not edit

Action Action folder (See other table)

<!–[if !supportEmptyParas]–> <!–[endif]–>

<!–[if !supportEmptyParas]–> <!–[endif]–>

Default.cfg Load test configuration file

Text Do not edit

Default.prm Load test configuration file

Text Do not edit

Default.usp Load test configuration file

Text Do not edit

Page 13: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

12 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

.usr Load test configuration file

Text Do not edit

Thick_usr.dat Load test configuration file

Text Do not edit

Thin_usr.dat Load test configuration file

Text Do not edit

Files within Action folder:

File Name Description Type Comments Regarding File

Script.mts Action script Text Edit text preceding the @@ sign only

Resource.mtr Object Repository Binary Do not edit

Snapshots Active screen files Folder Do not edit

There are few more files extensions like

.MTB Batch File

.LCK Locked

III) How to rename a checkpoint (QTP)? Example: Window("Notepad" ).WinEditor( "Edit").Check CheckPoint(" Edit") In the above example, the user would like to change the name of the CheckPoint object from "Edit" to something more meaningful. Note: This functionality is new to QuickTest Professional 9.0.This is not available for QTP 8.2 and below. 1. Right-click on the Checkpoint step in the Keyword View or on the Checkpoint object in Expert View. 2. Select "Checkpoint Properties" from the pop-up menu. 3. In the Name field, enter the new checkpoint name. 4. Click . The name of the checkpoint object will be updated within the script. Example: Window("Notepad" ).WinEditor( "Edit").Check CheckPoint(" NewCheckPointNam e") Note: You must use the QuickTest Professional user interface to change the name of the checkpoint.

Page 14: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

13 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

If you manually change the name of the checkpoint in the script, QuickTest Professional will generate an error during replay. The error message will be similar to the following:

"The "" CheckPoint object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object."

The CheckPoint object is not a visible object within the object repository, so if you manually modify the name, you may need to recreate the checkpoint to resolve the error.

12) Problem

After Quick Test Professional is started, Windows Media will not start. It returns the error message "wmplayer.exe has generated errors and will be closed by Windows. You will need to restart the program. An error log is being created."

If you start Window's Media Player first, it will continue to work normally after starting QuickTest Professional.

Solution:

Include the Windows Media Player's executable in the NoBBTApps section of the mic.ini file

1. Close QuickTest Professional. 2. Go to \bin\mic.ini. 3. Include wmplayer.exe in the NoBBTApps section of mic.ini file.

Example: [NoBBTApps] wmplayer.exe= rek

4. Save the mic.ini file and restart QuickTest Professional.

13) What is the lservrc file in QTP? The lservrc file contains the license codes that have been installed

The lservrc file contains the license codes that have been installed. Whenever a new license is created, the license code is automatically added to this file. The lservrc file is a text file, with no extension.

File Location: 1) For a Concurrent (Floating) license installation:

"#server installation directory#\# language# "

Example: C:\Program Files\HP\ QuickTestProfessional\lservrc

Page 15: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

14 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

2) For a Seat (Stand-alone) license installation:

#AQT/QTP installation directory#\bin"

Example: C:\Program Files\Mercury Interactive\ QuickTest Professional\ Bin\lservrc

14) What to do if you are not able to run QTP from quality center? This is for especially for newbies with QTP. Check that you have selected Allow other mercury products to run tests and components from Tools–> Options–> Run Tab.

15) Does QuickTest Professional support Macintosh operating systems? No, QTP is not expected to run on this OS.

IV) VBScript String Functions 1.LTrim 2.RTrim 3.Trim 4.Replace 5.StrReverse 6.Space LTrim Function:

Removes spaces on the left side of a string. Syntax:LTrim( string) Ex1:a=LTrim( " GAReddy ") Msgbox a Output=GAReddy . RTrim Function:

Removes spaces on the right side of a string. Syntax:RTrim( string) Ex1:a=RTrim( " GAReddy ") Msgbox a Output= GAReddy.

Trim Function:

Page 16: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

15 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Removes spaces on both the left and the right side of a string. Syntax:Trim( string) Ex1:a=Trim("GAReddy ") Msgbox a Output= GAReddy. Replace Function:

Replaces a specified part of a string with another string a specified number of times. Syntax:Replace( expression, find, replacewith[ , start[, count[, compare]]]) where start,count, compare are optional. expression:String expression containing substring to replace. find:Substring being searched for. replacewith:Replacement substring. start(Optional) :Position within expression where substring search is to begin. If omitted,1 is assumed. count(Optional) :Number of substring substitutions to perform. If omitted, the default value is -1, which means make all possible substitutions. compare(Optional) :Numeric value indicating the kind of comparison to use when evaluating substrings.If omitted,the default value is 0, which means perform a binary comparison. Ex1:a= Replace("abacadaeaf ","a","x" ) Msgbox a Output=xbxcxdxexf. Ex2:a=Replace( "abacadaeaf" ,"a","x", 1,3) Msgbox a Output=xbxcxdaeaf. As we are giving values for start and count parameters(optional )in above example only first 3 a's are replaced by x. StrReverse Function:Reverses a string. Syntax:StrReverse( string) Ex1:a=StrReverse( " GAReddy " ) Msgbox a Output=yddeRAG. Space Function:

Creates a string with the specified number of spaces. Syntax:Space( number) Ex1:a="Welcome"&space(5)&"All"

Page 17: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

16 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Msgbox a Output=Welcome All.

V) QTP reporter objects.

Reporter Object is used for sending information to the test results. With the help of this object you can:

>Report the status of test results (like pass, fail, warning)

>Enable/Disable reporting of step(s) following the statement.

>Retrieve the folder path in which the current test's results are stored.

>Retrieve the run status at the current point of the run session.

There are some very important methods and properties associated with it.

ReporterEvent Method:

I think this is a very common method used with Reporter object. I am sure even if you have worked on QTP for a relatively short period, you would have come across this. Its syntax:

Reporter.ReportEvent EventStatus, ReportStepName, Details

where EventStatus can be: 0 or micPass: If this step runs test passes which is shown in test report. 1 or micFail: If this step runs test fails which is shown in test report. 2 or micDone: Used to send message to the test report and does not affect status of test. 3 or micWarning: Again, used to send warning message to the test report and does not affect status of test. and ReportStepName is name of step and Details are the user defined details for the given step.

For Example:

Reporter.ReportEvent micPass, "Login Authorization" , "The user-defined step passed."

Filter property

Page 18: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

17 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

I have mentioned this on my other post Some Useful Tips with QTP but would like to mention it again here since I get a lot of questions on this. There can be situations where you don't want the full status displayed on the test report. This property can be used to selectively filter the status of your tests. Its syntax:

Reporter.Filter = NewMode

where NewMode can be: 0 or rfEnableAll: This is the default mode. All reported events are displayed in the Test Results. 1 or rfEnableErrorsAndWa rnings: Only those events with a warning or fail status are displayed in the Test Results. 2 or rfEnableErrorsOnly: Only those events with a fail status are displayed in the Test Results. 3 or rfDisableAll: All events in the Test Results are disabled.

ReportPath Property

This is used to get the path in which current test results are stored. Its syntax:

Path_of_Results = Reporter.ReportPath

RunStatus Property

This is used to get the current status of the run session Its syntax:

Reporter.RunStatus

For Example:

if Reporter.RunStatus = 0 then flag=1;

VI) How to make QTP perform better.

Everyone knows we use automated testing tools to optimize our testing process. Unless you make full use of the capability of the tool and unless a tool is used sensibly and with proper planning, it would not yield any results. Just record-and-playback is never the solution for any project. You need to go deep inside to understand the intricacies of any tool. Any software testing tool is only as good as the test engineer using it. On those thoughts, I feel this was one

Page 19: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

18 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

of the best questions asked in the forums of late. Well, here are some of my tips and tricks to optimize the QTP scripts:

Launch QTP using a .vbs file and not the QTP desktop icon. You will notice a substantial increase in speed. [Refer the earlier post on How to open QTP using vbs file? ,you just need the 1st point of that post]

For large tests, always define variables, function in an external .vbs file and not inside a reusable action. Attach these files with your test scripts. If you define a variable or a function in an action, on every iteration of your test run, memory(RAM) will be allocated to those variables/functions and would not be released. Now as your script starts consuming more and more RAM, your System Under Test (SUT) will tend to become slower.

While running, QTP consumes a lot of memory by itself. It is always advisable to have lots of available RAM( much more than what is recommended by HP) and good processor speed on a system where you intend to install QTP. When you have tests (and hence QTP) running for a prolonged period if time, there are chances of memory leaks. To avoid memory leakage always restart QTP at some intervals of time. Using AOM you can automate this process. [If you want to go into details of effect of RAM on speed of computer read the post on RAM, Memory Usage thoroughly]

Avoid using hard coded wait(x) statement. Wait statement waits for full x seconds, even if the event has already occurred. Instead use .sync or exist statement. While using exist statement always have a value inside it.

For ex: .Exist(10) Here QTP will wait max till 10 seconds and if it finds the object at (say) 3 secs , it will resume the execution immediately thereby saving your precious time. On the other hand if you leave the parenthesis blank, QTP would wait for object synchronization timeout you have mentioned under File > Test Settings > Run Tab.

Make full use of what HP-QTP has provided you in the tool IDE. Use "Automatically Generate "With" statements after recording" option present under Tools > Options > General Tab. This will not only make your code look neater but also make your scripts perform better.

Make your own judgement whether you want to go for Descriptive Programming or Object Repository or mixed approach. Each approach has it own pros and cons that in turn is related to QTP performance.

Unless absolutely required, uncheck the options "Save still image capture to results" and "Save movie to results" present under Tools > Options > Run tab. These options definitely have some bearing on QTP run time performance.

Make the Run Mode as "fast". This setting is present under Tool > Options > Run tab. Note: If you intend to run your scripts from QC no need to worry about this option, as the scripts WILL run in fast mode whether you want or not.

Page 20: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

19 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

If you are new to automation or QTP. Read this beginner article on Automation Object Model (AOM). AOM simplifies many aspects of QTP scripting. It can help you in controlling QTP from an external file.

Make use of relative paths while calling reusable actions in your script. Using relative path would make your script portable and easy to manage. I will cover in detail how to's and why's of using relative paths in my next post.

VII) How QTP identifies objects?

Here I am reproducing one of the most important extract from QTP help section. If you understand this part be assured you of your success in QTP Job interviews, other question that follow will be of very elementary nature. When QuickTest uses the learned description to identify an object, it searches for an object that matches all of the property values in the description. In most cases, this description is the simplest way to identify the object, and, unless the main properties of the object change, this method will work. If QuickTest is unable to find any object that matches the learned object description, or if it finds more than one object that fits the description, then QuickTest ignores the learned description, and uses the Smart Identification mechanism to try to identify the object. While the Smart Identification mechanism is more complex, it is more flexible. Therefore, if configured logically, a Smart Identification definition can probably help QuickTest identify an object, if it is present, even when the learned description fails.

The Smart Identification mechanism uses two types of properties: · Base Filter Properties—The most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object.

For example, if a Web link's tag was changed from {A} to any other value, you could no longer call it the same object.

· Optional Filter Properties—Other properties that can help identify objects of a particular class. These properties are unlikely to change on a regular basis, but can be ignored if they are no longer applicable. Understanding the Smart Identification Process

If QuickTest activates the Smart Identification mechanism during a run session (because it was unable to identify an object based on its learned description) , it follows the following process to identify the object: 1. QuickTest "forgets" the learned test object description and creates a new object candidate list containing the objects (within the object's parent object) that match all of the properties

Page 21: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

20 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

defined in the Base Filter Properties list. 2. QuickTest filters out any object in the object candidate list that does not match the first property listed in the Optional Filter Properties list. The remaining objects become the new object candidate list. 3. QuickTest evaluates the new object candidate list: o If the new object candidate list still has more than one object, QuickTest uses the new (smaller) object candidate list to repeat step 2 for the next optional filter property in the list. o If the new object candidate list is empty, QuickTest ignores this optional filter property, returns to the previous object candidate list, and repeats step 2 for the next optional filter property in the list. o If the object candidate list contains exactly one object, then QuickTest concludes that it has identified the object and performs the statement containing the object. 4. QuickTest continues the process described in steps 2 and 3 until it either identifies one object, or runs out of optional filter properties to use. If, after completing the Smart Identification elimination process, QuickTest still cannot identify the object, then QuickTest uses the learned description plus the ordinal identifier to identify the object. If the combined learned description and ordinal identifier are not sufficient to identify the object, then QuickTest stops the run session and displays a Run Error message. Reviewing Smart Identification Information in the Test Results

If the learned description does not enable QuickTest to identify a specified object in a step, and a Smart Identification definition is defined (and enabled) for the object, then QuickTest tries to identify the object using the Smart Identification mechanism. If QuickTest successfully uses Smart Identification to find an object after no object matches the learned description, the Test Results receive a warning status and indicate that the Smart Identification mechanism was used. If the Smart Identification mechanism cannot successfully identify the object, QuickTest uses the learned description plus the ordinal identifier to identify the object. If the object is still not identified, the test or component fails and a normal failed step is displayed in the results. Walking Through a Smart Identification Example

The following example walks you through the object identification process for an object. Suppose you have the following statement in your test or component: Browser("Mercury Tours").Page( "Mercury Tours").Image( "Login"). Click 22,17 When you created your test or component, QuickTest learned the following object description for the Login image:

Page 22: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

21 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

However, at some point after you created your test or component, a second login button (for logging into the VIP section of the Web site) was added to the page, so the Web designer changed the original Login button's alt tag to: basic login. The default description for Web Image objects (alt, html tag, image type) works for most images in your site, but it no longer works for the Login image, because that image's alt property no longer matches the learned description. Therefore, when you run your test or component, QuickTest is unable to identify the Login button based on the learned description. However, QuickTest succeeds in identifying the Login button using its Smart Identification definition. The explanation below describes the process that QuickTest uses to find the Login object using Smart Identification:

1. According to the Smart Identification definition for Web image objects, QuickTest learned the values of the following properties when you recorded the click on the Login image:

Page 23: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

22 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

2. QuickTest begins the Smart Identification process by identifying the five objects on the Mercury Tours page that match the base filter properties definition (html tag = INPUT and image type = Image Button). QuickTest considers these to be the object candidates and begins checking the object candidates against the Optional Filter Properties list. 3. QuickTest checks the alt property of each of the object candidates, but none have the alt value: Login, so QuickTest ignores this property and moves on to the next one. 4. QuickTest checks the name property of each of the object candidates, and finds that two of the objects (both the basic and VIP Login buttons) have the name: login. QuickTest filters out the other three objects from the list, and these two login buttons become the new object candidates. 5. QuickTest checks the file name property of the two remaining object candidates. Only one of them has the file name login.gif, so QuickTest correctly concludes that it has found the Login button and clicks it. Step-by-Step Instructions for Configuring a Smart Identification Definition You use the Smart Identification Properties dialog box, accessible from the Object Identification dialog box, to configure the Smart Identification definition for a test object class.

Page 24: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

23 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

To configure Smart Identification properties: 1. Choose Tools > Object Identification. The Object Identification dialog box opens.

2. Select the appropriate environment in the Environment list. The test object classes associated with the selected environment are displayed in the Test object classes list. Note: The environments included in the Environment list are those that correspond to the loaded add-in environments. 3. Select the test object class you want to configure. 4. Click the Configure button next to the Enable Smart Identification check box. The Configure button is enabled only when the Enable Smart Identification option is selected. The Smart

Page 25: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

24 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Identification Properties dialog box opens:

5. In the Base Filter Properties list, click Add/Remove. The Add/Remove Properties dialog box for base filter properties opens.

6. Select the properties you want to include in the Base Filter Properties list and/or clear the properties you want to remove from the list. Note: You cannot include the same property in both the base and optional property lists. You can specify a new property by clicking New and specifying a valid property name in the displayed dialog box.

Page 26: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

25 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Tip: You can also add property names to the set of available properties for Web objects using the attribute/ notation. To do this, click New. The New Property dialog box opens. Enter a valid property in the format attribute/ and click OK. The new property is added to the Base Filter Properties list. For example, to add a property called MyColor, enter attribute/MyColor. 7. Click OK to close the Add/Remove Properties dialog box. The updated set of base filter properties is displayed in the Base Filter Properties list. 8. In the Optional Filter Properties list, click Add/Remove. The Add/Remove Properties dialog box for optional filter properties opens.

9. Select the properties you want to include in the Optional Filter Properties list and/or clear the properties you want to remove from the list. Note: You cannot include the same property in both the base and optional property lists. You can specify a new property by clicking New and specifying a valid property name in the displayed dialog box.

Tip: You can also add property names to the set of available properties for Web objects using the attribute/ notation. To do this, click New. The New Property dialog box opens. Enter a valid property in the format attribute/ and click OK. The new property is added to the Optional Filter Properties list.

Page 27: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

26 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

For example, to add a property called MyColor, enter attribute/MyColor. 10. Click OK to close the Add/Remove Properties dialog box. The properties are displayed in the Optional Filter Properties list.

11. Use the up and down arrows to set your preferred order for the optional filter properties. When QuickTest uses the Smart Identification mechanism, it checks the remaining object candidates against the optional properties one-by-one according to the order you set in the Optional Filter Properties list until it filters the object candidates down to one object.

VIII)How to identify broken links in QTP?

Broken Links also sometimes called as dead links are those links on the web which are permanently unavailable. Commonly found, 404 error is one example of such link. Now the question is how can we identify broken links with the help of QTP during the run session? There can be two ways to do this:

Using Automatic Page checkpoint.

By manually creating a Page checkpoint.

Page 28: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

27 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Using Automatic Page checkpoint: Go to Tools > Options > Web > Advanced and check the two boxes labeled "Create a checkpoint for each page while recording" and "Broken Links"

Now every time you record a new page, QTP will automatically include a checkpoint for broken links.

By manually creating a Page checkpoint:

QTP does not provide a direct menu option to incorporate a page checkpoint. You need to take the help of standard checkpoint. Start recording session > Insert > Checkpoint > Standard Checkpoint (OR press F12). Place and click the hand pointer anywhere on your web page. Select Page (As shown in picture below) and Click OK.

Page 29: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

28 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

You will get the following screen: Check "Broken Link" checkbox down below and click OK. Now, how will you verify page checkpoint and hence broken links? Run the above script. Go To Test Results > Your Check Point. Check the status of all links under "Broken Links Result" If you want to verify links pointing only to the current host check the box titled "Broken

Links- check only links to current host" under Tools > Options > Web. Similarly If you want to verify links pointing to other hosts as well, uncheck it.._,_.___

XI) Creating MS word document in QTP?

Page 30: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

29 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

How many of you guys ever thought of creating a MS doc file with the help of QTP. It is in fact quite simple to create one. Let me show you a sample script of creating a very simple document in MS Word.

Dim obj_MSWord Set obj_MSWord = CreateObject( "Word.Application") obj_MSWord.Documents.Add obj_MSWord.Selection.TypeText ("This is a simple text") obj_MSWord.ActiveDo cument.SaveAs "D:\Expert.doc" obj_MSWord.Quit

Now you will try to copy paste this code in your QTP but due to some formatting problems you may not get the proper format. Please take care of the quotes before Word.Application. These should be double quotes else your script won’t run.

X) QTP file handling?

Many a times you may need to interact with text files using QTP. Interaction can be(but not limited to) in the form of reading input from a file, writing output to a file. This post describe in detail "File handling using QTP". We use FSO object to do this.

What is FSO? FSO stands for File System Object. This is used to support text file creation and manipulation through the TextStream object and is contained in the Scripting type library (Scrrun.dll) The FSO Object Model has a rich set of properties, methods and events to process folders and files.

How to create a file? We first create a FSO object using CreateObject and then create a text file using CreateTextFile.

For Example:

Suppose you want to create a file called "test.txt" located in C:

Dim fso, file, file_location file_location = "C:\file_location" Set fso = CreateObject("Scripting. FileSystemObject ") Set file = fso.CreateTextFile( file_location, True) // True--> file is to be overwritten if it already exists else false

We would use the same example for the rest of this post.

Page 31: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

30 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

How to open a file?

Set file= fso.OpenTextFile( "C:\file_ location" , ForWriting, True) //2nd argument can be ForReading, ForWriting, ForAppending //3rd argument is "True" if new file has to be created if the specified file doesn't exist else false, blank signify false.

How to read content from a file? Use ReadLine() method For example:

Set file= fso.OpenTextFile( "C:\file_ location" , ForReading, True) //2nd argument should always be "ForReading" in order to read contents from a file Do while file.AtEndofStream <> True data = file.ReadLine( ) msgbox data Loop

How to write content to a file? You can use Write() or WriteLine() Methods to write text into a file. The difference between the Write() and WriteLine() Method is that the latter automatically inserts a new line character while the former doesn't insert a new line character.

For example:

Set file= fso.OpenTextFile( "C:\file_ location" , ForWriting, True) //2nd argument should always be "ForWriting" in order to write contents to a file file.Write(" This is a place to get all your qtp") file.Write(" questions and answers solved.") //Output will be: This is a place to get all your qtp questions and answers solved. file.WriteLine( "This is a place to get all your qtp") file.Write(" questions and answers solved.") //Output will be: This is a place to get all your qtp questions and answers solved.

How to delete content? Use DeleteFile() method to delete a file from a particular location Foe Example:

Page 32: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

31 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

file_location = "C:\file_location" Set fso = CreateObject("Scripting. FileSystemObject ") fso.DeleteFile( file_location)

XI) Guidelines to select an appropriate automation tool?

If your organization is currently using manual means to test your software applications & is believing that it can derive tangible benefits by automating its software testing process, then simply jumping to a conclusion of buying some tool simply because it is popular among many, may not be wise. What should be done now is to take a judicious decision through a scientific process to find out as to which tool will best be suited to your needs. Since this is an capital intensive move aimed at taking your company to the world of Automated Testing, needs careful examination. When you are shopping for a proper automation tool, you will come across several people ambitiously marketing their products, which may provide solution to variety of automated testing needs. Now the question arises as to whether a particular tool is really suitable to your needs or not. Are you not inclining your choice for a particular tool by making lot many compromises in features. Think that in times to come, your testing needs may become more complicated by the variety of applications coming across for testing & that too under variety of operating systems. Thus following guidelines shall be helpful in evaluating & zeroing down your choice of an appropriate tool for the job at hand, out of a bunch of many testing tools sold by different vendors. Guideline – 1: Understand your True Requirement

Page 33: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

32 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

First of all don't look at & form any type of opinion about any XYZ tool available in the market. This is high time for doing deep introspection of your real needs. It is wise to prepare a comprehensive list of your requirements of software testing at the present moment. Identify the time consuming problems, which you want to solve with the new tool. Identify the technical capabilities your prospective tool should have to be compatible with the environment of your application. Following checklist can be helpful in a judicious compilation of your requirements: a) List down the Compatibility issues: Remember that the tool selected by you has to be compatible with: # The operating systems supported by your application to be tested # The development environments under which the application shall be created # Third party software if any with whom your application needs to be integrated at some stage b) List down the Users of the Tool

# List down the people who will be actually using the prospective tool. Keep the skill levels of the available persons at the back of your mind. # Remember that more powerful tools are bound to be more complex as well. If the skill level of the available manpower (who will be expected to use the prospective tool everyday), does not match the complexity level of the tool, believe me, you are likely to land into many problems in smooth implementation of the tool in your organization. # Think as to whether there is enough time for training your staff within the prevailing time & budgetary constraints, if any. c) List down the Testing requirements Technical requirements like the following needs to be listed down before zeroing down your choice on a particular automation tool. # Identify the types of your own testing problems you wish that your new tool should solve for you. # Identify the problems faced by you during manual testing. # Identify the time constraints coming across while making minor changes to your system. # Identify the shorter regression testing time frames. # Identify the Test data setup requirements. # Identify the Defect tracking requirements you are aiming at.

Page 34: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

33 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

# Identify the Increased test coverage you are looking for. # Identify the Increase in efficiency of the testing process you are looking for. Guideline – 2: Understand the constraints you have

You need to understand various factors, which may compel you to drop down some of the tools from your initial selection list. Such crucial factors need to be identified during the early stages of your tool selection process. a) Environmental constraints

# Environmental constraints can be either related to hardware or the software itself. # The prospective tool must be able to work on the desired operating systems # The prospective tool must not dictate the terms of having some specialized hardware for its working. # Up-gradation of existing hardware like providing more hard disk / More Ram etc. to cope with the requirements of additional scripts and test data likely to be added. # Consider your likely objections to your new tool running under some specific environment, while the software application might be required to run under different environment or operating system. This issue may gain importance from the consideration of the future use of the new tool. b) Credentials of the Vendors & their Clientele It is certain that you won't desire to hang on with problems with your new testing tool. Certainly anyone would like to have a quick, competent & professional solution to the tool related problems arising may be occasionally. Following checklist may come handy in such a situation. # The tool supplier must represent a genuine company. # The tool as a product & its supplying company must be matured enough. # The tool may not be worthwhile at all unless there is enough technical support available. # Find out the clientele of the prospective tool & try to obtain the feedback from such organizations if possible. # Find out the past history of the prospective tool?

Page 35: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

34 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

c) Understand the Quality related characteristics Following quality related constraints of the prospective tool should be helpful # Identify the skill level required for using the prospective tool # Verify as to whether it is possible to have multiple user access # Identify the support and help documentation required. # Verify as to whether it is possible to integrate the prospective tool with other tools. # Ensure that there should not be any possibility of getting your data corrupted by the tool. # Frequency of failure during realistic use # Identify the budgetary constraints if any. Such financial constraints can restrict your choice of buying a particular tool. Remember that it is not the question of just purchasing a particular tool by spending some money. In fact it has been seen that in many cases, the cost of fully implementing the tool can be much higher than the cost of the tool itself. Budgetary constraints shall be applicable not only to the tool purchase cost, but shall cover costs of licensing / AMC's, costs of training and cost of tool implementation etc. We can be in a position to evaluate various tools available in the market after compiling a comprehensive list of our requirements and various constraints. Guideline – 3: Shortlist the most likely suitable tools This is the stage when an extensive research is needed to identify various types of tools available in the market. WWW can be a good place to explore the tool. Preliminary study of the technical brochure of every tool shall reveal the capabilities of the tool fitting your requirements & constraints. We can identify various features of every tool by classifying them like a) Essential features b) Desirable features c) Less relevant features etc. a) Essential features: are the ones, which are extremely necessary to meet your requirements within the defined constraints. b) Desirable features: are the ones, which will make a particular tool standout among many of its competitors. Based upon the presence of variety desirable features, your decision can be favor of a particular tool among many more.

Page 36: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

35 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

c) Irrelevant features: are the ones, which are not of any great significance & may not be able to provide some tangible benefit to you in your present requirements. Evaluation of the above types of features is the next exhaustive & iterative exercise. At this stage you should evaluate as much number of tools as possible and try to zero down your focus on around 5-6 tools any one of which could qualify to be the final tool fitting your ultimate choice. The next step in the process should be establishing a contact with the tool suppliers & organizing a practical demonstration. If possible you can ask for an evaluation or trial version of the tool for refining your decision. At this stage you should clearly explain all your requirements of testing along with set of constraints to the tool supplier, who shall be in a better position to clarify many points left out by you during your short-listing process. Guideline – 4: Making a Final Choice Having gone through the above-defined rigorous process of evaluation, the time has come for you to take a decision in favor of one particular tool, which suits best into your slot of requirements & constraints. a) Final Comparison of Features: # With the help of all available data now you should be able to draw a clear comparison of the performance related features of the tools as desired by you vis-a-vis features claimed to be present in the technical literature provided by the persons marketing the tool. # This is stage to go on for verification of the credential of the particular tool from the present users by visiting their web sites or making contact through other channels. This shall help you in refining your choice of a particular tool. b) Practical demonstration at your site: If a particular tool has already caught your attention, you can ask the supplier to organize a live demonstration of the tool under your actual working environment. This way you will be able to judge the technical capability of the supplier as well in providing support later-on. c) Maintenance of Test Script Proper maintenance of automation scripts & ease of handling them is very important aspect of the tool under evaluation. Although we may not be able to make an on the spot judgement about this capability, but this aspect gets confirmed during the second or third release of testing after implementing the new tool. d) Final Comparative Trial Now this is the time for conducting same test on one particular application time & again on each & every short-listed tool independently. This way you shall be in a position to make a final decision in favor of a particular tool out of a box of many.

Page 37: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

36 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

XII) Introduction to Test Automation Framework

Judiciously testing all possible permutations of such components creates a highly complex testing situation with hundreds or thousands of testing scenarios. Under such situations there comes a need for automating the testing process with the help of automation framework approach, which can help in achieving detailed testing with great reduction in testing time. It can never be a workable idea to automate all the test cases. Hence it is important to scientifically understand the areas which can be automated. Remember that an ad-hoc approach to test automation can in fact, lead to longer testing time and poor quality irrespective of the name & fame of the testing tool selected by you. Now let us understand what is `Test Automation Framework'? Test Automation Framework is a set of assumptions, concepts and practices which provide necessary support for the automated software testing. The main advantage of such a framework is the low cost for maintenance. If there is change to any test case then only the test case file needs to be updated and the Driver Script and Startup script will remain the same. There's no need to update the scripts in case of changes to the application.

Types of Automation Framework: 1) Modularity driven framework: It requires the creation of small, independent scripts that represent modules, sections, and functions of the application- under-test. These small scripts are then used in a hierarchical fashion to construct larger tests, realizing a particular test case. It

Page 38: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

37 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

applies the principle of abstraction or encapsulation in order to improve the maintainability and scalability of automated test suites. 2) Data driven framework: It involves bunch of several interacting test scripts clubbed with their related data results. In this framework, variables are used for both input values and output verification values: navigation through the program, reading of the data sources, and logging of test status and information are all coded in the test script. It is quite suitable framework for use in RFT using Data-pools. This approach reduces coding effort to a great extent in case of large test cases, which otherwise could be quite time-consuming & cumbersome. 3) Keyword driven framework: It involves automated tests, which have inherent reusability and therefore ease of maintenance of tests that have been created at a high level of abstraction. It divides test creation into two stages like a) Planning Stage: Involving analysis of the requirements for the application to determine which operations and objects have to be tested. E.g. an application having web based questionnaire will require a large amount of text entries. b) Implementation Stage: It differs according to the tool or framework used. Generally automation engineers implement a framework that provides keywords like "check" and "enter". Testing engineers (who don't have to know the coding) write the test cases based on the keywords defined in the planning stage that have been implemented by the engineers. The test is executed using a driver who reads the keywords and executes the corresponding code. Keyword Driven Framework methodology requires more planning and a longer initial time-investment than going directly to the test creation stage and recording a test, it does make the test creation and test maintenance stages more efficient and keeps the structure of individual tests more readable and easier to modify. 4) Hybrid framework: Is a combination of three frameworks. This type of frameworks evolve over a passage of time and across multiple projects. It is the most successful automation frameworks, which generally accommodates both Keyword-driven testing as well as Data-driven testing. This allows data driven scripts to take advantage of the powerful libraries and utilities that usually accompany a keyword driven architecture. In this case, the framework utilities can make the data driven scripts more compact and less prone to failure. The utilities can also facilitate the gradual and manageable conversion of existing scripts to keyword driven scripts as & when required. On the other hand, the framework can use scripts to perform some tasks that might be too difficult to re-implement in a pure keyword driven approach, or where the keyword driven capabilities are not yet in place.

Page 39: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

38 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Ten Steps for Test Automation Framework Methodology: 1) Identification of the Scope of Testing: Company oriented, Product oriented, Project Oriented. 2) Identification of the Needs of Testing: Identify Types of testing e.g. FT, Web Services etc. and application / modules to be tested.} 3) Identification of the Requirements of Testing: Find out the nature of requirements, identify type of actions for each requirement & identify high priority requirements.

4) Evaluation of the Test Automation Tool: Evaluation checklist, Identify the candidate tools available in the market, Sample run, rate & select the tools, Implementation & Training

5) Identification of the Actions to be automated: Actions, Validations & requirements supported by the Tool

6) Design of the Test Automation Framework: Framework guidelines, validations, Actions Involved, Systems involved, Tool Extensibility Support, Customs messages & UML Documentation.

7) Design of the Input Data Bank: Types of Input file. Input files – Categorization & Design of file prototypes. 8) Development of the Automation Framework: Development of script based upon framework design, Driver scripts, Worker Scripts, Record / Playback, Screen / Window / Transaction, Action / Keyword & Data Driven. 9) Population of Input Data Bank: Different Types of data Input, Populate data from different data sources, Manual input of data and Parent – Child data hierarchy. 10) Configuration of the Schedulers: Identify scheduler requirements & configure the schedulers.

Benefits of Test Automation Framework Approach: Test Automation Framework built with systematic approach yields following benefits: # Ensures consistency # Significant reduction in the amount of code to develop & maintain thereby reducing the testing cycle time. # Comprehensive coverage against requirements. # Use of a "Common Standard" across the organization / Product team / Project team

Page 40: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

39 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

# Maximizes reusability of test scripts ( Utility Functions) # Provides a structured for test library having systematic maintenance of automation scripts # Data Pooling # Protects non-technical testers from the code

X XII) Create a Schedule to Run QTP at a Desired Time

Every Microsoft Windows has a wonderful feature of "Task Scheduler", which can be used for automatically running any application at any desired time, at desired frequency right from a specified date for initial launch. Once scheduling is done, it does not require any user intervention; however the only important thing to remember is that the PC must be kept on at the scheduled time. This "Task Scheduler" utility is available in Windows "Control Panel" by the name "Scheduled Tasks". Detailed steps are described as under. 1) Say our aim is to automatically run the file by the name QTP_Test.vbs available at the location C:\ExpertQTP\ QTP_Test. vbs 2) Go to Windows "Control Panel" -> "Scheduled Tasks". 3) Click on "Add Scheduled Task" in the "Scheduled Tasks" 4) This will start the "Scheduled Tasks Wizard".

5) Click on "Next" - > Browse - > In "Select Program to Schedule" screen Go to the location of the QTP_Test.vbs file available in C:\ExpertQTP folder - > Click "Open" as described in the following picture.

6) In the "Scheduled Tasks Wizard" select the schedule for running the QTP Script. For example Daily, or Weekly or Monthly as per various options offered in the Wizard. In or example select say "Daily". Then Click "Next" as described in the following picture.

7) Select the Time & day you want to start this Script. Then Click "Next" as described in the following picture.

Page 41: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

40 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

8) Enter the "User Name" & Password for the workstation, just only once as described in the following picture.

This way wizard will not ask the user for his manual intervention of feeding the password every time. 9) Click "Finish" 10) Above mentioned simple steps shall now execute the desired script automatically, every day at 12.59PM starting from 07/13/2008.

XIII) Points to take care before starting QTP and QC?

QTP * Always start QTP first then start the application that you want to automate. * Try to avoid the Text Checkpoint, GetText function and other similar functions that deal with screen resolution as this may fail your test in the long run. Test Director/Quality Center with Web Add-In If you are working on Web app along with TD/QC open, you might witness that the app opens up on TD/QC browser itself during playback instead of opening in a separate window. The answer for this is to set the index property for browser.

XIV) How to Manage your Files using QTP

Sometimes as a QTP programmer, we may need to keep track about the files inside our Operating system. Apart from tracking our files, we need to manage them dynamically like files can be created, files can be read, files can be edited and deleted. In order to accomplish this task, we require FileSystemObject. It contains methods to carry all administrative tasks related to files. Getting access of an already created file

For this, use the below written code. Set obj=CreateObject( "Scripting. FileSystemObject ") obj.getFile( "D:\testfile.txt") In order to run this code perfectly fine, the File "testfile.txt" should be present in the D:\ location else QTP will raise an error.

Page 42: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

41 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

As you can see in the above mentioned code, we have provided the complete path for the file which we also call as Absolute path. Now this code is not of much use unless we do something more along with it. Like after getting the reference for a file, we can see the size of the file, its parent folder, its name etc. Check for the existence of an already created file Sometimes we may be interested in knowing whether our file exists or not. For this, we use "FileExists" method. This checks whether the files exists or not. The "FileExists" method requires a single argument containing the full path of the file. This method returns a boolean value. I hope you guys must be aware of what a boolean value is. Now this method will return a value "True" if the file exists and "False" if the file doesn't exists. The below mentioned code will explain in detail: Set testobj = CreateObject( "Scripting. FileSystemObject ") If test.FileExists( "D:\Expert\ MyTestFile. txt") Then Set objFile = testobj.GetFile( "D:\Expert\ MyTestFile. txt") Else MsgBox "The file doesn't exist." End If Deleting the File

We can delete a file by firstly creating an instance of FileSystemObject and then we need to call the DeleteFile method. Lets see the below mentioned code to explain this concept. Set myobj = CreateObject( "Scripting. FileSystemObject ") myobj.DeleteFile( "D:\MyTestFile. txt") You can even delete your MS Word file with the above code. Cool na.... I know. Let me show you something even more interesting. If the file is read-only, then the "DeleteFile" method will not be able to delete the file. So how to delete such a file? Any guesses. This thing is left for you guys to find it out how we can delete a read only file. Copy Files Copying files from one location to another is also a very frequently done task. For this, we use CopyFile method. The syntax for copying files is: obj.CopyFile "Source-File- Path", "Destination- File-Path"

Page 43: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

42 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

In order to copy a file from "C:\test.txt" to "D:\test.txt" , we will use the code: Set obj=CreateObject( "Scripting. FileSystemObject ") obj.CopyFile "C:\test.txt" , "D:\test.txt" We can even rename a file just by changing the name of the file in the "Destination- File-Path" . What happens if we try to copy a copy inside a folder and the folder doesnt exist? This thing is left for you guys to try. Moving Files

We can also move files from one one location to another[Also known as Cut and Paste]. For this, we require MoveFile method. It is infact quite similar to CopyFile method. We use the below code to move files from one location to another. Set obj=CreateObject( "Scripting. FileSystemObject ") obj.MoveFile "C:\test.txt" , "D:\test.txt" Reading all contents of a file in a single shot

We can read all the contents of a file using the ReadAll method. It captures all the file contents and stores inside a variable. The following code will help you in reading all contents of a file "D:\test.txt" . Set obj1= CreateObject( "Scripting. FileSystemObject ") Set obj2= obj1.OpenTextFile( "D:\test. txt") FileContents = obj2.ReadAll 'Read all contents of the file MsgBox FileContents 'Display contents of file obj2.Close 'Close the File Reading all contents of a file line by line

We can read all the contents of a file line by line. For this we require the ReadLine method. The following code will help you in reading all contents of a file "D:\test.txt" line by line. Set obj1= CreateObject( "Scripting. FileSystemObject ") Set obj2= obj1.OpenTextFile( "D:\test. txt") Do Until obj2.AtEndOfStream Line=obj2.ReadLine msgbox Line Loop obj2.Close

Page 44: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

43 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

XV) All about Recovery Scenarios using QTP

Introduction to Recovery Scenarios: While executing scripts, we usually encounter unexpected & unpredictable events & errors, which results into application crashing during a run session causing total disruption of the run session and distortion of results. Such problems are quite frequent especially when the tests are made to run unattended. In such a case the test process halts until the user perform some desired recovery operation. Recovery scenarios are useful when it is difficult to predict at which step the errors can come or when we are confident that the error will not come in the QTP script, whereas it can be anywhere outside the QTP Script. For illustration; Pop-up message of "out of paper", as caused by the printer device driver. "On error resume next" is preferred when we sure that the error is expected one and wish to perform some other actions. In order to handle such situations QTP comes to our rescue by creating recovery scenarios and associates them with the particular tests. What does a Recovery Scenarios do is to activate a specific recovery operation when a trigger events takes place. Most simple example of a typical unexpected & unpredictable events & errors is like Incompatible Media in portable Drive. The Recovery Scenario Manager presents a structured wizard which helps us in defining the recovery scenario, like detailed definition of the unexpected event and the operations required to recover from the exception during the run session. Advantages of Recovery Scenario Manager: Recovery Scenario Manager can be used to handle several known errors occurring at runtime. Following four events available in the recovery scenario manager are extremely helpful 1) Application Crash: This event is useful in handling crashed applications at runtime. 2) Pop Up Window: This event is useful in managing various unwanted application windows, which get built-up at runtime. 3) Test Run Error: This event is useful in handling VBScript statement errors at runtime. 4) Object State: This event is useful in handling object related errors at runtime. Elements of Recovery Scenario: Steps to handle the exceptions are:

Page 45: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

44 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

1) Trigger Event: Is an unexpected event like appearance of a Pop-up window, object state, test run error causing application crash or interruption in our running session. 2) Recovery Steps: Constitutes a series of steps required to be performed to enable QTP to proceed further with the process of test after some trigger event has interrupted the run session. Examples of a recovery operation can be 1) A keyboard or mouse Operation like a Click over the "OK" button in the Pop-up window 2) Close Application Process 3) Function Call 4) Restarting the OS etc. 3) Post-Recovery Test Run: Are a set of instructions designed to be provided to QTP on proceeding further with the test after some recovery operation has been carried out. Examples of Post Recovery actions can be repeating the complete test from the beginning or some steps may be skipped altogether & continuing with the remaining steps in the test. QTP & Recovery Scenarios: All Recovery scenarios get saved & logically grouped in recovery scenario files. Grouping of various recovery scenarios in recovery scenario file can be managed according the user requirements. Recovery scenario files carry a typical extension of .rs. In order to instruct QTP to carry out a recovery scenario during a particular test run, we firstly associate it with the particular test. There is no limitation to any fixed number of recovery scenarios associated with a test. Order of execution of various recovery scenarios associated with a test can easily be prioritized, thereby the trigger events get recognized and handled in the desired sequence. Whenever any error comes during the execution of a test having many recovery scenarios associated with it; QTP intelligently hunts for the defined trigger event which had caused the particular error. After detecting the trigger event, QTP automatically performs the desired recovery steps and post-recovery test runs etc. Recovery statements can be inserted in the tests to comfortably control and activate the recovery scenarios during the test run. Cons of Recovery Scenarios: Although Recovery Scenarios are users friendly on one hand; they tend to slow down the speed of the Test Run. Presence of a few such recovery scenarios would reduce the speed of Test Run significantly. This can become irritant to the testers, who can prefer the approach of using VBScript On Error/Goto 0 far more useful for catching & handling small errors.

Page 46: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

45 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

XVI) How to Record Right Mouse Clicks using QTP

For recording the right mouse clicks in QTP, we need to manually modify the configuration file and then load it. This is a great article extracted from QTP Help Guide, which leads us through important steps to configure QTP to record our Right Mouse Clicks. Step –1: Choose Tools > Web Event Recording Configuration. The Web Event Recording Configuration dialog box opens.

Step –2: Click the Custom Settings button. The Custom Web Event Recording Configuration dialog box opens.

Step –3: In the Custom Web Event Recording Configuration dialog box, choose File > Save Configuration As. The Save As dialog box opens. Step –4: Navigate to the folder in which you want to save the web event recording configuration file, and enter a configuration file name. The extension for configuration files is .xml. Step –5: Click Save to save the file and close the dialog box. Step –6: Open the saved configuration file for editing in any text editor. The configuration file uses a defined structure. The beginning of the file, which is relevant for Web objects, is shown below.

The Property Name argument controls the recording of the mouse buttons. The value of the mouse buttons are defined as follows: 1—Left 2—Right 4—Middle Step –7: Edit the file as follows: To record a left mouse click for the onmouseup event, add the following line: To record right and left mouse clicks for the onmousedown event, add the following lines:

Page 47: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

46 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Note: Only one event, either onmouseup or onmousedown, should be used to handle mouse clicks. If both events are used, QTP will record two clicks instead of one. By default, QTP listens for the onmouseup event. Step –8: Save the file. Step –9: In the Custom Web Event Recording Configuration dialog box, choose File > Load Configuration. The Open dialog box opens. Step –10: Navigate to the folder in which you saved the edited configuration file, select the file, and click Open. The Custom Web Recording Configuration dialog box reopens. Step –11: Click OK. The new configuration is loaded, with all preferences corresponding to those you defined in the XML configuration file. Any Web objects you now record will be recorded according to these new settings.

XVII) Exploit the Power of MS Excel through QTP

The objective of this article is to briefly understand the process of interaction of MS Excel and VBScripts. For automating an application a framework is created in the beginning. This requires an independent structure for reporting and data. Microsoft Excel plays a very important role in this framework approach.

We can easily use the built-in mechanism of QTP through which we can display the test results in a predefined format. A result sheet gets generated after the execution of the test in QTP; which provides an in-depth view of the script – through which we can know the various point of failures, warnings and the passes. In the test script we create customize various checkpoints at our will. Likewise the result file can also be customized based upon the checkpoints already created according to the defined criterion of Pass / Fail. Generally while working in MS Excel, the user desires to generate a detailed report of the entire test. The idea of generating such detailed / customized report is to have the output in a format as per our own choice and to preserve the file in a centralized location.

Page 48: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

47 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

The entire process can be performed in following basic steps: Step-1: Understanding the hierarchy of MS Excel Application. Step-2: Creation of the desired Object in MS Excel Step-3: Creation of a new MS Excel workbook or opening an existing one. Step-4: Setting the objects for various sheets in the workbook. Step-5: Writing and fetching the data values in the cells. Step-6: Saving and closing of the workbook Step-7: Closing the application and clearing the memory The above steps can be explained through suitable illustrations to understand the approach properly. Understanding the hierarchy of Excel Application It is believed that the user is fairly acquainted with the basics of MS Excel like: 1) What is MS Excel Application 2) What are Workbooks in Excel 3) What are Sheets in Excel 4) What are Cells in Excel Hence I am skipping the basic explanation of the above basics of MS Excel & directly moving on to the main content of our topic. Some of the simple VBScripts are being described below for performing various actions in MS Excel. Creation of an Object in Excel: In the process of reporting it is the first step. In MS Excel the reporting can be done in two ways like 1) in the background wherein the application shall not be visible 2) the application can be made visible to the user once the process of writing or fetching the data is going on.

Page 49: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

48 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

However in both the above mentioned methodologies we need to create objects in Excel Application for example: Dim xl Set xl = CreateObject( "Excel.Application") When we run the above script, we can see a process named "Excel.exe" in the Windows task Manager. Creating a new workbook or Opening an existing one:

After creation of the object in Excel, it implies that Excel application has been invoked, however it is not visible. From now on we can either continue to perform the operations in the invisible back ground alternatively we can make the application visible and then we can perform the operations. To make the application visible: xl.visible = true To open a new Workbook: xl.workbooks. Add To open an existing Workbook: xl.workbooks. Open("File Name with complete path") Setting and accessing the objects of sheets in workbook: After opening a workbook in Excel (A New one or opening an existing one), next activity is to feed some data in various cells in various sheets of our workbook.

MS Excel provides three sheets in a workbook by default, which are available to us for performing various operations. To access these sheets with great ease, we need to create objects referencing these sheets. This will help us in avoiding describing complete hierarchy time & again. For example we wish to create a reference for a sheet with an index i, beginning from 1: Set sht1 = xl.activeworkbook. sheets(i) We can easily add or delete the desired sheets from the active workbook To add a sheet in the workbook: xl.activeworkbook. sheets.add

Page 50: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

49 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

To delete a particular sheet: ( where i represents the index which begins from 1) xl.activeworkbook. sheets(i) .delete To change the name of the sheet: xl.activeworkbook. sheets(i) .name = "Name of your choice" To count total number of sheets in a workbook: Countnt = xl.activeworkbook. sheets.count Writing and fetching the data values in the cells:

To write the data in Excel sheet, we need to identify the Cell ID of the cell where the data is needed to be written. Similarly for accessing the data value from particular cells, we must know their Cell ID. For an example we want to write some data in sheet2 cell ID as D8, the command can be written as under. Here "D" represents the Column Number & "8" represents the Row Number. xl.activeworkbook. sheets(2) .cells(8, 4) = "hello" To fetch the data from sheet3 cell ID A7: Val = xl.activeworkbook. sheets(3) .cells(7, 1) If an object has already been created in a particular sheet, we don't have to repeat the complete hierarchy again, instead we can simply write: Object.cells( row,col) = value

Saving and closing a workbook:

After finishing the work we can save the workbook to a desired location with a different name or save the changes made to an already existing open workbook. To save the new workbook under a new name: xl.activeworkbook. saveas "path_with_file_ name.xls" To save the changes made in an existing workbook: xl.activeworkbook. save To close a workbook: xl.activeworkbook. close

Page 51: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

50 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Closing an application and clearing the memory: To close the application: xl.quit To clear the memory from all objects: Set xl = nothing This is not the end; however it is just a beginning for us to explore the power of QTP in exploiting the potential of MS Excel through simple VBScripts.

XVIII) Smart Identification: A Fantastic Feature of QTP

QTP has a unique feature by the name Smart Object Identification or recognition which is used for identifying the objects smartly, whenever the normal identification fails due to the dynamic changes in the properties of the objects. Smart Identification is nothing but an algorithm used by the QTP when it is not able to recognize an object. A simple generic example as per the QTP manual would be, A photograph of a 8 year old girl and boy and QTP records identification properties of that girl when she was 8, now when both are 10 years old then QTP would not be able to recognize the girl. But there is something that is still the same, that is there is only one girl in the photograph. So a kind of PI - Programmed intelligence is needed instead of AI. Object identification is necessary to recognize the GUI objects on the screen. During automatic recording of a script, the object identifier records various objects present on the screen. The smart identification feature of QTP smartly identifies all the objects irrespective of their being developed using same technology or not, e.g. smart identification shall be able to identify the objects in an application although developed in Java but using some of the Microsoft controls as well. QTP identifies a particular object by comparing the properties of its test object and the run time object. QTP may not be able to recognize any dynamic objects whose properties or even the description may undergo some changes during the run time. Thus its great option of enabling Smart Identification helps us in identifying the objects even if their properties have undergone changes during the run time. If QTP is not able to detect any object having description matching with that of the recorded object, or in case it detects more than one object having matching description, then QTP ignores the recorded description, and uses the Smart Identification feature to identify the object. Smart Identification mechanism is a bit complex, but flexible. However, if configured

Page 52: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

51 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

logically, Smart Identification definition can help QTP in detecting an object, of course - if present, in-spite of failure of the recorded description. Understanding the Smart Identification Process: (Ref. Quick Test Professional 9.0 – Help Guide) If QTP activates the Smart Identification mechanism during a run session (because it was unable to identify an object based on its learned description) , it follows the following process to identify the object: 1) QTP "forgets" the learned test object description and creates a new object candidate list containing the objects (within the object's parent object) that match all of the properties defined in the Base Filter Properties list. 2) QTP filters out any object in the object candidate list that does not match the first property listed in the Optional Filter Properties list. The remaining objects become the new object candidate list. 3) QTP evaluates the new object candidate list: # If the new object candidate list still has more than one object, QTP uses the new (smaller) object candidate list to repeat step 2 for the next optional filter property in the list. # If the new object candidate list is empty, QTP ignores this optional filter property, returns to the previous object candidate list, and repeats step 2 for the next optional filter property in the list. # If the object candidate list contains exactly one object, then QTP concludes that it has identified the object and performs the statement containing the object. 4) QTP continues the process described in steps 2 and 3 until it either identifies one object, or runs out of optional filter properties to use. If, after completing the Smart Identification elimination process, QTP still cannot identify the object, then QTP uses the learned description plus the ordinal identifier to identify the object. If the combined learned description and ordinal identifier are not sufficient to identify the object, then QTP stops the run session and displays a Run Error message. How to Analyze Smart Identification Information displayed in the Test Results? (Ref. Quick Test Professional 9.0 – Help Guide) If the recorded description does not enable QTP to identify the specified object in a particular step, and a Smart Identification definition is defined (and enabled) for the object, then QTP

Page 53: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

52 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

tries to identify the object using the Smart Identification mechanism. There are two possible scenarios. Scenario –1: No Object Matches the Recorded Description If QTP happens to successfully use the Smart Identification feature to recognize an object after no object found to match with the recorded description, the Test Results receive a warning status by providing the information like the following in the results details: 1) An indication that the object (for example, the userName WebEdit object) was not found. 2) An indication that the Smart Identification mechanism successfully found the object, and information about the properties used to find the object. You can use this information to modify the recorded test object description, so that QTP can find the object using the description in future run sessions. 3) Normal result details for the performed step. The following screenshot displays the results for a test in which Smart Identification was used to identify the userName WebEdit object after one of the recorded description property values have changed.

Scenario –2: Multiple Object Match the Recorded Description If QTP happens to successfully use the Smart Identification feature to recognize an object after multiple objects have been found to match the recorded description, QTP shows the Smart Identification information in the Test Results window. The step still receives a `Passed' status, because in most of the cases, if Smart Identification was not used, the test object description plus the ordinal identifier could have potentially identified the object.

In such a situation, the Test Results shows information like the following in the results details: 1) An indication that the Smart Identification mechanism has successfully found the object, and information about the properties used to find the object. This information can be used to create a unique object description for the object, so that QTP can find the object using this description in the future run sessions. 2) Normal result details for the performed step. The following screenshot displays the results for a test in which Smart Identification was used uniquely identifies the Home object after the recorded description resulted in multiple matches.

Page 54: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

53 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

If the Smart Identification mechanism cannot successfully identify the object, the test fails and a normal failed step is displayed in the Test Results. Smart Identification Feature of QTP uses two types of properties: a) Base filter properties: Are the most fundamental properties of a particular test object class. Her we cannot change their values without changing the essence of the original object. b) Optional filter properties: Are other properties, which help us in identifying the objects of a particular class since these are not likely to get changed frequently. These properties can be ignored in case these are not applicable any more. Smart Identification Example: (Ref. Quick Test Professional 9.0 – Help Guide) The object identification process for an object is described through the following example in great detail. Suppose you have the following statement in your test or component: Browser("Mercury Tours").Page( "Mercury Tours").Image( "Login"). Click 22,17 When you created your test or component, QTP learned the following object description for the Login image:

However, at some point after you created your test or component, a second login button (for logging into the VIP section of the Web site) was added to the page, so the Web designer changed the original Login button's alt tag to: basic login. The default description for Web Image objects (alt, html tag, image type) works for most images in your site, but it no longer works for the Login image, because that image's alt property no longer matches the learned description. Therefore, when you run your test or component, QTP is unable to identify the Login button based on the learned description. However, QTP succeeds in identifying the Login button using its Smart Identification definition. The explanation below describes the process that QTP uses to find the Login object using Smart Identification: 1) According to the Smart Identification definition for Web image objects, QTP learned the values of the following properties when you recorded the click on the Login image:

Page 55: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

54 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

The learned values are as follows: Base Filter Properties: ____________ _ Property Value ____________ __ html tag INPUT ____________ __ Optional Filter Properties:

2) QTP begins the Smart Identification process by identifying the five objects on the Mercury Tours page that match the base filter properties definition (html tag = INPUT and image type = Image Button). QTP considers these to be the object candidates and begins checking the object candidates against the Optional Filter Properties list. 3) QTP checks the alt property of each of the object candidates, but none have the alt value: Login, so QTP ignores this property and moves on to the next one. 4) QTP checks the name property of each of the object candidates, and finds that two of the objects (both the basic and VIP Login buttons) have the name: login. QTP filters out the other three objects from the list, and these two login buttons become the new object candidates. 5) QTP checks the file name property of the two remaining object candidates. Only one of them has the file name login.gif, so QTP correctly concludes that it has found the Login button and clicks it. How to Disable Smart Identification During the run Session: Selection of the option "Disable Smart Identification during the run session", Instructs QTP not to use the Smart Identification mechanism during the run session. When we select this option, the Enable Smart Identification check boxes in the Object Properties and Object Repository dialog boxes get disabled, although the settings are saved. However when you clear this option, the Enable Smart Identification check boxes return to their previous on or off setting. When should we use Smart Identification feature of QTP? As per the suggested best practice we should disable Smart Identification while creating the test cases, so that we are able to recognize the objects which are dynamic or inconsistent in their properties. Moreover once the script gets created, the Smart Identification should be enabled, so that the script does not fail in case of any small change.

Page 56: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

55 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

However the scriptwriter should always check for the test results to verify if the Smart Identification feature had been used to identify a object or not. Sometimes Smart Identification needs to be disabled for particular objects in the OR, this is advisable when you use SetTOProperty to change any of the TO properties of an object and especially ordinal identifiers like index, location and creation time.

XIX) Frequently Asked Interview Questions on QTP

Following Frequently Asked Questions shall be quite helpful in making a reasonably good foundation for attending an interview on QTP. Q 1. What are the salient features of QTP? # It is an automated functional Graphical User Interface testing tool. # It can easily handle "Non-UI" based Test Cases as well. Like API (Certification testing & Database Testing etc. # It is meant for automation of user actions on a web or client based computer application. # It is primarily used for functional regression test automation. # It uses a scripting language based on VBScript # It has an excellent error handling mechanism.# It has excellent data driven testing features.

Q 2. What is Recovery in QTP?

Exception handling is called Recovery in QTP. Its primary aim is to enable the tests to continue to run in case of an occurrence of an unexpected failure. For example if an application crash occurs and a message dialog appears, QTP can be instructed to attempt to restart the application and continue with the rest of the test cases from there onwards. Q 3. What is a Checkpoint in QTP? In QTP, Checkpoint is used to verify the application under test. It can introduce a checkpoint to verify as to whether a particular object, text or a bitmap is present in the automation run. During a test execution, a checkpoint verifies that the behavior or state of the actual application is consistent with the expected application or not. Q 4. How many types of checkpoints are available in QTP?

Page 57: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

56 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

1) Standard Checkpoint - for checking the properties of an object. 2) Table Checkpoint – for checking the properties of a table. 3) Image Checkpoint – for checking the properties of an image. 4) Bitmap Checkpoint – for comparing an area of the application under test pixel-by-pixel with the screen as seen at record-time. 5) Database Checkpoint for automating the back-end testing. 6) Text Checkpoint – for checking that a section of text is found between two other sections of text. 7) Text Area Checkpoint 8) Page Checkpoint – for checking the properties of a web page. 9) Accessibility Checkpoint – for checking the accessibility of an application. 10) XML Checkpoint Q 5. How many types of main views of a script are available in QTP?

QTP provides two main views of a script. These are 1) Keyword View: is the default test procedure interface of QTP & is most useful for the beginners. It displays the automation steps of a test procedure as a descriptive tree of Actions and functions. The tree contains columns listing the Action or function name, any parameters, and comments.

2) Expert View: is most suitable for the advanced users, enabling them to customize the test, like writing user-defined functions. It is meant for displaying and editing of the source code of the test. Except for the root Global action, all other test actions can be edited here. Expert View acts as an IDE for the test. It includes most standard IDE features, such as breakpoints. Both Keyword View & the Expert View can be selected from tabs available at the bottom of the QTP window. Q 6. How results are generated in QTP? At the end of the test, QTP generates a result file for the test cases, which is in the form of a XML tree.

Page 58: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

57 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

This results file provides detail regarding `Pass' or `Fail' counts, error messages, and all supporting information which allows the user to diagnose the main cause of a failure. Q 7. What is a Virtual Object in QTP? Since sometimes complex objects are not recognized & recorded properly by QTP. Hence an experienced user can define that object as a personal virtual object and build a virtual object repository. This way by the concept of Virtual Object, the user can add some sort of support for such complex objects. If it is possible to extract the desired information from the object, we can do successful record and playback against that object. Q 8. How can we handle the exceptions with the help of recovery scenario manager in QTP? With the help of recovery scenario manager we can recover from unexpected events or errors occurring in the testing environment during the test run. The Recovery Scenario Manager presents a structured wizard which helps us in defining the recovery scenario, like detailed definition of the unexpected event and the operations required to recover from the exception during the run session. Recovery scenario has three steps in handling an exception

a) Triggered Events: Is an unexpected event like appearance of a Pop-up window, object state, test run error causing application crash or interruption in our running session. b) Recovery steps: are a series of steps required to be performed to enable QTP to proceed further with the process of test after some trigger event has interrupted the run session. c) Post Recovery Test-Run: Are a set of instructions designed to be provided to QTP on proceeding further with the test after some recovery operation has been carried out.

Q 9. What is the use of Text output value in QTP? Text Output values enable us to view the values which are taken by the application during the run time. If parameterized, the values change for every iteration. Hence by creating output values, we can capture the values which are taken by the application during the run time and output them to the data table. Q 10. What is the Object Spy feature in QTP? Object Spy enables us to view both the run-time object methods and the test, object methods associated with an object and to view the syntax for a selected method. It is used as a pointer to point towards an object. It displays the object hierarchy tree and the run-time object methods or test object methods associated with the selected object in the Methods tab of the Object

Page 59: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

58 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Spy dialog box. Q 11. What is Automation Object Model in QTP? Like we use QTP for automating the testing of our applications, we can use the automation object model of QTP to automate its own operations as well. With the help of objects, methods, and properties exposed by the automation object model of QTP along with standard programming elements like loops and conditional statements, we can write programs which can configure QTP options and run tests or components instead of performing these operations manually using the QTP interface. Automation programs are especially useful for performing the same tasks several times or on multiple tests or components, or quickly configuring QTP according to the needs for a particular environment or application. Most of the dialog boxes in QTP have a corresponding automation object. Most of the options in dialog boxes can be set retrieved using the corresponding object property, and most of the menu commands and other operations have corresponding automation methods. Q 12. What is a Run-Time Data Table in QTP? During the run session, QTP creates a Runtime Data Table, which is live version of the Data Table associated with our test. During the run session, QTP displays the run-time data in the Data Table pane so that we can see the changes taking place in the Data Table. When the run session ends, the Runtime Data Table closes, and the Data Table pane again displays the stored design-time Data Table. Data entered in the run-time Data Table during the run session does not get saved along with the test. The final data from the run-time Data Table gets displayed in the Run-Time Data Table in the Test Results window. Runtime Data Table is an excel file, which gets stored in the folder of the test created, its name is Default.xls by default.

Q 13. What are the properties used by the Smart Identification mechanism? The Smart Identification mechanism uses two types of properties: a) Base filter properties: Are the most fundamental properties of a particular test object class. Her we can not change their values without changing the essence of the original object. b) Optional filter properties: Are other properties, which help us in identifying the objects of a particular class since these are not likely to get changed frequently. These properties can be ignored in case these are not applicable any more. Q 14. How many scripting languages can be used in QTP? Scripts can be written using languages like Visual Basic, XML, JavaScript, Java, HTML

Page 60: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

59 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Q 15. What are the Commonly used Excel VBA functions. Common functions are: a) Coloring of a cell b) Auto fit cell c) Setting navigation from link in one cell to other Q 16. How QTP identifies various object? During recording QTP identifies various objects and stores them as test objects. For each test object QTP learns a set of default properties called mandatory properties. Simultaneously QTP looks at rest of the objects to check whether these properties are sufficient to uniquely identify the object or not. During the test run, QTP searches for the run time objects, which match with the test objects which, have been captured by it during recording. Q 17. What are object repositories in QTP? When planning and creation of tests is done, we firstly consider how we would like to store the objects in our tests. In QTP, the test objects can be stored in two types of object repositories a) Shared object repository: It stores test objects in a file that can be accessed by multiple tests (in read-only mode). If someone is new to QTP, he can prefer to use local object repositories. This way he can record and run the tests without creating, choosing, or modifying shared object repositories because all objects are automatically getting saved in a local object repository which can be accessed by its corresponding action. b) Local object repository: It stores objects in a file that is associated with one specific action, so that only that action can access the stored objects. If someone is familiar with QTP testing, he can find that it is quite efficient to save the objects in a shared object repository. This way, he can use the same shared object repository for multiple actions - if the actions include the same objects. Test object information that applies to many actions is kept in one centralized location. When the objects in the application change, we can update them in one location for all the actions that use this shared object repository. Q 18. How QTP recognizes objects in object repositories? Object Repository displays a tree of all the objects in the current component or in the current action or in the entire test , depending on the object repository mode selected by the user. We can view or modify the test object description of any test object in the repository or to add new objects to the repository. QTP remembers the default property values and determines in which test object class it fits. If it is not found enough it automatically adds assistive properties, one by one to the description until it successfully compiles the unique description. If no assistive properties are available, then it adds a special Ordinal identifier such as object location on the page or in the source code. Q 19. Is there any built-in function for scripting in QTP?

Page 61: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

60 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

QTP uses an in-built functionality called "Step Generator" to create scripts while appropriate steps are entered into it. Step Generator utility enables us to add steps by selecting from a range of context-sensitive options and entering the required values. We can open the Step Generator from the Keyword View or Expert View while recording or editing our test. We can also open the Step Generator from the Active Screen while editing. Method to open the Step Generator from a function library is as under a) In the function library, click the location in which you want to insert the new step. b) Choose Insert > Step Generator, or right-click and choose Step Generator. Alternatively, press F7. Q 20. How many types of Actions are there in QTP? QTP uses following three kinds of actions: a) Non-reusable action - can be called only in the test with which it is stored, and can be called only once. b) Reusable action - can be called multiple times by the test with which it is stored (the local test) as well as by other tests. c) External action – is a reusable action which is stored with another test. External actions are read-only in the calling test, but we can choose to use a local, editable copy of the Data Table information for the external action. By default, all new actions are non-reusable. We can mark every action created by us in the test as reusable or non-reusable. Q 21. How can we parameterize property values in QTP? Data Driver feature enables us to quickly parameterize several property values for the test objects, checkpoints, and method arguments containing the same constant value within a given action. We can choose to replace all occurrences of a selected constant value with a parameter, in the same way that we can use a Find and Replace All operation instead of a step-by-step Find and Replace process. QTP can also show us each occurrence of the constant so that we can decide as to whether to parameterize the value or not. Method to parameterize a value using the Data Driver is as under: a) Display the action you want to parameterize. b) Choose Tools > Data Driver. Q 22. How can we modify the properties of test object in QTP?

Page 62: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

61 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

We can modify an object by modifying any one of its property values or by changing the set of properties used to identify the particular object. This can be done for objects in the local object repository with the help of Object Repository window, and for objects in the shared object repository using the Object Repository Manager. Method to modify an object property is as under: a) Right-click the step containing the object that changed, and choose Object Properties or choose Edit > Step Properties > Object Properties from the menu bar. b) The Object Properties dialog box opens and displays the properties QuickTest uses to identify the object. c) Modify the properties and values as required. d) Click OK to close the dialog box. Q 23. How to retrieve the property of an object?

We can retrieve the property of an object by the use of "GetRoProperty" . Q 24. How to open or close any application during Scripting? During a run session, we can use SystemUtil, object to open and close the applications and processes.The SystemUtil.Run statement gets automatically added to the test when we run an application from the Start menu or the Run dialog box while recording a test.E.g : SystemUtil.Run "Notepad.exe" SystemUtil.CloseDes cendentProcesses ( Closes all the processes opened by QTP )

Q 25. Why use Regular Expressions?

Regular expressions are used to increase the flexibility and adaptability of the tests. Regular expressions enable QTP to identify objects and text strings with varying values. Regular expressions can be used while defining the properties of an object, the methods of an argument, while parameterizing a step, and while creating checkpoints with varying values

XX) Learn the Basics of Closing the Processes using QTP

The article will discuss on how to close processes in QTP. First we will discuss the SystemUtil object and then later in the article few other approaches.

Page 63: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

62 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

SystemUtil Object

SystemUtil is utility object provided by QTP. It can be used to launch or closes a process. Let's look at various methods supported by this object:

SystemUtil.Run file, [params], [dir], [op], [mode]

The Run method allows running a new process. The code below illustrates few example on how to launch a process using SystemUtil object

'Run internet explorer SystemUtil.Run "iexplore.exe" 'Run internet explorer and open google.com SystemUtil.Run "iexplore.exe" , "http://www. google.com" 'Run a IE Process in Maximized window Const SHOW_MAXIMIZED = 3 'Activates the window and displays it as a maximized window. SystemUtil.Run "iexplore.exe" , "http://www.google.com", , , SHOW_MAXIMIZED SystemUtil.ClosePro cessByName (bsProcessName)

CloseProcessByName method allows closing a process by its name. The code below illustrates few examples

'Close all internet explorer windows closedCount = SystemUtil.ClosePro cessByName( "iexplore. exe") 'Display # of closed windows MsgBox closedCount

The problem with using the above method is that it will also close Quality Center (QC) window even if script was launched from QC. This method should be used in case you are not concerned about running scripts from QC.

SystemUtil.ClosePro cessByWndTitle (bsTitle, [bRegExp])

CloseProcessByWndTi tle method allows closing a process by its title. The title can also be supplied as a regular expression by setting the bRegExp to True

'Launch a notepad window SystemUtil.Run "notepad.exe" 'Close the window just launched using the exact title SystemUtil.ClosePro cessByWndTitle "Untitled - Notepad" 'Launch a notepad window SystemUtil.Run "notepad.exe"

Page 64: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

63 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

'Close the window just launched using a pattern string SystemUtil.ClosePro cessByWndTitle ".*Notepad", True SystemUtil.CloseDes cendentProcesses CloseDescendentProc esses can be used to close any process launched by QTP. The code below illustrates the usage 'Launch explorer SystemUtil.Run "iexplore.exe" 'Launch excel using COM Set oXL = CreateObject( "Excel.Applicati on") oXL.Visible = True 'Close processes launched by QTP. This will close 'the internet explorer and Excel as well SystemUtil.CloseDes cendentProcesses This method is best suited to be used during the end of a script to cleanup any process left open. Closing all open Browsers Many times it's required to close all open browsers at the start of the script. There are various ways of achieving this; one is to use the SystemUtil.ClosePro cessByName method which we discussed earlier. But that approach is not generic as it won't close other browsers that QTP does support (like firefox and netscape). We can come with a generic 3 lines code which can close all supported QTP browsers 'Check the existence of a browser and close it 'until no more browsers exist While Browser("creationti me:=0").Exist( 0) 'Close the browser Browser("creationti me:=0").Close Wend QTP assigns creation time to each browser based on the launch time of that browser. A browser started earlier will have a lower creationtime and a browser started at a later point of time will have a higher creationtime. So when we start closing the browser with creationtime: =0, other browser's creationtime is decreased. Which means that the creationtime: =0 browser will

Page 65: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

64 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

always exist until there is no browser open. This approach of closing browsers suffers from 2 issues * QTP has a bug which makes it wait 10 second on Browser identified using creationtime when there is only one browser open. So above code will always take 10 secs to close the last browser * The code does not allow to ignore any specific browser (like Quality Center) Though there another way by which can enumerate all open browser and close them in QTP and below demonstrates the same 'Create a description for browser Set oBrowser = Description. Create oBrowser("micclass" ).Value = "Browser" Set oPage = Description. Create oPage("micclass" ).Value = "Page" 'Get all browsers Set allBrowser = Desktop.ChildObject s(oBrowser) Dim i, iCount iCount = allBrowser.Count - 1 For i = 0 To iCount 'Get the page object from the browser Set oPg = allBrowser(i) .ChildObjects( oPage)(0) 'Get the URL of the If InStr(oPg.GetROProp erty("title" ), "Quality Center", vbTextCompare) = 0 Then 'Close the browser allBrowser(i) .Close End If Next By now you must be wondering about the line 'Get the page object from the browser Set oPg = allBrowser(i) .ChildObjects( oPage)(0) So why didn't we use allBrowser(i) .Page("micclass: =Page"), well this a Bug or Limitation in QTP which does not allow using any further Test objects on objects returned from ChildObjects. This might be because of the fact that a QTP TestObject does not have any property or method as other Test Object. Ex - a Browser supports no method or property

Page 66: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

65 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

named Page. But QTP interprets that as way of hierarchy to decide where to look for that object. Anway this is all my opinion and might not be accurate. So the only workaround of using further TestObjects is to use ChildObjects again. Closing processes using WMI Another way to close a process is to use Window management instrumentation (WMI) 'Name/IP of the computer sComp = "." 'Get the WMI object Set WMI = GetObject("winmgmts :\\" & sComp & "\root\cimv2" ) 'Get collection of processes for with name iexplore.exe Set allIE = WMI.ExecQuery( "Select * from Win32_Process Where Name = 'iexplore.exe' ") 'Loop through each process and terminate it For Each IE in allIE IE.Terminate( ) Next Above code can also be used to close any process on a remote machine by changing sComp to the IP of the remote machine Closing Internet explorer using Shell Let's take a look at another way which is generic to VBScript and not dependent on QTP. For this we will use the COM object of "Shell.Application" . This COM library provides a collection of all open windows (Explorer + Internet Explorer). We can access each windows property and close if it is iexplore.exe process. The code below demonstrates the same 'Create the shell application object Set shlApp = CreateObject( "Shell.Applicati on") 'Get all open windows collection Set allWins = shlApp.Windows 'Loop through each window and close if IE For Each window In allWins If InStr(window. fullName, "iexplore.exe" ) Then 'Close the IE window window.Quit End If

Page 67: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

66 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Next The code above will only close alternate windows. This happens because we are loop through a collection of windows and closing a window in that collection reduces the collection and hence the for loop skips one window after closing a window. This issue can easily be resolved by adding the windows to be closed into an array and the closing them later Dim windows2Close 'Initialize with negative upper bound ReDim windows2Close( -1) 'Create the shell application object Set shlApp = CreateObject( "Shell.Applicati on") 'Get all open windows collection Set allWins = shlApp.Windows 'Loop through each window and close if IE For Each window In allWins 'Close all IE windows but ignore Quality Center If InStr(window. fullName, "iexplore.exe" ) And InStr(Window. LocationURL, "/qcbin/") = 0 Then 'Increase the array size by 1 ReDim Preserve windows2Close( UBound(windows2C lose) + 1) Set windows2Close( UBound(windows2C lose)) = Window End If Next 'Loop through all array elements and close each window For Each Window In windows2Close Window.Quit Next The above code shows how to ignore few internet explorers and close rest. Summary In this article we explored various ways of Closing processes and browsers using QTP.

XXI) Basics of Debugging Run Errors in QTP

Page 68: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

67 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

First of all let us understand the meaning of "General run error" as you are seeing above. "General run error" occurs in a situation when some source while being accessed by QTP propels an error. This is the inherent nature of QTP that in such a situation it displays a "General run error" message instead of showing a simple "Error" . Following line of a simple code will illustrate as to how the "General run error" shall be generated. Set oGeneralRunError = GetObject("A. B.C") On running the above code, you will get an error message "Invalid Syntax" Here we can see that the actual error is in-fact an "Invalid Syntax Error" and not a "General run error". However to view the actual error in this case, click on the "Debug" button and open the Watch Window. It is simple to fix the "General run error" - Incase we get this type of error while working on a QTP test object; we can place a Msgbox to check the existence of the object being handled. - However if we get this type of error while working under the Web environment, the issue can be resolved by using DOM object method.

XXII) Descriptive Programming to count and close all open browsers

Script to get count,names of all open browsers and to close them. Set b=Description. Create b("micclass" ).value=" Browser" Set obj=Desktop. ChildObjects( b) msgbox obj.count For i=0 to obj.count-1 c=obj(i).getroprope rty("name" ) msgbox(c) obj(i).Close Next

Page 69: GAReddy@OneTestingCenter@QTPLearningBook@MadeEasy@Part2QTPQTP LearningLet's Learn QTPQTP Easy LearningQTP GuideQTP BookQTP Learning PDFQTP - FundamentalsQTP - Advanced QTP - Topic

GAReddy @ OneTestingCenter QTPLearningBook@MadeEasy@Part2

68 GAReddy @ OneTestingCenter www.OneTestingCenter.com www.GAReddy.Blogspot.com

Thank you all.

Visit @

www.OneTestingCenter.com

www.GAReddy.Blogspot.com

For Documents, Presentations, PDFs, Videos, Scripts and much more.

QTP / LR – LoadRunner / QC – Quality Center – Trainings available

G A Reddy.

www.OneTestingCenter.com

www.GAReddy.Blogspot.com