qtp material

75
1-These QTP tutorials are designed for beginners to advanced users. Starting from QTP basics you will learn advance scripting all with practical examples for your easy understanding. Considering the big list of these QTP tutorials, we’ll be publishing new articles frequently. Keep track of all articles in this Quick Test Professional . Follow the topics closely, practice at home on QTP trial versio 2 -Introduction to QTP Keyword View This article is going to give you an insight into the Keyword view of the QTP GUI. During this process we are going to get a quick introduction to Actions, Object Hierarchy and the basic columns in the keyword view. Let’s start. There is a drop-down box at the top and it shows “Action 1”. What does this mean? Introduction to Actions: Tests in QTP are recorded in terms of actions. Action is nothing but a set of statements performing a sequence of actions. Most often an action is simply a logical unit of modularity. The calls to one or more actions can be defined as a QTP test. For E.g.: Let’s assume that in an online web based email system, the user needs to login, compose and send email and then logout, it is recommended that each of these operations be divided into 3 different actions although all of them can be written under one action. Test Email ’ will have: Action1 >Login Action2 >Compose and send email Action 3 >Logout

Upload: 202anji

Post on 20-Jul-2016

98 views

Category:

Documents


0 download

DESCRIPTION

Qtp

TRANSCRIPT

Page 1: QTP Material

1-These QTP tutorials are designed for beginners to advanced users. Starting from QTP basics you will learn advance scripting all with practical examples for your easy understanding.Considering the big list of these QTP tutorials, we’ll be publishing new articles frequently. Keep track of all articles in this Quick Test Professional . Follow the topics closely, practice at home on QTP trial versio

2 -Introduction to QTP Keyword View This article is going to give you an insight into the Keyword view of the QTP GUI. During this process we are going to get a quick introduction to Actions, Object Hierarchy and the basic columns in the keyword view.

Let’s start.There is a drop-down box at the top and it shows “Action 1”.

What does this mean?

Introduction to Actions: Tests in QTP are recorded in terms of actions. Action is nothing but a set of statements performing a sequence of actions.  Most often an action is simply a logical unit of modularity. The calls to one or more actions can be defined as a QTP test.For E.g.: Let’s assume that in an online web based email system, the user needs to login, compose and send email and then logout, it is recommended that each of these operations be divided into 3 different actions although all of them can be written under one action.‘Test Email’ will have:Action1 >LoginAction2 >Compose and send emailAction 3 >Logout

Page 2: QTP Material

The Test is essentially:Call to Action1; Call to Action 2; Call to Action 3If written in one action, the lines of script would be large and difficult to manipulate and maintain. So the logical division is recommended. Also, as we move on further in our exploration about Actions we are going to understand how actions can be parameterized thus enabling easy repetition of a certain action as many times as desired.

So when you create a new QTP test it contains a call to one action, “Action 1”.

When we expand the drop down, it shows the Test Flow. For a test with multiple actions it shows the sequence in which each action is called thus making the name, “Test Flow” self explanatory. This drop-down not only displays the sequence of actions, it also provides the option for the user to select or go-to a particular action to view and/or Edit.

There is also a “Reusable Actions” Folder view. For now, let’s just say that reusable actions can be used by multiple tests and multiple times in the same test where it was created. We are going to discuss in detail how that can be achieved. Every action by default is reusable. This can be changed if need be.

Let’s take a little diversion here and talk a little bit about Object recognition hierarchy in QTP.

Object Hierarchy – If you have noticed in our example the Agent Name and Password are displayed under the item Login. A point to note here is that, QTP uses a tree hierarchy to store objects. In our case, the Agent Name and Password are the child objects to the container object Login which is the Dialog. Container objects are window, dialog box in a windows based environment and web page in a web based environment.Here is an example, the login Dialog of the flights application:

The container here is the Login dialog and next level objects are Agent name, Password and the other buttons and images in the dialog. There are only 2 levels here. But there could be

Page 3: QTP Material

more levels, like browser.page.button in this case, browser is a container for page and page is a container for button.

Working with Keyword view:I am going to use the test we recorded in the previous article. Opening the flights application. Entering the Agent Name and Password in the Login Page and Clicking on OK.

I am also going to add some function calls and statements to programmatically from Expert view and show you how they appear under the tabular form in the Keyword view.

This is the code I put in the expert view:12345678910

Dialog("Login").WinEdit("Agent Name:").Set "swati"Dialog("Login").WinEdit("Password:").SetSecure "5112fd3c42beb7a58069b67cfdd9b7e7ad1fc69c"Dialog("Login").WinButton("OK").Clickmsgbox "text"If x=0 Thenmsgbox "text 2"End IfWindow("Flight Reservation").ActiveX("MaskEdBox").Type "010312"Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"

Lines 1 through 3 are the login operation. Line 4 is a function call to message box display operation. The I added a dummy if statement just to show you how it appears in the keyword view. X is a dummy value as well. Since we are not going to run this test, let’s just use it theoretically. Lines 8 through 10 are entering the date of flight and to, from locations. This is used to understand how objects are grouped.

This code appears as follows in the Keyword view: [click on image to enlarge]

Page 4: QTP Material

------------

As you can see there are 4 columns- Item, Operation, Value and Documentation. The table can be expanded or collapsed by clicking on the little arrow next to the action name.

Item: Each step is a sequence of events performed on an item. The item can be one of the following:

1. Test object (e.g.: Agent Name Edit box)2. Utility Object: These are some objects reserved by QTP to be used in tests. E.g.:

DataTable object. More coming up on this later.3. Statement: Any VB Script programmatic statement or even comments4. Function call: like ‘msgbox’ call in our program

Operation: It shows the operation that is performed on the item. When this column is clicked for a particular item it lists all the available operations that can be performed on the object.

Page 5: QTP Material

Value: This column can be considered as the argument of a statement displayed. In our example, the message box function call has a value “Text”. There can be multiple arguments to one statement in which case this column will be divided accordingly.Documentation:  A read only column that translates a statement into easily understandable comments.There are two other columns Assignment and Comment that can be added to the Keyword view table. To do so, the option to select isTools->View Options and choose the required columns from the list displayed.

Assignment: This column is not very widely used and what this does is assigns a value to or gets a value from a variable. [click on image to enlarge]

Page 6: QTP Material

Comments: The tester can write anything under this column. It will be treated as comments in the expert view.

Conclusion:Well, that sums up an interesting insight into the basic capabilities of the QTP keyword view. Actions are logical units of separation in a test. A test is therefore a series of function calls. When a new test is creation it contains one call to an action. By default all the actions are reusable. QTP follows a multi-level hierarchy to recognize objects. An object that contains a next level of objects is called a container. There can be more than one level of containers in a test.In the next article we will talk about way we can use this view to Insert Steps. Modify them, Insert checkpoints, Breakpoints and how we can manage actions.

3-Adding Standard Steps From Keyword ViewIn last tutorial we sawhow to work with keyword view.Today’s article is going to be about adding steps to a QTP test from the keyword view. Before we go about adding the steps, let’s see what kind of steps we can add at all:

1. Standard Step: A standard step is anything that acts on an object. For example, a set operation on an edit box with a particular value or selecting a value from a list box.

2. Checkpoint Step: Checkpoint is a step in a QTP Test that compares an expected value of a specific property/state of an object with the actual value. This is a kind of validation that QTP provides to the users to make sure their AUT is working as intended. So, when this kind of a step is inserted, QTP performs a check during this step execution and if expected and actual values are same, the checkpoint passes or else it fails. An example of a checkpoint is, if in an application a checkbox is supposed to be ON after its selected or a particular name that a text on the screen should be, etc. QTP has 10 checkpoints that it provides the users with. Apart from

