http://quicktesthp.blogspot.com

QTP VBScript new series + Interview Question Bank on QTP for enrichment of Knowledge in QTP

This Site has been brought to you by HP Certified Expert of QTP.

Exciting new articles for October:

1) QTP Tip:Deselect all Radio Buttons

2) HP QTP Crypt Object

3)Adding Hyperlinks in Excel Spreadsheet

Best of Luck Friends ! ! !

Expert QTP
expert.qtp@gmail.com

All Articles are Copyright Protected. These are Free for Reading & Personal Use. Reproduction in Any Form without the Permission is Illegal & Strictly Prohibited.

Copyright © 2009 ExpertQTP

Google Search

Tuesday, August 26, 2008

Create a Schedule to Run QTP at a Desired Time

Every Microsoft Windows has a wonderful feature of "Task Scheduler", which can be used for automatically running any application at any desired time, at desired frequency right from a specified date for initial launch. Once scheduling is done, it does not require any user intervention; however the only important thing to remember is that the PC must be kept on at the scheduled time.

This "Task Scheduler" utility is available in Windows "Control Panel" by the name "Scheduled Tasks". Detailed steps are described as under.

1) Say our aim is to automatically run the file by the name QTP_Test.vbs available at the location C:\ExpertQTP\QTP_Test.vbs

2) Go to Windows "Control Panel" -> "Scheduled Tasks".

3) Click on "Add Scheduled Task" in the "Scheduled Tasks"

4) This will start the "Scheduled Tasks Wizard".


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


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


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


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


This way wizard will not ask the user for his manual intervention of feeding the password every time.

9) Click "Finish"

10) Above mentioned simple steps shall now execute the desired script automatically, every day at 12.59PM starting from 07/13/2008.

Key Word: QTP, Quicktest, Automate, Schedule



Read more...


Saturday, August 23, 2008

How to Manage your Files using QTP

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

Getting access of an already created file

For this, use the below written code.

Set obj=CreateObject("Scripting.FileSystemObject")
obj.getFile("D:\testfile.txt")


In order to run this code perfectly fine, the File "testfile.txt" should be present in the D:\ location else QTP will raise an error.

As you can see in the above mentioned code, we have provided the complete path for the file which we also call as Absolute path. Now this code is not of much use unless we do something more along with it. Like after getting the reference for a file, we can see the size of the file, its parent folder, its name etc.

Check for the existence of an already created file

Sometimes we may be interested in knowing whether our file exists or not. For this, we use "FileExists" method. This checks whether the files exists or not. The "FileExists" method requires a single argument containing the full path of the file. This method returns a boolean value. I hope you guys must be aware of what a boolean value is. Now this method will return a value "True" if the file exists and "False" if the file doesn't exists.

The below mentioned code will explain in detail:

Set testobj = CreateObject("Scripting.FileSystemObject")
If test.FileExists("D:\Expert\MyTestFile.txt") Then
Set objFile = testobj.GetFile("D:\Expert\MyTestFile.txt")
Else
MsgBox "The file doesn't exist."
End If

Deleting the File

We can delete a file by firstly creating an instance of FileSystemObject and then we need to call the DeleteFile method. Lets see the below mentioned code to explain this concept.

Set myobj = CreateObject("Scripting.FileSystemObject")
myobj.DeleteFile("D:\MyTestFile.txt")

You can even delete your MS Word file with the above code. Cool na.... I know.

Let me show you something even more interesting. If the file is read-only, then the "DeleteFile" method will not be able to delete the file. So how to delete such a file? Any guesses.

This thing is left for you guys to find it out how we can delete a read only file.

Copy Files

Copying files from one location to another is also a very frequently done task. For this, we use CopyFile method. The syntax for copying files is:

obj.CopyFile "Source-File-Path", "Destination-File-Path"

In order to copy a file from "C:\test.txt" to "D:\test.txt", we will use the code:

Set obj=CreateObject("Scripting.FileSystemObject")
obj.CopyFile "C:\test.txt", "D:\test.txt"

We can even rename a file just by changing the name of the file in the "Destination-File-Path".

What happens if we try to copy a copy inside a folder and the folder doesnt exist? This thing is left for you guys to try.

Moving Files

We can also move files from one one location to another[Also known as Cut and Paste]. For this, we require MoveFile method. It is infact quite similar to CopyFile method.

We use the below code to move files from one location to another.

Set obj=CreateObject("Scripting.FileSystemObject")
obj.MoveFile "C:\test.txt", "D:\test.txt"

Reading all contents of a file in a single shot

We can read all the contents of a file using the ReadAll method. It captures all the file contents and stores inside a variable.
The following code will help you in reading all contents of a file "D:\test.txt".

Set obj1= CreateObject("Scripting.FileSystemObject")
Set obj2= obj1.OpenTextFile("D:\test.txt")
FileContents = obj2.ReadAll 'Read all contents of the file
MsgBox FileContents 'Display contents of file
obj2.Close 'Close the File

Reading all contents of a file line by line

