7 Important Points You Should Remember About Virtual Objects

1. A group of virtual objects that is stored in the Virtual Object Manager under a descriptive name is known as virtual object collection.

2. Virtual objects for analog or low-level recording are not supported by QuickTest.

3. Recognition of virtual objects can be disabled without deleting them from the Virtual Object Manager.

4. Virtual objects can only be used when recording and running a test. Any type of checkpoint on a virtual object cannot be inserted.

5. The virtual object collections shown in the Virtual Object Manager are stored on your computer and not with the tests that include virtual object steps. This means that if you use a virtual object in a test step, the object will be recognized during the run session only if it is run on a computer containing the appropriate virtual object definition. To copy your virtual object collection definitions to another computer, copy the contents of your \dat\VoTemplate folder (or individual .vot collection files within this folder) to the same folder on the destination computer.

6. Virtual objects can only be defined for objects on which you can click or double-click and that record a Click or DblClick step. Otherwise, the virtual object is ignored. For example, if you define a virtual object over the WinList object, the Select operation is recorded, and the virtual object is ignored.

7. You cannot use the Object Spy to view the properties of Virtual objects.

How to add object repository in qtp

How to add object repository in qtp

Hi friends, I got very good response from you on my previous post “object repository in qtp”. So today also I am going to give you some advance knowledge in context to object repository in QTP.
I am going to teach you two following things in context to object repository.

1. How to add object repository in qtp manually.
2. How to add or load object repository in qtp during runtime.

Procedure to add object repository in qtp manually

1. Go to Edit->Action->Action Properties window.
2. Than switch to “Associated Repositories” Tab.
3. Click on “+” sign.
4. Now click on right most side button and add object repository file (in .tsr format)

Procedure to add object repository in qtp during run time:

Just write following lines of code in your script.
——————————————————————————–

Dim qtApp

Set qtApp = CreateObject(“QuickTest.Application”)

qtApp.Test.Actions(1).ObjectRepositories.Add “C:\Repository1.tsr”
———————————————————————————

Note: Above script will add “Repository1.tsr” file to your test during run time. Please note that this object repository file will be loaded during run time so you can see it attached only during run time. During stop mode you will not be able to see attached object repository.

If you want to verify that object repository is added or not during runtime you can verify. When your script is in running mode just Go to Debug->Pause and then you can verify by going to Edit->Action->Action Properties and then associated repository tab.

QTP Tutorial – Using Virtual Objects and Recovery Scenarios in QTP Tests

Virtual Objects in QTP

Do you see Object not found error while running QTP tests? Well, this is because during playback QTP can’t recognize non-standard objects. To solve this object recognition problem we use Virtual Objects. Using Virtual Object Wizard we can map these unrecognized objects to standard class which then can be used as standard object to record the test.

How to solve object recognition problem in QTP?

Example of Virtual Object:
Here is a scenario: I am recording a test on a Microsoft word document. I activate the already opened MS word doc and I click on any of the icons in the top menu. For example, I click on “Format Painter”. The code that gets recorded into QTP is:

1 Window("Microsoft Word").WinObject("NetUIHWND").Click 132,120
2 Window("Microsoft Word").WinObject("NetUIHWND").Click 672,101

In cases like this we would go for a virtual object. By definition, a virtual object is an object that is recognized by QTP as non-standard but is instructed explicitly by the tester to behave like a standard object.

Virtual Object Wizard Steps:

Step #1) Go to the menu option “Tools->Virtual Objects-> New Virtual Object” and click “Next” in the following window.

Before you hit “Next” take a minute the read what this wizard will do.

Virtual Objects

Step #2) Here you will find a list of classes. You can choose any class depending on how the object in your application is behaving like. In our case, the “Format Painter” Icon is more like a button. So I am going to choose “Button” from the list.

Virtual Objects

Step #3) In this screen you can mark the screen where the object is on your AUT. Click “Mark Object” and choose the object from your AUT.

Virtual Objects

Step #4) The width and height values for the marked object will be populated once the selection is made. Hit “Next”

Virtual Objects