Page 7: QTP Material

these, the tester can verify and validate any conditions by programmatically writing them. All the check points will be dealt in detail in the coming articles.

3. Output value: As the name implies an output value is nothing but a variable that stores the outcome of a particular step in a test. This value can be used subsequently as an input for another step. This value is only available for the time period of a test run after which it gets reset. This topic also will be detailed out shortly.

4. Comments: Any step that is a non-programmatic and won’t be executed, but is put in the script to increase readability is a comment.

5. Conditional and Loop statement.6. Other: These are the kind of statements that help in designing the programming

logic. Some examples are sync statement, writing into test results etc.Let’s start with adding a standard step. For our convenience I am going to explain the use of only item, operation, value and documentation columns in the keyword view. Though there are two more columns, they are seldom used.

Inserting a step is the first part of adding a line to a program. A step merely adds a blank line in your test. It is up to the tester to define the step and to add details to the step. The details include what item to act on, what operation to perform, what value to assign etc. If it’s a new test, any step we are trying to add becomes the first step. From the menu main, select Insert-> New Step after clicking anywhere in the keyword view.[Note - click on any image to enlarge]

Another way is to right click on an existing step and selecting Insert new step from the menu.

Page 8: QTP Material

Both of these option result in the addition of a new line after the selected step. If a container object was selected while adding a new line, the new step gets added as a sub-step. If a last-level object was selected, the new line gets added as a sibling.

Here is how the new line looks like. The new line added is nothing but a skeleton that can be defined as required.

So, the first thing you see in a newly inserted line is a ‘Select an item’ drop down.

Given the fact that everything operation needs an object to be performed on, this is inevitable. Now as we already discussed item can be anything, a Test object, Statement, Utility Object or comment. The Test objects that are contained under a Container Object are displayed here. Therefore, according to our example, Agent Name, OK, Password is displayed in the list when a new step is to be added while clicking on or under the sub-level steps of the Login Dialog.

Object Repository:If anything other than the items listed are required by the user there is an option to select the same from Object Repository. Now, this is the first time in our articles that we have encountered the word Object Repository. So, what is it really? When we try to put it simply,

Page 9: QTP Material

an Object Repository is what its name suggests. It a place or more like a database where all the Objects in a test are stored. This is what happens when the user chooses ‘Object Repository’ from the list.

So either from the list displayed or from Object repository an item can be selected. The next thing is to define the operation to be performed on the selected object. Click in the Operation column and a list of operations that can be performed on the selected object are displayed. This list is dependent on the type of object selected. For instance, a dialog object will have different methods available than when an Edit box is chosen.

Choose the desired operation

Page 10: QTP Material

The next column is the Value. As we already know that this column is the argument to the operation to be performed on the selected item. On clicking in this column, the arguments are displayed as shown below:

If more than one argument is required to carry out the said operation, all the arguments will be displayed as multiple cells in the Value column.

The type operation on the ‘FlyFrom’ item needs a keyboard input. When the icon in this column is displayed the following dialog is displayed that helps the user to configure this value.

As you can see from the window above, the value to be entered in this field can either be a ‘Constant’ in which case the constant value can simply be typed in the text box and then followed by clicking the ‘OK’ button in the window.

Or it could be parameterized, which means it would be picked up from a location in the data sheet, a random number or an Environment variable. How to parameterize a value for an argument will be discussed in length later on.

In our example, I am writing “Test” in the constant field and clicking OK and here is how the line generated looks:

Page 11: QTP Material

It should be noted that the ‘Documentation’ field gets auto-populated with the description pertaining to the operation performed on the item selected.

ConclusionSo, that concludes the topic, ‘Adding a standard step to a test from the Keyword View’. We have discussed the various kinds of steps that can be added from the Keyword view and explored the adding of a Standard Step in detail.

We’ll have couple of more articles on QTP keyword view. In the coming articles, we will see how to add the other kinds of steps, adding conditional and loop statements and how the Keyword view can be used to modify/delete the test steps.

4-Adding Conditional and Loop Statements in Keyword View.Understanding QTP keyword and expert view feature in detail is very important to learn QTP. So we have divided this Keyword View tutorials in four articles. This is the third article in Keyword View series.Check out all the articles in this QTP training series @ Quick Test Professional (QTP) training series[Note - Click on any image to enlarge]

Condition and Loop Statements in Keyword viewA quick recap of what we learned so far -We acquainted ourselves with the Keyword View of the QTP and we are trying to understand the different features this view provides and see how these features can be used to write effective tests. To do that, we are working with a basic example where we recorded a series of simple operations on the Sample Flight Application.This aids in understanding how QTP translates the steps performed on the application into a table with 4 essential columns of the Keyword view. Not only does QTP show the user the operations performed in terms of a table but also lets the user manipulate the steps from this very table.

Page 12: QTP Material

We have explored how a standard step can be added to the keyword view. Apart from a standard step, this view also displays the conditional and loop statements in a test.In this article we are going to explore how QTP’s Keyword view handles these statements.Firstly, what do Loop and If statements do?Loop Statement: This is a part of programming logic that is used when a particular set of statements have to be executed repeatedly for a particular number or times. Another variation to this statement is to repeat execution for a block of code until a certain condition is satisfied or while the said condition is satisfied.If statement: As the name indicates, the if statement in a program is used to perform a check for a certain condition to be satisfied, and when it does a certain block of code gets executed. Variations to an ‘if’ statement is ‘if ..else’ and ‘if else if…’Keyword view has a different icon to indicate each of these statements in the keyword view. Let’s include some dummy steps into our program and see how these statements appear in the keyword view. For convenience and since the steps that I am about to insert are dummy, I am going to put the code directly into Expert view and we observe it in keyword view.

1) Conditional statements:

The above is the different variations of the ‘if’ statement that I entered in the expert view and as I said all the code does not serve any purpose except for our understanding. We will note how these statements are represented in the keyword view.

Page 13: QTP Material

As you can see each statement type is given a different icon for identification.

2) Loop Statements:Let’s look at how these statements are represented. We will follow the exact method that we did for conditional statement.

Adding condition statements to the keyword view:For my examples above I have added the conditional statements from the Expert view and we merely looked at their representation in the Keyword view. So far we have not added them directly from the keyword view. Keyword view does provide a way for these statements to be added directly to the test. Here is how you can do it.

Page 14: QTP Material

Click anywhere in the keyword view, just like how you would do it to add a standard statement, right click and choose “Insert->Step” followed by “Conditional Statement” and the statement that you would need. Here is how it looks:

As you can see above, An If..Then, Elseif..then, Else are the statements that can be chosen based on the requirement of the tester.

Let us choose an ‘if..then’ and see what happens.

This is what gets inserted. Now, just the way we would do for a standard step, we will need to define a conditional statement too.

Item: Click on the ‘item’ column corresponding to the ‘if’ statement and all the objects available will be displayed. This feature again is no different from the standard step definition. So choose an object that you wish to act on. As an example, I am going to check if the ‘Password’ field exists. So I choose “Password” from the list.Operation: Again, a list of all the functions available will be displayed when this column is clicked on. Since I am checking if the password field exists or not, I will choose ‘Exist’Value: The argument/arguments for the function is what this field is. For the ‘Exist’ function an argument is not necessary so we will leave it empty.Let us now look at how this new statement looks in the keyword view as well as what it looks like in Expert view.

Keyword view

Page 15: QTP Material

Expert view:

------------

As you can see, the ‘if’ statement is defined.

Now, we have to add code or statements to define what needs to be done if the condition becomes true.