We can read all the contents of a file line by line. For this we require the ReadLine method.
The following code will help you in reading all contents of a file "D:\test.txt" line by line.

Set obj1= CreateObject("Scripting.FileSystemObject")
Set obj2= obj1.OpenTextFile("D:\test.txt")
Do Until obj2.AtEndOfStream
Line=obj2.ReadLine
msgbox Line
Loop
obj2.Close



Read more...


All about Recovery Scenarios using QTP

Introduction to Recovery Scenarios:

While executing scripts, we usually encounter unexpected & unpredictable events & errors, which results into application crashing during a run session causing total disruption of the run session and distortion of results. Such problems are quite frequent especially when the tests are made to run unattended. In such a case the test process halts until the user perform some desired recovery operation.

Recovery scenarios are useful when it is difficult to predict at which step the errors can come or when we are confident that the error will not come in the QTP script, whereas it can be anywhere outside the QTP Script. For illustration; Pop-up message of “out of paper”, as caused by the printer device driver. “On error resume next” is preferred when we sure that the error is expected one and wish to perform some other actions.

In order to handle such situations QTP comes to our rescue by creating recovery scenarios and associates them with the particular tests. What does a Recovery Scenarios do is to activate a specific recovery operation when a trigger events takes place. Most simple example of a typical unexpected & unpredictable events & errors is like Incompatible Media in portable Drive.

The Recovery Scenario Manager presents a structured wizard which helps us in defining the recovery scenario, like detailed definition of the unexpected event and the operations required to recover from the exception during the run session.

Advantages of Recovery Scenario Manager: Recovery Scenario Manager can be used to handle several known errors occurring at runtime. Following four events available in the recovery scenario manager are extremely helpful

1) Application Crash: This event is useful in handling crashed applications at runtime.

2) Pop Up Window: This event is useful in managing various unwanted application windows, which get built-up at runtime.

3) Test Run Error: This event is useful in handling VBScript statement errors at runtime.

4) Object State: This event is useful in handling object related errors at runtime.

Elements of Recovery Scenario:
Steps to handle the exceptions are:

1) Trigger Event: Is an unexpected event like appearance of a Pop-up window, object state, test run error causing application crash or interruption in our running session.

2) Recovery Steps: Constitutes a series of steps required to be performed to enable QTP to proceed further with the process of test after some trigger event has interrupted the run session. Examples of a recovery operation can be 1) A keyboard or mouse Operation like a Click over the “OK” button in the Pop-up window 2) Close Application Process 3) Function Call 4) Restarting the OS etc.

3) Post-Recovery Test Run: Are a set of instructions designed to be provided to QTP on proceeding further with the test after some recovery operation has been carried out. Examples of Post Recovery actions can be repeating the complete test from the beginning or some steps may be skipped altogether & continuing with the remaining steps in the test.

QTP & Recovery Scenarios:

All Recovery scenarios get saved & logically grouped in recovery scenario files. Grouping of various recovery scenarios in recovery scenario file can be managed according the user requirements. Recovery scenario files carry a typical extension of .rs.

In order to instruct QTP to carry out a recovery scenario during a particular test run, we firstly associate it with the particular test. There is no limitation to any fixed number of recovery scenarios associated with a test. Order of execution of various recovery scenarios associated with a test can easily be prioritized, thereby the trigger events get recognized and handled in the desired sequence.

Whenever any error comes during the execution of a test having many recovery scenarios associated with it; QTP intelligently hunts for the defined trigger event which had caused the particular error. After detecting the trigger event, QTP automatically performs the desired recovery steps and post-recovery test runs etc.

Recovery statements can be inserted in the tests to comfortably control and activate the recovery scenarios during the test run.

Cons of Recovery Scenarios:

Although Recovery Scenarios are users friendly on one hand; they tend to slow down the speed of the Test Run. Presence of a few such recovery scenarios would reduce the speed of Test Run significantly. This can become irritant to the testers, who can prefer the approach of using VBScript On Error/Goto 0 far more useful for catching & handling small errors.

Keywords: QTP, Recovery Scenarios, errors, exception handling


Read more...


Thursday, August 14, 2008

How to Record Right Mouse Clicks using QTP

For recording the right mouse clicks in QTP, we need to manually modify the configuration file and then load it.

This is a great article extracted from QTP Help Guide, which leads us through important steps to configure QTP to record our Right Mouse Clicks.

Step –1: Choose Tools > Web Event Recording Configuration. The Web Event Recording Configuration dialog box opens.


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

Step –3: In the Custom Web Event Recording Configuration dialog box, choose File > Save Configuration As. The Save As dialog box opens.

Step –4: Navigate to the folder in which you want to save the web event recording configuration file, and enter a configuration file name. The extension for configuration files is .xml.

Step –5: Click Save to save the file and close the dialog box.

Step –6: Open the saved configuration file for editing in any text editor. The configuration file uses a defined structure.

The beginning of the file, which is relevant for Web objects, is shown below.


The Property Name argument controls the recording of the mouse buttons. The value of the mouse buttons are defined as follows:
1—Left
2—Right
4—Middle