Step #5) You can now configure the way in which you would want the selected object to be recognized with reference to its parent. As you can see, you have a choice to see identify it based on its parent alone or the entire hierarchy. I am just going to keep the default values and click “Next”

Virtual Objects

Step #6) Give your virtual object a name and add it to a collection (nothing but a consolidated list of Virtual objects). I keep the default  values and click “Finish”

Virtual Objects

This completes the process for creation of a Virtual object.

Step #7) Go to “Tools->Virtual Objects->Virtual Object Manager”. Here you can see all the collections that are available and the objects within them.

Virtual Objects

Clicking on “New” will take you back to the creation process that we have just seen. You can delete a collection using the “Delete” button.

Once you are done creating the virtual object, repeat the recording process on your AUT for the same object. This is how the code looks:

1 Window("Microsoft

Word").WinObject("NetUIHWND").VirtualButton("button").Click

Now you will be able to perform all the operations on this VirtualButton that you can on a standard button object.

A few points to note:

1) This feature is not available for Analog and low level recording modes.

2) From the example you can see that the virtual object completely relies on the width and height factors, so it is not highly reliable.

3) To disable QTP from recognizing the virtual objects while recording, choose the option “Disable recognition of virtual objects while recording’ under “Tools->Options->General”.

Virtual Objects

Recovery Scenario in QTP

At times when you are trying to login to your Gmail account, assume a pop-up window comes up and you will be asked to confirm your security information. This does not happen every time you login. If your test is to login to Gmail account and as soon as you enter the user ID, password, hit the Sign In button and if your QTP test is expecting to arrive at your inbox your test is going to fail if the security information screen comes up randomly.

To handle cases like this we use the ‘Recovery Scenarios”.

Steps to create Recovery Scenario in QTP:

————

Step #1) Go to “Resources -> Recovery scenario manager” , click on the “New Scenario” icon.

Recovery scenario

Step #2) Click Next

Recovery scenario

Step #3) The trigger for this to start could be one of the following options. Choose according to your scenario. In our case I will choose, Pop-up window. The other options are self explanatory.

Recovery scenario

Step #4) Using the “Pointed hand” option, choose the window that you would want to add.

Recovery scenario

Step #5) Define the recovery option by clicking on the “Next” icon below:

Recovery scenario

Step #6) Choose one from the list. I am going to choose “Keyword or mouse operation”. The options in this screen are really easy to understand. So choose accordingly.

Recovery scenario

Step #7) I am going to go with the default settings and click Next. The recovery operation gets added to the list. If you need to add more than one recovery operation you can keep the corresponding checkbox checked and click Next. It will take you back to the screen in Step number: 5. Or if you are done, you can simply uncheck the checkbox and click on “Next”. That is what I am going to do.

Recovery scenario

Step #8) Now you will have to define the post recovery operations.  All the options are as their names indicate. I am going to choose “Proceed to next step”. Click Next

Recovery scenario

Step #9) Enter the scenario name, description and click Next

Recovery scenario

Step #10) It provides a gist of your scenario. As you can see, there are 3 parts to a recovery scenario. The Trigger, Recovery operation and post recovery operations. You can choose to add this scenario to the current test or to all tests by choosing the relevant checkboxes. I am going to keep them unchecked at this point because I want to show how a tester can associate them to a test explicitly. Click “Finish”

Recovery scenario

Step #11) The scenario we just created will appear in the list. Save and close.

Recovery scenario

Step #12) Associating the recovery scenario. Open a test, in the “Resources” pane, right click on “Associated Recovery scenarios”, right click and choose “Associate recovery scenario”. Browse for the scenario and click “Add Scenario”. The chosen scenario will appear in the list in the Resources pane.

Recovery scenario

Step #13) Also, you can go to “File->Settings->Recovery” and add the scenarios you would like. Here you can also choose the options as to how often you would like it to run. You can choose to run it, On Error, On Every Step or Never.

Step #14) The extension for a recovery scenario file is “.qrs”

This concludes our discussion on Virtual Objects and Recovery scenarios. I would recommend the tester to use various combinations of Trigger, Recovery and post recovery operations when practicing the recovery scenarios.