For the sake of our example, if the password box exists we will enter a value in the field. How can we accomplish this? Once a conditional or loop statement are added any steps that the user adds or records will be directly added under them unless explicitly specified. The statement added or recorded could be a standard step or another conditional or loop statements (nesting).So, to define the ‘Then’ part of our ‘if’ statement, I am going to record the action of entering the password value. To do so, I will choose ‘Record’ from the menu options and enter a password value in the ‘Flights’ Login page. Take a look at the screen shots below, the recorded statement got directly added under the ‘if’ statement.

Any steps you add further will be added under to the ‘if..then’ block.

To want to add outside the block, select the block (the ‘if’ statement), right click and choose ‘Insert New Step after block’

Page 16: QTP Material

The new step just comes as a sibling to the ‘if’ block.

Now, that we have understood the basic functionality it goes without saying that all the other conditional statements work the same way and any of them can be used as needed by the programmer’s logic.

Adding Loop statements to the keyword view:The procedure to add the loop statement is by right clicking in the keyword where you want it inserted and choosing “Insert New Step->Loop Statement” and the required option.

Page 17: QTP Material

As always, the inserted step has to be defined. Any steps recorded or added after the loop will be within the block and to exit the block the user has to be explicitly specify that the new step is to be added outside the block by right clicking on the loop statement and choosing “Insert New step after block” option.

Let us add a ‘For’ Statement as an example.I chose the “For” from the menu option and this is what gets inserted into the keyword view:

In the value column I will set the iterator value. I set it as 1 to 3.  Next I added a statement as “msgbox “x””. Let’s look at how this looks in the keyword view.

Conclusion:So, that concludes our session on the conditional and loop statements and how they can be inserted from the keyword view. If or loop statements can be pretty much added just the way a standard step is added. Just like a standard step these steps also need to be defined. Steps that are recorded or added after a block statement will be added within the block by default unless specified. When a statement has to be added outside the loop we need to

Page 18: QTP Material

choose the option “Insert new step after block” option from the right click menu after choosing the block after which we desire the steps to follow.

In the next session we will explore more options of the keyword view such as moving and deleting steps, adding and deleting breakpoints.

5 - moving steps, deleting steps and dealing with breakpoints in keyword view. This is the fourth and the last article on QTP keyword view features.If you missed any article in this QTPtraining series please check all articles on this page: QTP Training TutorialsOther features of the Keyword View:We are almost approaching the end of sessions concerning the ‘Keyword View’ of QTP. How it looks, what it does, what can we do with it – These are some of the aspects we are trying to unveil in the course of our articles. Understanding the view, adding steps, conditional statements are already dealt with.

Today we’ll learn remaining Keyword View features such as moving steps, deleting steps and dealing with breakpoints.Just like always, we will use the sample test we have been working with – The login operation on the Flight sample application.

Moving steps:1) The first and the simplest way – Keyword view acts like any text modification application when it comes to cutting, copying and pasting the steps. Thus, all the clipboard shortcuts are applicable.

Ctrl+C – Copying Ctrl+V – Moving Ctrl+X- Cut

2) The next way is by choosing the menu option. To use this, select the step that needs to be moved and choose the following menu choices:

Edit->Cut Edit->Copy Edit->Paste

3) The other method is dragging and dropping.Any of the above methods can be used to move steps. However, there are few ground rules:

1. The loop or condition statements can only be moved in blocks. For example, for an ‘if…else’ statement you cannot just move the else part.

2. In a step, where the item is a child object and the user decides to move it, there is one of the two scenarios that come up. Either the step gets moved under the same parent or to a different parent. If it is moved under the same parent, it simply comes

Page 19: QTP Material

up in the new position chosen. But if it is moved under a different parent, the parent gets duplicated. Let’s see this pictorially:

[Note - click on any image to enlarge]

I am going to move the step where we enter the agent name (the one highlighted above) under the ‘Flight Reservation’ parent object. Let’s note that the parent object for ‘Agent Name’ is Login. I simply dragged the step to be the last one. This is how, it appears:

Earlier in the introduction sessions, we have discussed that we can have multiple actions in a test. Let us see how a test with multiple actions would appear in the keyword view and how this view can be used these actions as desired.To achieve this is, I am simply going to convert all the steps under the parent object ‘Flight Reservation’ in our above example to appear under another action. Adding actions, steps to actions all these are going to be discussed in detail as we move on in our sessions.

Action 1:

Action2:

Page 20: QTP Material

As you can notice in the test flow pane, the sequence in which these actions are executed is displayed.

If I would want the Action 2 to run first followed by Action 1, keyword view let’s me do that by allowing me to drag and drop the actions to the necessary position.

With this, we have covered all the information necessary to move steps/actions/blocks within a test using the keyword view.Delete Steps:Deleting steps from QTP could not have been simpler. All you need to do is choose the step that you do not want in the test and simply hit the “Delete” button on the keyboard or right click on  a step and select “Delete” from the menu or select a step and choose “Edit->Delete” from the main menu.

If a step that has sub-steps defined for it is chosen for deletion, the following message is displayed to the user:

------------

What this means is that, if a step with sub-steps is chosen for deletion, all the sub-steps get deleted too.

And, that’s all there is to discuss about deleting steps.

Adding Breakpoints to the test from the keyword view:Often, during the execution there might be one or more things that you want to key an eye out for and observe what kind of changes are happening. This might be to see the state an Object gets to or to note a value a variable takes etc. A facility that helps us do just that is a Breakpoint. It is basically a certain point in your test where you want to pause the test run

Page 21: QTP Material

and observe or obtain certain information about your test. Most times this feature makes debugging easier.

Now, that we know what a breakpoint is, we will try to understand how to add them to our tests from the keyword view.

All you need to do is, click in the left margin at the particular step where you need to pause the test. The addition of a breakpoint is represented by a red dot in the left margin corresponding to the step where a break is added.

Here is how it looks:

Selecting a step and pressing F9 on the keyboard also results in the addition of a breakpoint.

Lastly, the menu option “Debug->Insert/Remove Breakpoint” can also be used.

So, once a breakpoint gets inserted, the test will run until the step where it is inserted normally and will come to a halt before executing it. At the point the tester can perform the required observations for which the program was stopped and continue to run it by choosing the “Run” option one more time from the main menu whenever he is ready.

Page 22: QTP Material

If we add a breakpoint from the keyword view, the same is displayed in the Expert view also in front of the line corresponding to the row to which it gets added.

The vice versa is true too, if you add a breakpoint from the Expert view, it gets reflected in the keyword view.

As simple as it is to insert a breakpoint it is even simpler to delete is once its purpose is served or when it is no longer needed.

Delete BreakpointsClicking one more time on the line where the breakpoint already exists will result in its deletion. Keyword F9 or the menu option “Debug->Insert or Delete Breakpoint” can be chosen on a step with a breakpoint and it gets removed.

Conclusion:So this concludes the discussion of all the properties and capabilities of keyword view in detail. This view is the most readable one among the two and once all the features are understood, we can use it as effectively as possible to make the tests robust.

Next we will deal with how to record a new test and what are the factors that determine the success of a being able to do so.

The last few QTP tutorials have been about the QTP’s Keyword view which was really crucial in getting a high-level understanding of a QTP test’s structure and also introduced us to few ways in which our tests can be tailored to meet our needs.  So I think we are ready to record our first test in its entirety.  We are going to do just that in the next few QTP training articles. Today’s topic, therefore is the first step in doing so which is the “Record and Run settings’. We are going to understand all about this, why it is important and how this can affect a test.

6-Record and Run Settings DialogWhen QTP is launched and we choose to record a new test, the ‘record and run settings’ dialog opens up.  Alternately a user can choose to access this window by choosing “Automation->Record and Run Settings” option from the menu. So far in our examples we