Step –7: Edit the file as follows:
To record a left mouse click for the onmouseup event, add the following line:

To record right and left mouse clicks for the onmousedown event, add the following lines:





Note: Only one event, either onmouseup or onmousedown, should be used to handle mouse clicks. If both events are used, QTP will record two clicks instead of one. By default, QTP listens for the onmouseup event.

Step –8: Save the file.

Step –9: In the Custom Web Event Recording Configuration dialog box, choose File > Load Configuration. The Open dialog box opens.

Step –10: Navigate to the folder in which you saved the edited configuration file, select the file, and click Open. The Custom Web Recording Configuration dialog box reopens.

Step –11: Click OK. The new configuration is loaded, with all preferences corresponding to those you defined in the XML configuration file. Any Web objects you now record will be recorded according to these new settings.

Key Words: QTP, quickest, Right Mouse Click, Event Recording





Read more...


Wednesday, August 13, 2008

Exploit the Power of MS Excel through QTP

The objective of this article is to briefly understand the process of interaction of MS Excel and VBScripts.

For automating an application a framework is created in the beginning. This requires an independent structure for reporting and data. Microsoft Excel plays a very important role in this framework approach.

We can easily use the built-in mechanism of QTP through which we can display the test results in a predefined format. A result sheet gets generated after the execution of the test in QTP; which provides an in-depth view of the script – through which we can know the various point of failures, warnings and the passes.

In the test script we create customize various checkpoints at our will. Likewise the result file can also be customized based upon the checkpoints already created according to the defined criterion of Pass / Fail.

Generally while working in MS Excel, the user desires to generate a detailed report of the entire test. The idea of generating such detailed / customized report is to have the output in a format as per our own choice and to preserve the file in a centralized location.

The entire process can be performed in following basic steps:

Step-1: Understanding the hierarchy of MS Excel Application.

Step-2: Creation of the desired Object in MS Excel

Step-3: Creation of a new MS Excel workbook or opening an existing one.

Step-4: Setting the objects for various sheets in the workbook.

Step-5: Writing and fetching the data values in the cells.

Step-6: Saving and closing of the workbook

Step-7: Closing the application and clearing the memory

The above steps can be explained through suitable illustrations to understand the approach properly.

Understanding the hierarchy of Excel Application


It is believed that the user is fairly acquainted with the basics of MS Excel like:

1) What is MS Excel Application

2) What are Workbooks in Excel

3) What are Sheets in Excel

4) What are Cells in Excel

Hence I am skipping the basic explanation of the above basics of MS Excel & directly moving on to the main content of our topic.

Some of the simple VBScripts are being described below for performing various actions in MS Excel.

Creation of an Object in Excel:

In the process of reporting it is the first step. In MS Excel the reporting can be done in two ways like 1) in the background wherein the application shall not be visible 2) the application can be made visible to the user once the process of writing or fetching the data is going on.

However in both the above mentioned methodologies we need to create objects in Excel Application for example:

Dim xl
Set xl = CreateObject(“Excel.Application”)

When we run the above script, we can see a process named "Excel.exe" in the Windows task Manager.

Creating a new workbook or Opening an existing one:

After creation of the object in Excel, it implies that Excel application has been invoked, however it is not visible. From now on we can either continue to perform the operations in the invisible back ground alternatively we can make the application visible and then we can perform the operations.

To make the application visible:
xl.visible = true

To open a new Workbook:
xl.workbooks.Add

To open an existing Workbook:
xl.workbooks.Open(“File Name with complete path”)

Setting and accessing the objects of sheets in workbook:

After opening a workbook in Excel (A New one or opening an existing one), next activity is to feed some data in various cells in various sheets of our workbook.

MS Excel provides three sheets in a workbook by default, which are available to us for performing various operations. To access these sheets with great ease, we need to create objects referencing these sheets. This will help us in avoiding describing complete hierarchy time & again.

For example we wish to create a reference for a sheet with an index i, beginning from 1:
Set sht1 = xl.activeworkbook.sheets(i)

We can easily add or delete the desired sheets from the active workbook

To add a sheet in the workbook:
xl.activeworkbook.sheets.add

To delete a particular sheet: ( where i represents the index which begins from 1)
xl.activeworkbook.sheets(i).delete

To change the name of the sheet:
xl.activeworkbook.sheets(i).name = “Name of your choice”

To count total number of sheets in a workbook:
Countnt = xl.activeworkbook.sheets.count

Writing and fetching the data values in the cells:

To write the data in Excel sheet, we need to identify the Cell ID of the cell where the data is needed to be written. Similarly for accessing the data value from particular cells, we must know their Cell ID.

For an example we want to write some data in sheet2 cell ID as D8, the command can be written as under. Here “D” represents the Column Number & “8” represents the Row Number.


xl.activeworkbook.sheets(2).cells(8,4) = “hello”

To fetch the data from sheet3 cell ID A7:
Val = xl.activeworkbook.sheets(3).cells(7,1)

If an object has already been created in a particular sheet, we don’t have to repeat the complete hierarchy again, instead we can simply write:
Object.cells(row,col) = value