QTP Tutorial – QTP Smart Object Identification, Sync Point, and Test Result Analysis

Smart Identification:

Assume a situation when no object matches or multiple objects match the recorded description for an object during run time, how does QTP handle it?

QTP has a mechanism in place for cases exactly like this. If the recorded description does not enable QTP to identify the specified object in a step, and a smart identification definition is defined (and enabled) for the object, QTP tries to identify the object using “Smart identification”.

Let us see how this works with some examples.  For every object there are Primary Properties and Secondary properties.

Example 1: Object with the recorded description is not found.

On a page there was a button and the following are properties:
a) Primary: Name
b) Secondary: Abs x,y

While recording the “Name” property was “Login ID”. Due to some changes to the application, the “Name” property is now changed to “User ID”. In this case, QTP will find a button with a different description and it should fail if it considers the primary properties alone.

But in cases like this when the primary properties don’t match then it checks the secondary ones and if they match it recognizes the object. In this case, it is going to recognize the button by its X and Y co-ordinates.

Example 2: QTP was supposed to find a page X and there are 2 pages with similar browser settings.

In this case too, it tries to use the “name” or other properties to find the right page/pages and works accordingly.

The above 2 are examples of cases where QTP engages the smart identification mechanism.

  • The Test results will also show if a step employed Smart identification to run successfully.
  •  If QTP cannot find the object despite Smart Identification, then the test fails.

For most of the objects, QTP provides a default Base filter properties (Primary) and Optional filter properties (Secondary) that it checks if we enable Smart identification for them. The user does have an option to edit what properties to consider too. To do so, go to “Tools->Object Identification”. Choose the relevant Environment from the drop down and choose the Object Class. Once you chose it, check the “Enable Smart Identification” and click “Configure”.

Smart identification

Click Add or Remove

Smart identification

Select the properties as required:

Smart identification

Make your selection and Click OK when done.

Smart identification

The above process will ensure that the next time it has difficulty identifying an object of this class, it will employ smart identification to do so.

Also, for most of the objects “Smart identification” is turned ON by default. You can see where this is the case for a certain object by accessing it in the OR under “Additional details” part of its object properties.

It is set to “True” if enabled and “False” if disabled.

You could also choose to enable or disable Smart identification entirely for a test run. Choose “File->Settings->Run->Disable Smart Identification during the run session” option.

Synchronization point:

Consider this program,

1 SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
2 Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
3 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "swatiseela"
4 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure "sfgs686898"
5 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click
6 Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click

In an ideal world, as soon as you hit the “Sign in” button in the gmail login page, the “Inbox” should get displayed without any delays. That means, the state of the application is ready for the last statement in our example to be executed immediately after the last but one statement runs.

But in real time, due to many reasons applications don’t always load at the same pace. If we do not instruct QTP to wait a certain while before it moves on. More specifically until an object attains a certain state.

A synchronization point is used to instruct QTP to wait until a particular object property achieves the value you specify.

On inserting a sync point a “Wait Property” statement is inserted into the test.

1 Browser("Gmail: Email from Google").Page("Gmail - Inbox"). Link("Sign out").WaitProperty “Visibile”,true,20

So your new program is going to look something like this: (line #6 below)

1 SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
2 Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
3 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "swatiseela"
4 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure "sfgs686898"
5 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click
6 Browser("Gmail: Email from Google").Page("Gmail - Inbox"). Link("Sign out").WaitProperty “Visible”,true,1000
7 Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click

It can be inserted while recording using the menu option “Insert->Synchronization Point”.  Choose the Object to insert the sync point.

Synchronization point

Enter the value as required:

Synchronization point

This is the statement that gets inserted:

1 Browser("Gmail - Inbox").Page("Gmail - Inbox").Link("Sign out").WaitProperty "visible", true, 10000

Running a test

1) Automation->Run or F5 typically runs the entire test.

2) You can run a part of the test by choosing “Automation->Run Current Action” option

3) You can run a test from a certain point in your test by choosing “Automation->Run From Step” option.