Page 23: QTP Material

have just continued with its default settings but now we will explore it further. The following is the how this dialog looks:

As the same suggests, this is a space that QTP provides the user to set certain parameters that help the user to create a test via record and to execute the same during a run session.

QTP can record and run a test on either a windows app or a web app.  The web tab is available only when the Web add-in is selected to be loaded at start up. This tab is used for Web, .NET Web Forms, PeopleSoft, and Web-based SAP objects. So there are 2 tabs to define the settings separately for each of these environments.  There will be a separate ‘Siebel’ tab available is a Siebel add-in is installed and loaded during start up.Let’s look at the ‘Web’ tab first”:

“Web Tab” on Record and Run Settings Dialog:The default settings are as shown in the picture above. This setting means that when a record session is started the target of the record operation can be any of the web application that is already open in a browser.  The user also has a instruct QTP to ignore

Page 24: QTP Material

certain web pages like QC or any other page with a specific URL or a specific title. The way he can do that is, “Tools->Options->Web” and define those pages in the following QTP dialog:

But if the user chooses, the next option “Open the following address when a record or run session begins” the corresponding elements in the screen get enabled. Take a look at it below:

Page 25: QTP Material

The user can enter the address of any page and the choice of the browser.  The browsers that QTP 11 supports are:

Page 26: QTP Material

The browsers that are supported and are currently installed in your machine will only appear in the list.

There is another way to set the record and run settings other than from this window and that method is through Environment variables. Since we did not yet get there, we will discuss them in detail later on. For the sake of mentioning, if the environment variables URL_env andBrowser_env are set, then it overrides the URL and browser chosen in the ‘Record and Run Setting’ window. How to create these and how they work – all this will be dealt with later.‘Do not record and run on browsers that are already open ‘– If this option is chosen all the browsers that are open prior to recording and running and also prior to launching QTP will be ignored.  It is as if these browsers don’t exist for QTP because the user can not even spy these pages to view the objects. In other words, these browsers are totally ignored and as a result deemed inaccessible to QTP.

‘Close the browser when the test closes’ – this option when chosen will close the browsers on which the record and/or run session was carried out when the test ends.

“Windows Tab” on Record and Run Settings Dialog:This tab is for the windows based applications. The default option to record and run on any windows app opened.

------------

Page 27: QTP Material

If the “Record and Run only on’ option is chosen, the other options under it get activated.

1. Applications opened by QuickTest: when this option is chosen, the applications that are opened as a result of an invoke operation performed by Quick Test are only chosen for recording

2. Applications opened via the Desktop (by the Windows shell):This means that the application that are opened from a windows desktop are chosen

3. Applications specified below: choosing this option will open another child window where a specific app to be opened by the QTP at the beginning of a record or run session can be defined.

Page 28: QTP Material

As you can see from the above window, the path of an application and its folder should be added and QTP opens that particular app while record and/or run.

That concludes a quick introduction to various ‘record and run settings’ that can be used for a QTP test. When testing a web app, it is also important to make sure that we add the correct settings in the windows application tab too. It is crucial because, it will help us in preventing opening up of unnecessary applications and also to make sure that we do not accidentally change any of the already open windows applications. It should be noted that, the setting in the windows tab do not directly affect the testing performed on a web app.So the recommended settings for the windows tab while testing a web app are:

Page 29: QTP Material

Once these settings are done, the test recording begins. Any operation performed on the test gets recorded in the QTP. The tester can stop the record operation once all the steps that he wished to perform on the AUT are done by clicking on the “STOP” option available in the QTP menu.

The recorded steps can then be re-performed on the AUT by choosing ‘RUN’ option from QTP. Run operation too invokes the application (web or windows) depending on the setting specified.

ConclusionThis forms the basis for performing any basic steps on the AUT using QTP. In the real world this alone isn’t sufficient. Testing as an activity is verification and validation inclusive, so we will have to tailor these basic lines of code to include certain verification and validation points. To do so, QTP provides some checkpoints and the tester can also programmatically add steps to check few things as needed.

Page 30: QTP Material

We will discuss these checkpoints in the coming series of articles and also try to learn the best practices to be followed while test creation to ensure maximum efficiency.

7-How QTP Identify Object Uniquely? – This is the 7th QTP Tutorial in our QTP training series.We are getting ourselves equipped with all the basic concepts that will enable us to writerobust QTP tests. We have covered the QTPrecord and run settings, working with keyword view and the other related topics.This is the next article in the series that talks about a crucial aspect of QTP – The mechanism it uses to identify an object uniquely.  When you look at the below screen:

There are 3 buttons and 2 text boxes along with various other elements in this dialog.In the previous examples, when we entered the user name and password we saw how QTP recorded the same operations in terms of programmatic code as well as a table in keyword view. Now, during play back how does QTP know that the value we provide as Agent Name or Password has to go respectively in those edit boxes. Or how does it know which button to click to submit the values entered?

Let us try to find an answer to that.It is clear that QTP somehow remembers which object to act on. The way it does it is, it stores the object in the AUT as a test object. It then examines its properties and classifies the object. For E.g.: when it encounters the OK button it examines its properties and based on these, it classifies the object as a ‘WinButton’.QTP has a predetermined set of properties that it learns/stores for every class of object it identifies. There are 3 aspects to this:

1. Mandatory properties: This is the list of properties for a certain class that QTP always stores. We could say that this is the object description. It also checks this in conjunction with the parent object to see if the description is sufficient to identify the object uniquely.

Page 31: QTP Material

2. Assistive properties: In case the description of mandatory properties is insufficient to identify the Object a set of non-mandatory properties will be added to the description one after the other until there is enough data to identify the object.

3. Ordinal Identifier: If the assistive properties also do not result in unique identification of an object a special ordinal identifier is added by QTP, such as the object’s location on the page or in the source code.

So, this is how QTP forms Test Objects. It uses this Test Object description to search for the objects to act on during a run session. It chooses the objects that match perfectly with the description it contains. These objects are called Run-Time objects.Unless your application has changed significantly the Test Object description that QTP has is sufficient to find an object.

For the WinButton object that we have in our Flight app, let us see what properties QTP has stored. This information is available in the Object Repository. Menu option “Resources->Object Repository” will launch the OR for us. Alternately, you can use CTRL+R or click on the icon.

If you notice in the above window, it stored the ‘text’ in the WinButton as its description to identify this button at runtime.

For more complicated applications, the tester can add or remove certain properties to make the description robust enough to identify the object at runtime more precisely. To do this, simply click on the ‘+’ icon.

Page 32: QTP Material

All the other properties of the object will be displayed. The user can choose to add one or more of these properties.

There is also something called “Visual Relation Identifier” in the OR screen for the WinButton properties.This is a feature that further supports the object recognition according to their neighboring objects in the AUT. Once set, this creates a kind of link for the less stable components in your AUT with the objects that are more uniquely identifiable. QTP will identify these objects as long as they maintain their relative position to these unique objects.

To set a kind of positional link we are going to have to click on this column in the OR and the following screen comes up:

Page 33: QTP Material

In this screen select the ‘+’ sign to add an object with which you want your test object to have a positional link.

I will choose “Agent Name” and say that this object should be above “OK”button.

This is how I set that:

Page 34: QTP Material

Now, in case some properties of OK button changes in the future, QTP will identify it if, “Agent Name” is above it.

Smart identification:This is the mechanism employed by QTP under one of these two situations. The description for an object that QTP has:

1. does not match with any run time objects2. Matches with multiple objects

This is a little bit of an advanced concept, so we will get to it at a later time via some example for easy and elaborate understanding.