Saving and closing a workbook:

After finishing the work we can save the workbook to a desired location with a different name or save the changes made to an already existing open workbook.

To save the new workbook under a new name:
xl.activeworkbook.saveas “path_with_file_name.xls”

To save the changes made in an existing workbook:
xl.activeworkbook.save

To close a workbook:
xl.activeworkbook.close

Closing an application and clearing the memory:

To close the application:
xl.quit

To clear the memory from all objects:
Set xl = nothing

This is not the end; however it is just a beginning for us to explore the power of QTP in exploiting the potential of MS Excel through simple VBScripts.

Keywords: MS Excel, QTP, VBScript


Read more...


Tuesday, August 12, 2008

Important Challenges faced by Software Testers

Famous book 'Surviving the Top Ten Challenges of Software Testing - A People-Oriented Approach', written by William Perry and Randall Rice, wonderfully describes following Ten challenges faced by the software testers. I am briefly mentioning these challenges here just to generate a healthy curiosity among my software tester fellows. For in-depth details, please go through this wondeful book & enjoy.

CHALLENGE – 1: TRAINING IN TESTING
IS TESTING A NATURAL-BORN INSTINCT?

Core Issues are :
($) Lack of education in testing
($) The large majority of testers have never had formal training in software testing.
($) Many testers and their management are unaware of training sources for testing.

Solutions for Training:
($) Obtain formal training in testing techniques
($) Certification : CSTE (Certified Software Test Engineer)
($) Attending conferences
($) Reading books and articles

CHALLENGE – 2: RELATIONSHIP BUILDING WITH DEVELOPERS
WHOSE SIDE ARE TESTERS ON?

Core Issues are :
($) Lack of teamwork
($) "Us versus them" mentality, seen most often in organizations with independent test teams. Here Them refers to the Developers.

Solutions to the Teamwork Challenge:

($) The goal is to get to "Us and them"
($) Each person on the team can have a role in testing like
- Developers: unit and structural testing
- Testers: independent testing
- Users: business-oriented testing
- Management: to support testing activities

CHALLENGE – 3: USING TOOLS
TESTING WITHOUT TOOLS:
Core Issues are :

($) Lack of understanding of the usefulness of test tools
($) Without upper management support, it is difficult to acquire test tools.
($) A process is needed for the tools.
($) People should be trained in the use of test tools.
($) People must accept and apply the tools.

Solutions for Acquiring and Using Test Tools:
($) Identify a "champion" for obtaining test tools.
($) Base the case for test tools in costs vs. benefits.
($) Have a basic testing process in place.
($) Train people in tool usage.
($) Measure the benefits.

CHALLENGE – 4: GETTING MANAGERS TO UNDERSTAND TESTING
Core Issues are :
($) Management is not fully aware of what is required for effective testing.
($) Management is often focused on the product, not the process. This leads to lack of management support and involvement for testing.

Solutions to Educating Management in Testing Issues:
($) Cultural change is needed.
($) Focus your message to management on:
- reducing the cost of rework
- meeting the project schedule
($) The benefits of testing must relate to these two things to be persuasive.

CHALLENGE – 5: COMMUNICATING WITH USERS ABOUT TESTING
WOULD THE REAL CUSTOMER STAND UP?
Core Issues are :
Core Issue No. 1 - A lack of understanding of who the customer really is. We must understand the difference between: Customers & Users

Core Issue No. 2 - Lack of customer involvement in testing.
Solutions to Identifying and Involving the Customer in Testing:
($) Involve the customer and users throughout the project by performing reviews and inspections.
($) Include users on the system test team.
($) Perform user acceptance testing.
($) Understand the difference between the customer and users.

CHALLENGE – 6: MAKING THE NECESSARY TIME FOR TESTING
TOO MUCH WORK – TOO LITTLE TIME :

Core Issues are :
($) Arbitrary schedules and estimates do not allow enough time for testing.
($) Realism: There is never enough time to test every possible combinations of test conditions.

Solutions to the Time Crunch:
($) Base schedules and estimates on measurable testing activities.
- Scripts to be executed
- Cases to be tested
- Requirements to be tested
($) Have contingency plans for schedule slippage.
($) Integrate automated testing tools to the project.

CHALLENGE – 7: TESTING "OVER THE WALL" SOFTWARE
OVERCOMING THROWING STUFF OVER THE WALL:

Core Issues are :
($) Developers depending on testers to find bugs.
($) Seen most often when independent test teams are used in an organization

Solutions to Overcoming Throwing Stuff Over the Wall:
($) Developers must take ownership and responsibility for the quality of their work.
($) Quality control is most effective when performed at the point of creation.
($) Train developers to become excellent testers.
($) Get management support for developer responsibility for quality.

CHALLENGE – 8: TRYING TO HIT A MOVING TARGET
Core Issues are :
($) Software and systems that undergo rapid and/or constant change.
($) Software development techniques such as Rapid Application Development can produce a new version of the software very quickly.
($) You can’t perform a four-week test every day manually.