4) As soon as you choose any of the above ways to run a test, you will be promoted to choose the location where you would like the test results to be stored. You can choose the folder by choosing the first option in which case, the results will be stored for every instance of the test run. But if you choose the next option, temporary folder, the results get overwritten and only the latest test run result will be stored in the folder chosen. In terms of memory, it is advisable to use the second option while testing your QTP test. Unless you want every test run results, do not choose the first option because obviously it is going to use up a lot of space.

————

Running a test

5) Input parameters:  If the test input parameters were defined for this test, this tab is the place where you provide them.

Running a test

6) You can also run a couple of tests all at once in a batch. QTP has a “Batch Runner” tool. It is also an external tool just like a “Password encoder tool” that we discussed earlier.

7) To launch go to “Programs > QuickTest Professional > Tools > Test Batch Runner”. Create a batch (.mtb) using icon1.

Running a test

8) Once creating a list is done, run the batch using icon2 icon. After the batch run is complete, you can view the results for each test in its default test results folder (<test folder>\res#\report).

Test results:

In our articles so far, whether we are discussing data table iteration, checkpoints, smart identification or in general the test step run , the Test results is the place you get to see whether something was successful or not.

Apart from the above, the test results can hold the screenshot of your AUT when a failure occurs. This depends on the settings at “File->Settings->Run”.

The tester can print and export test results.

To make test results more understandable the user can write his comments into the test results.

For example, if a certain condition fails in your test you might want to write in the test results that “Did not work for the value X”. You can do so by using the “reporter.reportevent” statement. The following is the syntax:

Reporter.Reportevent(Event Status,Reporter step name, details)

Event status: MicPass, MicFail,MicWarning,MicDetail, the next two parameters can be any text that helps include further detail.

If this is my statement and I run it:

reporter.ReportEvent micPass,”Swati’s First Step”,”Passed coz I told it to pass …”

The test results are going to look like this: (click to enlarge image)

Test results

Transactions:

Since this is not a very widely used feature, I am going to do a high level introduction here.

Typically, a test is divided into transactions when you have to measure how long it takes to run a certain section of it.

It is also used when a QTP test is to be used by Load Runner or Business Process Monitor. In either of these cases, your test has to be recorded in terms of a transaction and anything outside of it will be ignored.

You can start a transaction from QTP using “Insert->Start Transaction”. Give it a name, choose if you want it before or after the current step and choose OK.

Transactions

Services.StartTransaction “TransactionTest” – Gets inserted. Now I will record a login into Gmail.com.

Once you are done recording. Choose “Insert->End Transaction”. Click OK.

Transactions

Services.EndTransaction “TransactionTest” – gets inserted.

This is the code:

Transactions

Now I will run this test. Let us see how the test results look. The results will show a summary in terms of time taken to finish the transaction.

Transactions

Silent Test runner:

Another tool that QTP provides is the Silent Test runner. This enables the tester to run his test without having to launch QTP. It also helps simulate QTP runs from load runner and verify it compatibility with the same.

It will not work if QTP is already open and another test is running via it.

Use Start > Programs > QuickTest Professional > Tools > Silent Test Runner menu command to invoke it. Select the test and click “Run Test”

Silent Test runner

This is how it looks while running the test:

Silent Test runner

Once it is completed:

Silent Test runner

Test Run log:

Silent Test runner

The “Transaction Summary” will be activated if the test contains at least one transaction.

QTP Tutorial – How to Make QTP Tests Modular and Reusable Using Actions and Function Libraries

QTP Actions and Action Properties:

Actions divide a test into logical units. This aids in highly readable tests and make sure that modularity is achieved.

There are 3 types of QTP actions:

  1. Reusable – only these can be called multiple times within the same or different tests
  2. Non-reusable – These cannot be called by any other actions
  3. External actions – a reusable action when called from another action becomes an external action in the called action.

How to use QTP Actions in  tests?

1) By default all new actions are reusable

2) Every action has its own “Action” datasheet or a local sheet

3) Call to an existing action in another test can be inserted by using the menu option: “Insert->Call to an existing action-> (Choose test/action)”

QTP Actions

4) The statement or action call inserted in the current test will be as follows:

1 RunAction “Action2[Testname]”, oneiteration

5) The action will be called as many times as the action called properties is specified for the parent action.