------------

Ordinal identifier:This is a numeric value that depicts the relative order of the object with objects that have a similar description. If an object 1 and Object 2 have the same mandatory and assistive properties, then the ordinal identifier will be used to recognize the object uniquely. This value is related to the other objects of the screen, so in case anything changes in the screen, this identifier might not come useful.

Page 35: QTP Material

It should be noted that, if the mandatory and assistive properties are enough then an ordinal identifier is not assigned during record. It can be added later on by clicking on the respective column for the object in the OR

There are 3 kinds of ordinal identifiers:1. Index: this is based on the order of appearance of an object in the application code2. Location: based on the location in a screen or dialog or page3. Creation Time: This is used only for browser objects. In case 2 browsers with similar

properties exist, then the one that is created first and next are considered.For example, Let us understand how ‘index’ identifier works in our Flight applications login screen:

These are the following components:

As you can see, the static text and the edit boxes have the same ‘text’ property.

If I know that one of them is a static text and the other is WinEdit object, then there is no problem at all. Say if all these are treated as WinObject then I will have to specify which object to act on. This is only going to happen when the mandatory, assistive and smart identification have failed. So in order to tell QTP which is what, I am going to assign an ‘Index’ ordinal identifier. I will do so from the OR.

I will set the Agent name static text identifier as 0 and for the editbox I will set it as 1.

This is how it looks:

Page 36: QTP Material

So if I need to access the static text then I will do so as follows:

WinObject(“text:=Agent Name:”, index:=0) – This will refer to the static textWinObject(“text:=Agent Name:”, index:=1) – This will refer to Edit boxThe same theory applies to Location identifier too except that we will choose the location in the window to determine the numeric value that is applicable to a certain object.

Configuring Object identification properties:The mandatory, assistive properties and ordinal identifiers to be considered for an object of a certain class to be recognized can be configured by using “Tools->Object Identifier”. We can also set the smart identification properties through this window.

The window looks as follows:

Page 37: QTP Material

As can be seen in this above image, the environment can be chosen from the drop-down box. Once that is chosen the classes of objects in the corresponding environments are shown in the list. After an object is selected, the mandatory and assistive properties are displayed. The user can Add/Remove additional properties to this list.

Also smart identification can be enabled/disabled for a certain class of object when needed. To set the ordinal identifier there is a drop-down that can be chosen to identify the object using Location, Index or Creation Time (only for browser type only).

We will wrap up the fundamental concepts before moving on to full-fledged QTP programs. The next QTP article will have the different recording modes, Object Spy, Object Repository etc. details.

8 -Recording Modes in QTP: Recording is the most commonly used method to create a test. The basic steps are typically recorded and the test later under goes improvements in order to suit the needs of the testing process.QTP provides 3 modes of recording:

1. Normal2. Low-level3. Analog

Though only the normal recording mode gets used most of the times, it is important to know the others too, as the knowledge about the same can come handy when the need arises for them.

Page 38: QTP Material

Normal Recording mode- The default recording method is always the normal mode. In all our previous articles when we say record we meant the normal mode. So, as we know this method uses the model of Test Objects and Runtime objects to learn and act on the AUT.Analog recording mode- records the exact mouse and key strokesthat the user performs in relation to either the screen or AUT window.  The steps that are recorded using this method cannot be edited.The way this usually gets represented in a code is:

Window/app.RunAnalog “Track1”One scenario in which this type of recording can be used is when we are trying to capture a signature.

Low Level recording mode- This mode records the co-ordinates in the application where the operation is performed, irrespective of whether QTP recognizes the specific Object or Operation.Some important points to note about these different modes are:

1. In the middle of recording, we can switch to Analog/Low-level mode, finish the task required and go back to normal recording

2. Analog and Low-level recording modes require more memory space than the normal mode.

3. Mouse movements are not recorded in the low-level recording mode4. The switch to Analog mode is available only during recording and not during editing5. The test that is recorded in an analog mode will fail if it is run after changing

the screen resolution.The menu option to change the recording mode is:

Object Spy:

Page 39: QTP Material

Object Spy is an extremely helpful tool that QTP has to view the properties and operations of an object in the AUT. The prerequisite to using this tool is that the AUT has to be opened.

The Object Spy can be accessed by using “Tools->Object Spy” or by directly clicking on the below

It is also available from the Object repository and Object repository manager windows.

When Object Spy is launched, this is how its interface looks:

Page 40: QTP Material

By clicking on the pointy hand you can point to any object whose properties you wish to examine.

This is how it displays the properties:

Page 41: QTP Material

As you can see, it shows all the properties of the object and the corresponding values. It shows the object hierarchy. There is also an ‘Operations’ tab which when clicked displays all the operations that can be performed on the test object:

Page 42: QTP Material

The spy not only displays the properties, it also has a provision that lets the users add a certain object to the OR.

You can do that by clicking on the OR icon with a + in it.

Object RepositoryIn one of the previous articles we talked about how an OR is like a warehouse where all your objects are stored.

------------

OR has the list of Objects that QTP learned during the record process and the class to which they belong. It stores the set of properties that uniquely identifies the Object (description) and also names the object for the sake of identification in our test, based on its most prominent feature.

Page 43: QTP Material

The objects that are acted upon during record get automatically added to the OR. Alternately, the user can add additional objects on a need basis. This can be done directly from the OR window or from Object Spy.  (Ctrl+R or Resources->Object Repository or click on the icon.)

There are two kinds of repositories:1. Local2. Shared

Every time a test is created we have seen that a call to Action 1 is the only statement by default. We can add other actions and call them as needed. So, for every action QTP creates its own local repository by default.  It contains the objects that are related to that particular action.

Conversely, the user may decide to use a common repository for multiple actions in which case, this repository is to be associated with the actions and all of them can share the objects that it contains. This can be done using the “Object Repository manager’. The objects can be exported from a local repository into the shared one to maintain a single location for all the objects.  Also, a shared repository is read-only in the action level and any changes to it have to be made via ‘Object Repository manager’.

The repository to be used by an action has to be specified in the action properties.

How is it done practically is something we will look into using some examples later on.

Some of the important points to note here are:1. Even though there is a single shared repository for all actions every action will have

its own local repository whether the test uses it or not. For example: For test 1 if there are Action 0, Action 1 and Action 2 and there is a shared repository ORShared, there will be local repositories OR0, OR1 and OR2 by default. However, if all the actions use one shared repository, local OR will be empty.

2. If a local OR and Shared OR have an object with the same name, the action will consider the object in its local OR.

3. There can be more than one Shared OR’s associated to the same action. If Shared OR1 and Shared OR2 have one object named OBJ1 each and if the action calls for OBJ1 then the order in which the shared ORs were associated will be considered. That means, if Shared OR1 was first associated then the OBJ1 from Shared OR1 will be taken into account.

It goes without saying that having a shared Object Repository is more efficient as it helps in easy maintenance and you can use one object description across multiple actions.

Page 44: QTP Material

Here we covered some of the key concepts that will enable us to understand and create better QTP Tests. In my opinion information on Actions, Active screen and a rather impromptu but important password encoder tool are few more aspects we will have to cover before we move to more advanced topics.

9-Basic of VB Scripting Concepts to Learn QTPIt should be noted that this article is not an exhaustive list of all the VB Script features. Consider this as a place that will introduce you to certain key concepts to guide you while you attempt to self-learn the language.  Since the expert view of QTP is a VB Script editor, it is a must that we try to understand VBscript for QTP before we move on to our articles on QTP Expert View.VBScript data types and subtypes:Data types:1) There is only one data type: Variant. It can store different kinds of information based on the context in which it is used.2) If used in a numeric context it is a number or a string if used in a string expression.3) If a number has to behave as a string we could enclose it within “ “.4) There are various subtypes to a variant. You can explicitly specify these subtypes to achieve a clear definition for your data. The below is a screen shot from the VB User guide that shows all the subtypes of data that can be used:(click on image to enlarge)