Solutions for Hitting a Moving Target:
($) The testing process must accommodate change.
($) Focus on testable requirements.
($) Use automated testing tools.
($) Manage the rate and degree of change.

CHALLENGE – 9: FIGHTING A LOSE-LOSE SITUATION
Core Issues are :
($) Testers are often the "bad guys" when they find defects, yet if the software goes live with problems, testers are blamed for the defects.
($) Since independent testers have no control over the software development process, they cannot guarantee software quality.

Solutions for Fighting a Lose-Lose Situation:
($) The perception of testing must change.
- Testers are paid to find defects
- Each defect found is one more the customer or user will not find
($) Testers are not to blame for bottlenecks. It is management’s responsibility to have an efficient process.

CHALLENGE – 10: HAVING TO SAY "NO"
Core Issues are :
($) Testers are often the bearer of bad news.
($) Problem: Management doesn’t like to hear bad news.

Solutions for Having to Say "No":
($) Most responsibility is on management to:
- have a quality software development process in place.
- have contingency plan in place in case of problems.
- understand that testing is only an evaluation activity.
- accept the honest facts.
($) Keep the test results objective

SUMMARY - APPLYING THE LESSONS LEARNT:
($) Most testing problems seem to be human in nature.
($) "Quality is everyone’s job, but it’s management’s responsibility." Dr. Deming.
($) There are three key parts of the testing picture: Process, People and Tools.

Keyword: Testing, Challenges, QTP, Quicktest, Automation


Read more...


Friday, August 8, 2008

Smart Identification: A Fantastic Feature of QTP

QTP has a unique feature by the name Smart Object Identification or recognition which is used for identifying the objects smartly, whenever the normal identification fails due to the dynamic changes in the properties of the objects.

Smart Identification is nothing but an algorithm used by the QTP when it is not able to recognize an object. A simple generic example as per the QTP manual would be, A photograph of a 8 year old girl and boy and QTP records identification properties of that girl when she was 8, now when both are 10 years old then QTP would not be able to recognize the girl. But there is something that is still the same, that is there is only one girl in the photograph. So a kind of PI - Programmed intelligence is needed instead of AI.

Object identification is necessary to recognize the GUI objects on the screen. During automatic recording of a script, the object identifier records various objects present on the screen. The smart identification feature of QTP smartly identifies all the objects irrespective of their being developed using same technology or not, e.g. smart identification shall be able to identify the objects in an application although developed in Java but using some of the Microsoft controls as well.

QTP identifies a particular object by comparing the properties of its test object and the run time object. QTP may not be able to recognize any dynamic objects whose properties or even the description may undergo some changes during the run time. Thus its great option of enabling Smart Identification helps us in identifying the objects even if their properties have undergone changes during the run time.

If QTP is not able to detect any object having description matching with that of the recorded object, or in case it detects more than one object having matching description, then QTP ignores the recorded description, and uses the Smart Identification feature to identify the object. Smart Identification mechanism is a bit complex, but flexible. However, if configured logically, Smart Identification definition can help QTP in detecting an object, of course - if present, in-spite of failure of the recorded description.

Understanding the Smart Identification Process: (Ref. Quick Test Professional 9.0 – Help Guide)

If QTP activates the Smart Identification mechanism during a run session (because it was unable to identify an object based on its learned description), it follows the following process to identify the object:

1) QTP "forgets" the learned test object description and creates a new object candidate list containing the objects (within the object's parent object) that match all of the properties defined in the Base Filter Properties list.

2) QTP filters out any object in the object candidate list that does not match the first property listed in the Optional Filter Properties list. The remaining objects become the new object candidate list.

3) QTP evaluates the new object candidate list:

# If the new object candidate list still has more than one object, QTP uses the new (smaller) object candidate list to repeat step 2 for the next optional filter property in the list.

# If the new object candidate list is empty, QTP ignores this optional filter property, returns to the previous object candidate list, and repeats step 2 for the next optional filter property in the list.

# If the object candidate list contains exactly one object, then QTP concludes that it has identified the object and performs the statement containing the object.

4) QTP continues the process described in steps 2 and 3 until it either identifies one object, or runs out of optional filter properties to use.

If, after completing the Smart Identification elimination process, QTP still cannot identify the object, then QTP uses the learned description plus the ordinal identifier to identify the object.

If the combined learned description and ordinal identifier are not sufficient to identify the object, then QTP stops the run session and displays a Run Error message.

How to Analyze Smart Identification Information displayed in the Test Results?
(Ref. Quick Test Professional 9.0 – Help Guide)

If the recorded description does not enable QTP to identify the specified object in a particular step, and a Smart Identification definition is defined (and enabled) for the object, then QTP tries to identify the object using the Smart Identification mechanism. There are two possible scenarios.

Scenario –1: No Object Matches the Recorded Description

If QTP happens to successfully use the Smart Identification feature to recognize an object after no object found to match with the recorded description, the Test Results receive a warning status by providing the information like the following in the results details:

1) An indication that the object (for example, the userName WebEdit object) was not found.