Example:
Action2 is a reusuable action in Test2. It is called on every iteration in the datatable of Test2.
Action1 is the action that calls Action2 in Test1.
Action1 runs only once.
Then, Action2 will run only once irrespective on how many times it was called in Test2.

6) A previously reusable action can be changed to become non-usable and vise versa.

7) When a previously reusable action is marked as non-reusable the test that calls the action fails and a warning message is displayed to the user.

8) We have seen in the previous article how parameters can be passed “To” and “From” actions.
To define these you could do one of the following:
a) Choose the action from the keyword view, right click and choose action properties.
b) While in the action in the expert view, select Edit->Action Properties from the menu.

9) The dialog box appears with General (name, description, reusable or not), Parameters(i/p or o/p), associated repositories (can associate another action’s OR) and Usedby tabs

QTP Actions

10) To send parameters to an action the general syntax is:

1 RunAction “Action Name”. Oneiteration, i/p parameters, o/p parameters

The following are some of the ways in which you can utilize the output value of an action in your test depending on your requirement:

a) Action o/p value (value returned by a called action) can be stored in a variable.

1 RunAction “Action1”,OneIteration, i/pvalues, x, x being the variable

b) Action o/p value can be stored in an environment variable.
To create an environment variable choose “File->Settings->Environment tab” , in the ‘Variable Type’ drop down choose userdefined and click + and ‘Add new environment Parameter’ – enter the name (env_Var) and an empty value and click OK.

QTP Actions

To assign the o/p value to this variable,

1 RunAction “Action1”,OneIteration, i/pvalues, Environment(“env_var”)

c) Action o/p value can be stored in a data table column.

1 RunAction “Action1”, OneIteration, i/pvalue, DataTable(“A”, dtGlobalsheet)

QTP Functions and Function Libraries:

Though there are many built in functions available in the QTP for the tester, there might still be instances when you might want to perform a specific operation and make those steps reusable. You could do that by creating user defined functions, put them in a separate file, associate it with the test and have the function name work as a keyword for that particular test.

————

So by definition, a function is nothing but a piece of code that performs a certain task.

Let’s create a function library now:
Use the menu option “File->New->Function Library” or “Shift+Alt+N” or click on the “New” drop down option in the menu and choose “Function library”

QTP will open up an editor, very similar to the keyword view of a test. Here you can write your code. I am going to include statements that will login a user into gmail.com page.

QTP Functions

1 Function gmailLogin(uname, pwd)
2 SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
3 Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
4 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set uname
5 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure  pwd
6 Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click
7 End Function

Once you are done writing the code, “Save” the function library by choosing the required name and location on your computer.
Note – A function library does not get auto included in any of your tests. You are going to have to do it explicitly.

The following are the steps to associate a function library into your test:

Step #1) Open your test or create a new test

Step #2) Depending on the settings you have on your IDE you might have the resources pane already available to you. If not choose the menu option “View->Resources” and this displays the pane.

Step #3) Right click on the “Associate Function libraries”, click the “Associate Function library” option and choose the library file you created earlier.

QTP Functions

Step #4) There will be a message that asks for the tester’s confirmation before converting the path to a relative path. This is done to make sure that the test does not fail if the files are moved as long as the same hierarchy is followed. Click yes on this dialog box:

QTP Functions

Step #5) It will appear under this node from now and that is how you verify if your association has worked or not.

Step #6) Once you have associated the library make sure you save your test.

From now on if there is a statement in my test that is as follows, it will invoke the function in the library and execute the steps in there.

1 gmailLogin(“swatiseela”,”akihad989080890”)

In the above statement you are passing constant user name and password values. But if you choose to you can pass the values from the data table too.

1 gmailLogin(DataTable("SignInName", dtGlobalSheet), DataTable("GPassword", dtGlobalSheet))

You can have more than one function in your library files and you can have more than one library files associated to your test.

Conclusion:

This concludes our Function libraries and Actions.  These two topics are crucial for a tester as they make all your tests more modular and reusable.

The next topic is going to be on Object repositories (OR). We will discuss how to create, associate and work with shared ORs and OR manager.