5) Conversion functions can be used to convert one subtype of data into another.6) Since it is the only data type available, all the return values from a function are variants.Here are different VBScripting examples you can try on your own.Variables:

Page 45: QTP Material

1) A variable is nothing but a space in the computer’s memory that can store certain information. This information is bound to change from time to time. Where the information goes physically is immaterial but when needed, it can be accessed or changed by addressing the name of the variable.E.g: If there is statement that you want to run a number of times, you could use a variable to contain that count. Say X. X is a variable that can be used to stored, change and use the space in the memory where we want to keep the count.2) All variables are of the datatype Variant.3) Declaring a variable prior to its use is optional, although it’s a good practice to do so.4) To make the declaration mandatory there is a “Option Explicit”Statement available.To declare variables:Dim x – This declares  xDim x, y, z – This declares multiple variablesX=10 – This is how a value is assigned. As a general rule, the variable is the left hand side component and the right is its value.X=”Swati” – this is the way a string value is assigned.To make declarations mandatory this is how the code has to be written:Option ExplicitDim x, striIf Option explicit statement was not used, we could have directly written:x=100stri=”Swati”and it would not have thrown an error.5) Naming convention: Names must start with an alphabetic character, must be unique, cannot contain and embedded period and cannot exceed 255 chars.6) A variable containing a single value is a scalar variable and the one that has more than one is an array.7) A one dimensional Array can be declared as: Dim A(10). All the arrays in VB Script are zero based that means the array index starts from 0 through the number declared. That means, our array A has 11 elements. Starting from 0 to 10.8) To declare a 2 dimensional array simply separate the row count and column count by a comma. Eg: Dim A(5, 3). This means it has 6 rows and 4 columns. The first number is always row and the second always a comma.9) There is also a dynamic array whose size can change during run time.  These arrays can be declared using dim or redim statements.------------

If an array is declared as Dim A(10) and during run time if we need more space we can so the same by using the statement: redim A(10). There is a “Preserve” statement that can be used in conjunction with the redim statement.

Page 46: QTP Material

Dim A(10,10)……….Redim preserve A(10,20)This piece of code shows how we do it. Initially A is a 11 by 11 array. Then we are resizing it to be a 11 by 21 array and the preserve statement will make sure that the data that is previously contained in the array is not lost.

Constants:1. As the name implies a constant is nothing but an unchanging value in a program that

is assigned a name.2. They can be declared by prefixing “Const” to a name.3. Eg: Const a=”10” or Const Astr=”Swati”.4. This value cannot be changed accidentally while the script is running.

Operators:Some of the important operators that are most commonly used are:

1. String concatenation: & (Eg: Dim x=”good”&”day”, so x contains “goodday”2. Addition (+)3. Subtraction (-)4. Multiplication (*)5. Division(/)6. Logical negation (Not)7. Logical conjunction (And)8. Logical disjunction ( Or)9. Equality(=)10. Inequality (<>)11. Less than (<)12. Greater than(>)13. Less than or equal to(<=)14. Greater than or equal to (>=)15. Object equivalence(Is)

It is important to note that the list is not complete but merely a subset containing the most commonly used operators.

The operator precedence rules are:

1. Multiplication or Division take precedence over addition or subtraction2. If multiplication and division exist in the same expression, then left to right order is

considered

Page 47: QTP Material

3. If Addition and subtraction occur in the same expression,then too, left and right order is taken into consideration.

4. The order can be over ridden by using parenthesis. In this case, the expression within the parenthesis is executed first.

5. & operator takes precedence after all arithmetic operators and before all logical operators.

ConclusionSo, this being the VBScript basics, in the coming article we will look into how we can write loop and conditional statements that are essential in building the programming logic. The next article will be the last in the VB Script series before we move on back to QTP’s expert view.

10-VB Scripting Basics – Writing Loop and Conditional Statements for Building the Programming LogicIn the last VB Scripting article we saw some of the basic features of VB script. We are going to learn a few moreprogramming conceptsbefore we conclude our introduction series.

Conditional Statements:1) If statement:If (condition)..Then{Statement or a block of statement}Else{Statement or a block of statement}End if

This is the typical syntax to write this statement.

The if..then..else statements can be nested to any number of levels. Alternately, the else block can be used or not. Elseif is another variation that can be used when choosing between one of the

multiple options.if x=0 thenMsgbox “value=0”Elseif x=1 then msgbox “value=1”Elseif x=2 then msgbox “value=2”Else msgbox “value not found”End if

Page 48: QTP Material

2) Select statementThis is to choose one out of the many options depending on the condition that comes satisfied. The condition is evaluated once and based on the value it attains one of the following blocks of code gets chosen to be run.Select Case (expression)Case “case1″{Block 1}Case “case 2″{Block 2}…..Case Else{Else block}End Select

Looping statements:There are 4 kinds of loop statements:1) Do…loop:This is used when a statement or a block of statements need to be executed while or until a said condition is true. Let us first  look at the syntax of this:Syntax 1:Do (While | Until) condition{Statement or statements}[Exit Do]{Statement or statements}LoopSyntax 2:Do{statement or statements][Exit Do]{statement or statements]Loop [{While | Until} condition]Condition: could be a numeric or string component that either attains a true or false value. If the condition is null it is treated as False.Observe the ‘Exit do’ in the above.There is also a slight difference between the syntax 1 and syntax 2.

In case of syntax 1, the statements within the do loop do not get executed unless, the condition becomes true or holds true.

For syntax 2, the statements within the loop get executed at least once and then the check is performed on the condition.

Page 49: QTP Material

Exit Do: In order to avoid infinite loops we will have to force the loop to exit. Exit Do is a statement that is used in such circumstances.2)While…wendSyntax:While{Statement or block of statement}WendIt is self explanatory from the syntax that the statements nestled under the while block get executed as long as the condition holds true.

Although this statement is available, it is not very flexible so it is recommended to use the Do…Loop statement.

3) For…NextThis is the statement that you would use when you want a statement/set of statements to run a certain number of times while a certain counter gets incremented or decremented.For counter = start To end [Step step][statements][Exit For][statements]Next

As you can see from the syntax above, there is a ‘Step’ clause to this statement. This clause is optional.

The step clause if not specified, the for loop steps one counter forward by default The step can be used to increment or decrement the counter value Exit For is similar to “Exit Do”, it can be used to come out of the For block and

execute the statement that follow. Any number of Exit For statements can be used within one block of For statement It is usually used with a if..then statement to make sure some condition that would

lead to infinitely looping is true and in case if it does, the For statement has a way to exit.

Any number of For statements can be nested within a For.Example:------------

Fori=1to 10……If x=true then……Exit forEnd ifNext

Page 50: QTP Material

Example for a positive step:For i = 2 To 12 Step 2total = total + kNextExample for a negative step:For i = 12 To 2 Step -2total = total + kNext4) For each…next:  This is similar to ‘For …next’. This is used for collection objects or arrays. This statement runs a statement or a set of statements for every object or item in an array instead of a number of times specified.  As the ‘For…next’ statement Exit for is used to exit before the looping is through, like in case of an error. Also, any number of For Each statements can be nested within each other.Syntax:For Each element In group[statements][Exit For][statements]Next [element]

Element is the variable that is used to iterate through the elements in the array or collection object