2) An indication that the Smart Identification mechanism successfully found the object, and information about the properties used to find the object. You can use this information to modify the recorded test object description, so that QTP can find the object using the description in future run sessions.

3) Normal result details for the performed step.

The following screenshot displays the results for a test in which Smart Identification was used to identify the userName WebEdit object after one of the recorded description property values have changed.


Scenario –2: Multiple Object Match the Recorded Description

If QTP happens to successfully use the Smart Identification feature to recognize an object after multiple objects have been found to match the recorded description, QTP shows the Smart Identification information in the Test Results window. The step still receives a ‘Passed’ status, because in most of the cases, if Smart Identification was not used, the test object description plus the ordinal identifier could have potentially identified the object. In such a situation, the Test Results shows information like the following in the results details:

1) An indication that the Smart Identification mechanism has successfully found the object, and information about the properties used to find the object.

This information can be used to create a unique object description for the object, so that QTP can find the object using this description in the future run sessions.

2) Normal result details for the performed step.

The following screenshot displays the results for a test in which Smart Identification was used uniquely identifies the Home object after the recorded description resulted in multiple matches.


If the Smart Identification mechanism cannot successfully identify the object, the test fails and a normal failed step is displayed in the Test Results.

Smart Identification Feature of QTP uses two types of properties:


a) Base filter properties: Are the most fundamental properties of a particular test object class. Her we can not change their values without changing the essence of the original object.

b) Optional filter properties: Are other properties, which help us in identifying the objects of a particular class since these are not likely to get changed frequently. These properties can be ignored in case these are not applicable any more.

Smart Identification Example: (Ref. Quick Test Professional 9.0 – Help Guide)

The object identification process for an object is described through the following example in great detail.

Suppose you have the following statement in your test or component:

Browser("Mercury Tours").Page("Mercury Tours").Image("Login").Click 22,17

When you created your test or component, QTP learned the following object description for the Login image:


However, at some point after you created your test or component, a second login button (for logging into the VIP section of the Web site) was added to the page, so the Web designer changed the original Login button's alt tag to: basic login.

The default description for Web Image objects (alt, html tag, image type) works for most images in your site, but it no longer works for the Login image, because that image's alt property no longer matches the learned description. Therefore, when you run your test or component, QTP is unable to identify the Login button based on the learned description. However, QTP succeeds in identifying the Login button using its Smart Identification definition.

The explanation below describes the process that QTP uses to find the Login object using Smart Identification:

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


The learned values are as follows:

Base Filter Properties:
_____________
Property Value
______________
html tag INPUT
______________

Optional Filter Properties:


2) QTP begins the Smart Identification process by identifying the five objects on the Mercury Tours page that match the base filter properties definition (html tag = INPUT and image type = Image Button). QTP considers these to be the object candidates and begins checking the object candidates against the Optional Filter Properties list.

3) QTP checks the alt property of each of the object candidates, but none have the alt value: Login, so QTP ignores this property and moves on to the next one.

4) QTP checks the name property of each of the object candidates, and finds that two of the objects (both the basic and VIP Login buttons) have the name: login. QTP filters out the other three objects from the list, and these two login buttons become the new object candidates.

5) QTP checks the file name property of the two remaining object candidates. Only one of them has the file name login.gif, so QTP correctly concludes that it has found the Login button and clicks it.

How to Disable Smart Identification During the run Session:


Selection of the option “Disable Smart Identification during the run session”, Instructs QTP not to use the Smart Identification mechanism during the run session.

When we select this option, the Enable Smart Identification check boxes in the Object Properties and Object Repository dialog boxes get disabled, although the settings are saved. However when you clear this option, the Enable Smart Identification check boxes return to their previous on or off setting.

When should we use Smart Identification feature of QTP?

As per the suggested best practice we should disable Smart Identification while creating the test cases, so that we are able to recognize the objects which are dynamic or inconsistent in their properties. Moreover once the script gets created, the Smart Identification should be enabled, so that the script does not fail in case of any small change.

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

Keywords: QTP, quicktest, hp, qtp smart identification



Read more...


Frequently Asked Interview Questions on QTP

Following Frequently Asked Questions shall be quite helpful in making a reasonably good foundation for attending an interview on QTP.

Q 1. What are the salient features of QTP?
# It is an automated functional Graphical User Interface testing tool.

# It can easily handle "Non-UI" based Test Cases as well. Like API (Certification testing & Database Testing etc.

# It is meant for automation of user actions on a web or client based computer application.

# It is primarily used for functional regression test automation. # It uses a scripting language based on VBScript

# It has an excellent error handling mechanism.# It has excellent data driven testing features.

Q 2. What is Recovery in QTP?
Exception handling is called Recovery in QTP. Its primary aim is to enable the tests to continue to run in case of an occurrence of an unexpected failure. For example if an application crash occurs and a message dialog appears, QTP can be instructed to attempt to restart the application and continue with the rest of the test cases from there onwards.

Q 3. What is a Checkpoint in QTP?
In QTP, Checkpoint is used to verify the application under test. It can introduce a checkpoint to verify as to whether a particular object, text or a bitmap is present in the automation run.

During a test execution, a checkpoint verifies that the behavior or state of the actual application is consistent with the expected application or not.

Q 4. How many types of checkpoints are available in QTP?
1) Standard Checkpoint - for checking the properties of an object.

2) Table Checkpoint – for checking the properties of a table.

3) Image Checkpoint – for checking the properties of an image.

4) Bitmap Checkpoint – for comparing an area of the application under test pixel-by-pixel with the screen as seen at record-time.

5) Database Checkpoint for automating the back-end testing.

6) Text Checkpoint – for checking that a section of text is found between two other sections of text.

7) Text Area Checkpoint

8) Page Checkpoint
– for checking the properties of a web page.

9) Accessibility Checkpoint – for checking the accessibility of an application.

10) XML Checkpoint

Q 5. How many types of main views of a script are available in QTP?
QTP provides two main views of a script. These are

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

2) Expert View: is most suitable for the advanced users, enabling them to customize the test, like writing user-defined functions. It is meant for displaying and editing of the source code of the test. Except for the root Global action, all other test actions can be edited here. Expert View acts as an IDE for the test. It includes most standard IDE features, such as breakpoints.

Both Keyword View & the Expert View can be selected from tabs available at the bottom of the QTP window.

Q 6. How results are generated in QTP?
At the end of the test, QTP generates a result file for the test cases, which is in the form of a XML tree.

This results file provides detail regarding ‘Pass’ or ‘Fail’ counts, error messages, and all supporting information which allows the user to diagnose the main cause of a failure.

Q 7. What is a Virtual Object in QTP?
Since sometimes complex objects are not recognized & recorded properly by QTP. Hence an experienced user can define that object as a personal virtual object and build a virtual object repository. This way by the concept of Virtual Object, the user can add some sort of support for such complex objects.

If it is possible to extract the desired information from the object, we can do successful record and playback against that object.

Q 8. How can we handle the exceptions with the help of recovery scenario manager in QTP?
With the help of recovery scenario manager we can recover from unexpected events or errors occurring in the testing environment during the test run. The Recovery Scenario Manager presents a structured wizard which helps us in defining the recovery scenario, like detailed definition of the unexpected event and the operations required to recover from the exception during the run session.

Recovery scenario has three steps in handling an exception
a) Triggered Events:
Is an unexpected event like appearance of a Pop-up window, object state, test run error causing application crash or interruption in our running session.

b) Recovery steps: are a series of steps required to be performed to enable QTP to proceed further with the process of test after some trigger event has interrupted the run session.

c) Post Recovery Test-Run: Are a set of instructions designed to be provided to QTP on proceeding further with the test after some recovery operation has been carried out.

Q 9. What is the use of Text output value in QTP?
Text Output values enable us to view the values which are taken by the application during the run time. If parameterized, the values change for every iteration. Hence by creating output values, we can capture the values which are taken by the application during the run time and output them to the data table.

Q 10. What is the Object Spy feature in QTP?
Object Spy enables us to view both the run-time object methods and the test, object methods associated with an object and to view the syntax for a selected method. It is used as a pointer to point towards an object. It displays the object hierarchy tree and the run-time object methods or test object methods associated with the selected object in the Methods tab of the Object Spy dialog box.

Q 11. What is Automation Object Model in QTP?
Like we use QTP for automating the testing of our applications, we can use the automation object model of QTP to automate its own operations as well. With the help of objects, methods, and properties exposed by the automation object model of QTP along with standard programming elements like loops and conditional statements, we can write programs which can configure QTP options and run tests or components instead of performing these operations manually using the QTP interface.

Automation programs are especially useful for performing the same tasks several times or on multiple tests or components, or quickly configuring QTP according to the needs for a particular environment or application.

Most of the dialog boxes in QTP have a corresponding automation object. Most of the options in dialog boxes can be set retrieved using the corresponding object property, and most of the menu commands and other operations have corresponding automation methods.

Q 12. What is a Run-Time Data Table in QTP?
During the run session, QTP creates a Runtime Data Table, which is live version of the Data Table associated with our test. During the run session, QTP displays the run-time data in the Data Table pane so that we can see the changes taking place in the Data Table.

When the run session ends, the Runtime Data Table closes, and the Data Table pane again displays the stored design-time Data Table. Data entered in the run-time Data Table during the run session does not get saved along with the test. The final data from the run-time Data Table gets displayed in the Run-Time Data Table in the Test Results window.

Runtime Data Table is an excel file, which gets stored in the folder of the test created, its name is Default.xls by default.

Q 13. What are the properties used by the Smart Identification mechanism?
The Smart Identification mechanism uses two types of properties:

a) Base filter properties: Are the most fundamental properties of a particular test object class. Her we can not change their values without changing the essence of the original object.

b) Optional filter properties: Are other properties, which help us in identifying the objects of a particular class since these are not likely to get changed frequently. These properties can be ignored in case these are not applicable any more.