group stands for the name of the collection object or arrayNote:  We have not discussed collection objects so far in our series, but a collection object is nothing but an object which is a set of related items (objects, these might be of the same type or could be of different types)

Best Practices for Code Writing in VB Script1. In the beginning of every program, write down a brief description of what the

program does2. Provide comments for every variable used during its declaration to briefly describe

what this variable is going to do3. Keep the code modular, as much as possible4. Have the main program readable and have all the logic segregated in terms of

function, so it makes them easy to read and maintain.5. The segregation of code into functions will also increase reusability6. An agreed naming convention has to be used to maintain consistency7. Comments – Provide comments to make the code more understandable8. Indentation – Make sure that you indent the lines of code to clearly understand the

sequence of execution9. Option Explicit is to be declared so that you don’t run into issue when you have a

spelling mistake of a variable name

Page 51: QTP Material

10. Watch out for infinite loops

ConclusionThis concludes our brief introduction to VB Script. As already mentioned, this is in no way a complete guide to learning the scripting language, but enough to get us through writing beginner to moderate level QTP programs. There is one topic of functions that we did not cover here but that exclusion was deliberate. It is because, functions is a full length and a very important topic which we will discuss in detail in the coming articles.

11-QTP Password tool:For obvious reasons websites do not display password even while we are providing it as an input to sign in. QTP has a unique feature that will preserve the password from being out in the open thus maintaining the password’s integrity. As you might have noticed when we enter the password as ‘Mercury’ in the flights application a long and illegible sequence of characters is set in the password edit box.

This is how it looks:Dialog(“Login”).WinEdit(“Password:”).SetSecure “512c58cda469a14c01aa536f4a1a6a544d7d09e6″In the above line of code we can see that the password is encrypted.

QTP records a ‘SetSecure’ method when a password is entered. It automatically encodes the password entered during login and decodes the same while running the test.This is a mechanism that QTP employs to hide the password on the screen.

The user can also choose to enter a value discreetly into a non-password text box by using the SetSecure method and a encrypted equivalent of the text to be entered as a parameter.

If a need arises that we need to set a secure value in a certain text box then QTP comes with a tool called ‘Password Encoder’. This tool will take a regular text and encodes it.

The “Password Encoder Utility’ is available at:

Start > Programs > HP QuickTest Professional > Tools > Password EncoderIt launches the following app:

Page 52: QTP Material

The tool is very user-friendly and self explanatory.

When the “Password” field is provided with an input, the “Generate” button becomes active and on clicking it, the encoded text is displayed in the “Encoded String” field. The same can be copied to the clipboard by clicking on the “Copy” button which gets enabled when the encoded password is generated.

For example:

Click Generate:

The encoded text can be used as a direct input to a text/edit box or as a parameter in the DataTable.

Page 53: QTP Material

Active Screen:This is another versatile feature that QTP provides to make thetesting process more transparent to the user.  While recording QTP saves a snap shot of the application state when a certain operation was performed on it. The amount of details that you want your active screen to store and record depends on the settings. Before we talk more about the settings and what it means let us take a look at how the active screen looks.To view the active screen, click on “View->Active Screen”.Here I have a test that creates a Gmail account and I chose to view the active screen. This is how it looks:[Click to enlarge image]

As you can see, when I have the statement selected the corresponding object on which the statement acted upon is highlighted in the snap shot that the active screen has captured.Let us see what happens when I move to the next statement, (Click to enlarge image)

The corresponding text box where I am trying to enter the First Name is highlighted and as it can be noted this is no longer the Gmail page, it is the ‘create a new Google account’ page.

Page 54: QTP Material

Now let us see what how much of information can we ask QTP to store in this snap shot while recording and how do we do it.

Choose “Tools->Options->Active Screen” from the menu. It opens up the following window:

Each level of capture and its corresponding features are explained in this window. The default setting is as you see it in the screen shot.

The levels can be changed as required.

The following are the levels and what each level means gets displayed as the user sets them.

1. Complete2. Partial(Default)3. Minimum4. None

The capture level can be decreased or increased even after a test is created.

------------

Alternately the user can set a custom level of active screen capture by clicking on the “Custom Level” button and choosing the relevant options.

Page 55: QTP Material

The active screen, apart from being a visual aid at examining process also has several important aspects that can help the tester to manipulate the tests as required.

1. The Objects in the Active screen can be added to the local or shared object repositories.

2. Check-points can be added from this screen.3. Output values can be added4. Parameterization for the fields can also be done from this screen5. Steps can be added to the test

For example, in our Gmail page earlier if I choose to add the ‘Sign in’ button to the repository I can do that by right clicking on the object and the following options get displayed for me to choose from: (Click to enlarge image)

As you can see, I can insert a checkpoint, output value or choose to view or add object among other things.

Although we are yet to uncover the checkpoint and output value features, it is inevitable to mention them here, as they are some key functionality that the active screen helps with.

Replacing the active screen for a certain step:In case a need arises for me to change the active screen that got recorded by default, QTP provides me a way to do that.

Choose the option “Tools->Change Active screen” from the menu and QTP lets you go to the new screen and when you click on the new screen, the control goes back to QTP with the following confirmation message: (Click to enlarge image)

Page 56: QTP Material

On choosing “Yes” to this message, the new screen will be displayed hence forth when active screen for that step is viewed.

If all the snap shots in your test have to be replaced or updated, you can choose to run the test in “Update Run mode”. You might be able to guess what this means, but in any case we will have a detailed discussion on it later on in the coming articles.

Real time use of active screen is when you want to make changes to the test without opening your application but just from the screen captured during record.Although it must be noted that tests with Active screen captured occupy way more disk space than the ones without it.

On saving a test using “Save as” an option to exclude Active screen is available to the user.

Page 57: QTP Material

So what you can do is, record a test with active screen, modify it as needed while leveraging as many features as you can from it and “Save as” a new test without the active screen. This ensures that your tests are easy on disk space at the same time you get to use the active screen to your benefit while it was needed.

That is some brief insight into the topics, password encoder and Active screen. 

12- Expert view of QTP  – Expert view is where the operations we performed on the AUT get displayed as VB

Script code. For every LOC in this view, there is a corresponding column in Keyword view. There is also the action drop down box that can be used to access, view and edit

different actions in the test. This view is particularly useful for users who are familiar with programming using VB

script. One of the most important uses of this view is that it facilitates the creation of

functions and function libraries. (a topic for detailed discussion later) The user can print the test or function library as it appears in this view any time. File-

>Print will print the test.This is how it looks: 

Page 58: QTP Material

You can add statements to this view directly by typing in or by using step generator.

Step generator: This is a facility that QTP provides in order to make adding programmatic steps into

QTP easy for the user. You can use it in the Keyword view, function library, Active screen or Expert view to

generate steps It can be used to write steps into a test or to a function library. To launch, use the menu option “Insert->Step Generator” menu option. Right click

any where you want the step to go and select “Insert Step-> Step generator” or F7(except in Active screen)

Page 59: QTP Material

Example:I will explain this with a scenario: Open www.gmail.com and click on “Create Account” link. This is how this statement will look.

Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Link("Create an account").Click 

If I need to check if the link exists at all, before I write the code to click on it, I will need a step     before the above statement. This is how I do it:

Step # 1) Select the place where you need the step inserted.a) Expert view: Place the cursor where you want the step to go and launch step generator.b) Keyword view:  Select the step below which you want to insert the step.

Page 60: QTP Material

c) Active screen: In the active screen window, right click and choose the step generator option. It will ask you to choose the object on which your step should be based on. Following that the step generator window is launched.

Step #2) This is the step generator window that gets launched. Please note the details that it is displaying now. It is showing all the details related to the step that is currently chosen. We can choose the required values for the new step but that does not affect the current step.