Q 14. How many scripting languages can be used in QTP?
Scripts can be written using languages like Visual Basic, XML, JavaScript, Java, HTML

Q 15. What are the Commonly used Excel VBA functions.
Common functions are:
a) Coloring of a cell
b) Auto fit cell
c) Setting navigation from link in one cell to other

Q 16. How QTP identifies various object?
During recording QTP identifies various objects and stores them as test objects. For each test object QTP learns a set of default properties called mandatory properties. Simultaneously QTP looks at rest of the objects to check whether these properties are sufficient to uniquely identify the object or not. During the test run, QTP searches for the run time objects, which match with the test objects which, have been captured by it during recording.

Q 17. What are object repositories in QTP?
When planning and creation of tests is done, we firstly consider how we would like to store the objects in our tests. In QTP, the test objects can be stored in two types of object repositories

a) Shared object repository: It stores test objects in a file that can be accessed by multiple tests (in read-only mode). If someone is new to QTP, he can prefer to use local object repositories. This way he can record and run the tests without creating, choosing, or modifying shared object repositories because all objects are automatically getting saved in a local object repository which can be accessed by its corresponding action.

b) Local object repository: It stores objects in a file that is associated with one specific action, so that only that action can access the stored objects. If someone is familiar with QTP testing, he can find that it is quite efficient to save the objects in a shared object repository. This way, he can use the same shared object repository for multiple actions - if the actions include the same objects. Test object information that applies to many actions is kept in one centralized location. When the objects in the application change, we can update them in one location for all the actions that use this shared object repository.

Q 18. How QTP recognizes objects in object repositories?
Object Repository displays a tree of all the objects in the current component or in the current action or in the entire test , depending on the object repository mode selected by the user. We can view or modify the test object description of any test object in the repository or to add new objects to the repository.

QTP remembers the default property values and determines in which test object class it fits. If it is not found enough it automatically adds assistive properties, one by one to the description until it successfully compiles the unique description. If no assistive properties are available, then it adds a special Ordinal identifier such as object location on the page or in the source code.

Q 19. Is there any built-in function for scripting in QTP?
QTP uses an in-built functionality called "Step Generator" to create scripts while appropriate steps are entered into it. Step Generator utility enables us to add steps by selecting from a range of context-sensitive options and entering the required values.

We can open the Step Generator from the Keyword View or Expert View while recording or editing our test. We can also open the Step Generator from the Active Screen while editing.

Method to open the Step Generator from a function library is as under
a) In the function library, click the location in which you want to insert the new step.

b) Choose Insert > Step Generator, or right-click and choose Step Generator. Alternatively, press F7.

Q 20. How many types of Actions are there in QTP?
QTP uses following three kinds of actions:
a) Non-reusable action - can be called only in the test with which it is stored, and can be called only once.

b) Reusable action - can be called multiple times by the test with which it is stored (the local test) as well as by other tests.

c) External action – is a reusable action which is stored with another test. External actions are read-only in the calling test, but we can choose to use a local, editable copy of the Data Table information for the external action.

By default, all new actions are non-reusable. We can mark every action created by us in the test as reusable or non-reusable.

Q 21. How can we parameterize property values in QTP?
Data Driver feature enables us to quickly parameterize several property values for the test objects, checkpoints, and method arguments containing the same constant value within a given action.

We can choose to replace all occurrences of a selected constant value with a parameter, in the same way that we can use a Find and Replace All operation instead of a step-by-step Find and Replace process. QTP can also show us each occurrence of the constant so that we can decide as to whether to parameterize the value or not.

Method to parameterize a value using the Data Driver is as under:
a) Display the action you want to parameterize.

b) Choose Tools > Data Driver.

Q 22. How can we modify the properties of test object in QTP?
We can modify an object by modifying any one of its property values or by changing the set of properties used to identify the particular object. This can be done for objects in the local object repository with the help of Object Repository window, and for objects in the shared object repository using the Object Repository Manager.

Method to modify an object property is as under:
a) Right-click the step containing the object that changed, and choose Object Properties or choose Edit > Step Properties > Object Properties from the menu bar.

b) The Object Properties dialog box opens and displays the properties QuickTest uses to identify the object.

c) Modify the properties and values as required.

d) Click OK to close the dialog box.

Q 23. How to retrieve the property of an object?
We can retrieve the property of an object by the use of "GetRoProperty".

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

Q 25. Why use Regular Expressions?
Regular expressions are used to increase the flexibility and adaptability of the tests. Regular expressions enable QTP to identify objects and text strings with varying values.

Regular expressions can be used while defining the properties of an object, the methods of an argument, while parameterizing a step, and while creating checkpoints with varying values

Key Word: FAQ, Frequently Asked Question, QTP, Quicktest professional, Interview question


Read more...


Saturday, August 2, 2008

Creating MS Word document inside QTP

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


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

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

Think of this scenario . Lets say I have already opened MS Word document. Now I want to save it into my PC. The script is slightly different from the one shown above.Any idea what should be the code??



Read more...


 
Copyright © 2009 ExpertQTP