Page 61: QTP Material

I am going to set the values as required by me to enable checking if the link exists.

Page 62: QTP Material

As you can see, I chose a Test Object, Create an account link and chose the operation Exist. I left the arguments empty because it is optional and chose that the return value of the operation be stored in a variable var_Exist. It displays the VB Script statement, as it is going to appear in the Expert view in the “Generated Step” field. In other words, the syntax.Step #3) The drop down where I chose a test object, I can alternately choose to base my step on a utility object or Functions.

Page 63: QTP Material

Step #4) Object: this field contains a list of required object or the function library source.Step #5) Operation field will let you choose the appropriate method, property or function.------------

Step #6) Arguments and Return value: These fields are self explanatory. The user could parametewise the arguments or provide constant values.Step #7) The user can just insert one statement or choose to follow it with another one by checking the “Insert another step” option ON.Step #8) So, back to our example. I will click OK. This is the statement that gets inserted. var_Exist = Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Link("Create an account").Exist

Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Link("Create an account").Click

Page 64: QTP Material

CheckpointsWe have so far encountered in various places of your articles, somereferences to checkpoints. There are many ways to define what a checkpoint is, this is mine –“It is a logical point in your test where you are trying to establish if there is a match between a certain expected value to the actual value as it exists on the AUT”.We have talked earlier; QTP provides certain inbuilt checkpoints but does not limit the user to just those. At any point in a test, the tester is free to build any number of check points in his test to include verification points. That according to me is one of the most versatile features in QTP.

It is obvious that custom checkpoints are entirely relative to each one’s problem at hand. We will equip ourselves with basic concepts on the checkpoints that come as an integral part of QTP.

1) When a checkpoint is added, QTP adds a “Check CheckPoint” in the Expert view and a corresponding row in the keyword view.Example: Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Check CheckPoint("Gmail: Email from Google") 

 2) The user can have the check point statement return a boolen value that depicts the result of the checkpoint. If it passed, it returns a 1 and 0 if failed. To be able to that, we need to use parentheses around the checkpoint argument in the statement in the Expert View.Example: i=Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Check(CheckPoint("Gmail: Email from Google")) 

3) By default, the name of the checkpoint will be the name of the object on which this check is performed.4) The user can accept this name or change it5) When the test runs, if the expected value matches with the actual one for the checkpoint, the checkpoint passes otherwise it fails.6) The results can be viewed in the Run Results viewer.There are 10 checkpoints that QTP provides to its users:

1. Standard Checkpoint2. Image Checkpoint3. Bitmap Checkpoint

Page 65: QTP Material

4. Page Checkpoint5. Text Checkpoint6. XML Checkpoint7. Text Area Checkpoint8. Table Checkpoint9. Accessibility Checkpoint10. Database Checkpoint

The general way a checkpoint is inserted is after the initial test steps are created. It is possible to add checkpoints during recording or editing though.

It is recommended that the tester has preliminary knowledge about all the checkpoints in order to make the right judgment about what checkpoint is apt for the task at hand.

In the previous QTP training session we listed all the checkpoints that QTP provides. All these checkpoints are very important to insert verification points in QTP tests to check if current and expected values of an object match or not. This determines the PASS or FAIL status of that test..

13-Standard Checkpoint:1) It is used to check the Object Property value.2) Compares the expected value with the actual value during runtime.3) It can be set during recording or editing a test.4) Active screen can also be used to insert this checkpoint. It is important that sufficient information be available in the active screen to be able to insert a checkpoint.For Example: If there is a screen with, Login edit box, Password Edit box, OK, Cancel and Help buttons. We need to check if the Cancel button is visible. We are trying to achieve this by placing a checkpoint on the “Visible” object property of the Cancel button. While recording I performed a enter Login, enter password and click OK; and the setting on my active screen is to just store the objects I acted on and not the others, I will not be able to place the checkpoint on the cancel button because the active screen does not possess information about that object. Therefore, it is important for the active screen to have captured all the objects in the page and only then we can insert the checkpoint. I hope this explains what I mean when I say that the active screen should have sufficient information.5) Once added, the checkpoint properties can be changed using the “Checkpoint Properties” dialog box.6) Every checkpoint gets added to the local object repository when added. It can be moved to the shared object repository if needed.7) Supported for all the environments as long as the appropriate add-ins are loaded.

Page 66: QTP Material

8) Some examples of the objects that this can be used on are: web images, Edit boxes, static text, web tables etc.How to insert a standard checkpoint while recording:Step #1) Insert->Checkpoint: Select this option from the menu after starting a record session.Step #2)   – Clicking on this icon also results in the same thing.Step #3) A list of relevant checkpoints applicable to the current or selected step on performing one of the steps listed in 1 and 2.

Step #4) Select the type of checkpoint. We will select “Standard” in our case.Step #5) QTP interface gets hidden and the user can choose the object in the AUT over which the user wants to insert a checkpoint.Step #6) Select the object and the following screen appears:

Page 67: QTP Material

Step #7) Choose the object and click OK in the dialog. The checkpoint properties dialog box is displayed.

Step #8) Select the properties you want checked and click OK. I am going to choose just the name. As you can see above, you can modify the properties to to either a constant value or parameterize. There is also a timeout parameter that you can set. What this means is that, QTP waits for the particular number of seconds specified in this dialog for a certain Object to attain a property value before it performs the check.Step #9) This is how I set the parameters and click OK.

Step #10) This is how my checkpoint looks in the keyword view:(click to enlarge image)

Page 68: QTP Material

Step #11) In the expert view, the following code gets displayed:

1 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Check CheckPoint("Sign in_2")

How to insert a Standard checkpoint while editing:1) Active Screen:    In the active screen, right on an object and select the option to insert standard checkpoint. After that, follow the same steps as above to insert a checkpoint. (click to enlarge image)------------

2) At any step in the QTP test, select the menu option “Insert->Checkpoint” and choose “Standard checkpoint”. Again follow the steps as above.How the checkpoint properties can be accessed and modifiedAfter creation, the user can modify a checkpoint as required. This can be done through the “Checkpoint properties” dialog box. This dialog can be accessed in the following ways:

Page 69: QTP Material

1) While creating a checkpoint this box opens up for initial definition of the properties2) Select an existing checkpoint statement in the Keyword view, right click and select “Checkpoint properties”3) Open the Object repository and the properties are available there are shown below: (click to enlarge image)

From this box, all the properties of a checkpoint can be modified as required.

Since the standard checkpoint is the first in our list I have provided the detailed steps of adding it in different scenarios and modifying it in different ways in detail. Moving forward I am going to list the properties and features that are unique for each checkpoint. It should be noted that the steps to add, use and manipulate the checkpoints are all the same for most of the checkpoints. From now on, unless specifically mentioned, the above approach can be used generically across the other ones too.

Image Checkpoint:A slight variation of a standard checkpoint is while it is used on web images.

In case the object on which the checkpoint inserted happens to be a web image, the following dialog box opens up.

Page 70: QTP Material

It should be noted that this screen is almost identical to “Checkpoint Properties” dialog, it is specific to images.

The only extra parameter is the “Compare Image Content” checkbox. If it is checked, the image in run time is checked with the one stored during the creation of the checkpoint to see if it is exactly the same. If they are the same, the test results will only have one image. If they are different both the images will be displayed in the test results.

For example, on the gmail page, I tried to insert a standard checkpoint on one of the images from the Active screen and this is what gets displayed: (click to enlarge image)

Page 71: QTP Material

I will not make any changes in the dialog, you can if you wish to and click OK.

This is how the inserted checkpoint is going to be: (click to enlarge image)