Sei sulla pagina 1di 29

What are the Run modes in QTP ?

There are 2 run modes in QTP


* Normal : It shows the execution of your QTP script step by step. This works good in case of debugging your script.
* Fast Run : It will not show the execution line by line.
What are the Debugging modes used in QTP ?
Different Debugging modes used in QTP are
* Step Into : To run only the current line of the active test or component.
* Step Out : Runs to the end of the called action or user-defined function, then returns to the calling action and pauses the
run session.
* Step Over : to run only the current step in the active test or component. When the current step calls another action or a
user-defined function,the called action or function is executed entirety, but the called action script is not displayed in the
QuickTest window.
What are the draw backs of QTP ?
Disadvantages are
* QTP takes very long to open huge tests. Also CPU utilization becomes 100% in that case.
* QTP scripts are heavy as it stores all the html files (for active screen) as well.
* Block commenting is not provided till 8.2 version.
What are the extension of file..........
* Per test object repository : filename.mtr (Mercury Test Repository)
* Shared Oject repository : filename.tsr (Test Shared Repository)
* User Defined Libary File : filename .vbs
* Test Batch Runner File : filename .mtb
* QTP Recovery Scenarion File : filename .qrs
* QTP Test Scripts File: filename.mts
What are two types of automation in QTP ?
There are 2 types of automation
* Recording or generating the script and playing back using Repository
* Another one is Descriptive method.
Can we do more than capture / payback in QTP ?
Yes we can do. That is scripting we can write script which is more effective
What is Descriptive programming ?
With out mentioning the description in Object repository, we can directly mention the description in Test script is known as
descriptive programming
What is Object repository ?
Object repository in qtp is like a storage place where it stores the properties of all the objects when we reocrd the script and
later when we execute the script QTP checks that the objects in the application match the objects in the object repository
and executes it, if both the objects matches the test will pass, if it cannot identify the object or there is a mismatch the script
will fail.
Object repository is same as GUI map in winrunner where we have to make the tool capture the properties of object where
as in QTP object repository automatically does that for us.
What are types of Object repository (OR)?
OR are of two types

* Per-action
* Shared
Tell about Per-action repository modes
In this, for each action a seperate object repository file is created. So object1 in Action1 is different from the same object1 in
Action2
This mode is most useful, when the object does not change frequently and a few actions are associated with the test. If the
object changes in the application, then we need to change each of the object repositor.
Tell about Shared object repository modes
In this, common object repository file can be used for muliple actions and multile tests. So Object1 is action1 is same for
Action2, because all the objects are saved at one place. Here if the object changes, then we need to update a single object
repository file.
What are the Advantage & Disadvantge Per-action repository ?
Advantage
* As you record operations on objects in your application, QuickTest automatically stores the information about those objects
in the appropriate action object repository.
* When you save your test, all of the action object repositories are automatically saved with the test as part of each action
within the test. The action object repository is not accessible as a separate file (as is the shared object repository).
Disadvantages
* Modifying the test object properties, values, or names in one object repository does not affect the information stored for the
same test object in another object repository or in other tests - Time Consuming
* If you add objects to one of the split actions, the new objects are added only to the corresponding action object repository.
What are the Advantage & Disadvantge Shared object repository ?
Advantage
* Only one instance of the object in the repository so reduce the repetitions
* one time change to the object properties would bring change in every script using the object
Disadvantge
* Complexity increase as objects of all the action are in the same repository
What is Check points ?
A checkpoint verifies that expected information is displayed in an Application while the test is running. Checkpoints are used
to compare actual and expected results.
How many Check points are there in QTP ?
They are 4 types of checkpoints
* GUI Check point
* Bitmap Checkpoint
* Database Checkpoint
* Test Checkpoint
What is the use of Check points ?
The Check points is useful to get the point in time from where to begin the recovery in case of failure.
Can we change the name of the Check points ?

No, QTP is do not allow to change the name of Check point, because these class names are internally built. But in version 9
(just released) it is possible to cahange not in previous versions
What is Transaction ?
A Transaction is a logical unit of work that comprises one or more SQL statements executed by a single user. or It is a group
of statements between two commits
What is use of Step Generator ?
Step Generator is used to insert a statement(function ro method) of a particular object which is available in the Object
Repository
What is Source Control ?
The practice of tracking changes made to code is called Source Control.
Familiar Source control Tools are CVS, VSS, ClearCase etc
What is Batch testing ?
Group of tests executing sequentially one by one is called Batch Testing. Every test Batch consists of mutiple dependent
test cases. In those batches every end state is base state to next case. Test batch is also known as Test suit or Test belt.
Generally Test engineers are executing test programs as a batches because "End state of one test is base state to another
test".
The result of one Script failure or pass , fails or passes the whole batch test.
What will you when Object is not indentifed by the Obect Repository ?
Use Smart identifcation.
What is Smart identifcation ?
Smart Identification is used by QTP, whenever it is unable to identify any object during run time. While identifying an object,
QTP tries to match the mandatory properties first, if it couldn't find the object, then it adds assistive properties one by one to
identify the object correctly. This operation is done by smart identifier and it is displayed in the results section along with one
warning message. It's generally used to identify Web elements only.
What is Envoirement variable ?
Envoirement variable is variable which is global through the testing.
What is the typesof Envoirement variable ?
There are 3 types of environmental variables
* User-Defined Internal
* User-Defined External
* Built-In
What are Exception in QTP ?
The four exceptions are
* Pop exception
* Object state
* Test run error
* Application crash
Can We use Test Director with QTP ?
Yes. We cant use Test Director 7.2 with QTP 8.2. Because QTP 8.2 supports QC (Quality Center)

We can use QTP 8.2 with Test director 8.0.


What are Action ?
There are 3 types of Actions available in QTP.
* Non-reusable
* Reusable
* External Actions
What is Framework ?
A framework is nothing but a folder structure . It contains all the components that are using in Automation Architecture. Here
components means Object Repository, Library,Logs, Test Data, Script, Result etc
What is Compiled modules ?
In qtp the compiled modules are called library files .
What is Automation Framework ?
Automation frame work is nothing but a set of rules defined for developping and organising the test scripts or
It is a process to develop the automation scripts and reduce maintenance. This framework completely depends on the
application, types of testing and tools that you are using. Its hard to provide generalised framework for all applications:
In how many ways we can Parameterize our test ?
we can parameterize our tests in 4 ways.
* Test or component parameter
* Data Table parameter
* Environmental variable parameter
* Random number parameter
What are tyes of Table ?
Types of tables are
* run time data table
* design time data table
Whats the QTP?

QTP is Mercury Interactive Functional Testing Tool.


Whats the basic concept of QTP?

QTP is based on two concept

Recording
Playback

Which scripting language used by QTP?


QTP using VB scripting.
How many types of recording facility are available in QTP?
QTP provides three types of recording methods

Context Recording (Normal)


Analog Recording

Low Level Recording

How many types of Parameters are available in QTP?


QTP provides three types of Parameter

Method Argument
Data Driven
Dynamic

Whats the QTP testing process?


QTP testing process consist of seven steps

Preparing to recoding
Recording
Enhancing your script
Debugging
Run
Analyze
Report Defects

Whats the Active Screen?


It provides the snapshots of your application as it appeared when you performed a certain steps during recording session.
Whats the Test Pane?
Test Pane contains Tree View and Expert View tabs.
Whats Data Table?
It assists to you about parameterizing the test.
Whats the Test Tree?
It provides graphical representation of your operations which you have performed with your application.
Which all environment QTP supports?
ERP/ CRM
Java/ J2EE
VB, .NET
Multimedia, XML
Web Objects, ActiveX controls
SAP, Oracle, Siebel, PeopleSoft
Web Services, Terminal Emulator
IE, NN, AOL
How can you view the Test Tree?
The Test Tree is displayed through Tree View tab.
Whats the Expert View?
Expert View display the Test Script.
Which keyword used for Nornam Recording?
F3

Which keyword used for run the test script?


F5
Which keyword used for stop the recording?
F4
Which keyword used for Analog Recording?
Ctrl+Shift+F4
Which keyword used for Low Level Recording?
Ctrl+Shift+F3
Which keyword used for switch between Tree View and Expert View?
Ctrl+Tab
Note:
> QTP records each steps you perform and generates a test tree and test script.
> QTP records in normal recording mode.
> If you are creating a test on web object, you can record your test on one browser and run it on another browser.
> Analog Recording and Low Level Recording require more disk sapce than normal recording mode.
Whats the Transaction?
You can measure how long it takes to run a section of your test by defining transactions.
Where you can view the results of the checkpoint?
You can view the results of the checkpoints in the Test Result Window.
Note:
If you want to retrieve the return value of a checkpoint (a boolean value that indicates whether the checkpoint passed or
failed) you must add parentheses around the checkpoint argument in the statement in the Expert View.
Whats the Standard Checkpoint?
Standard Checkpoints checks the property value of an object in your application or web page.
Which environment are supported by Standard Checkpoint?
Standard Checkpoint are supported for all add-in environments.
Whats the Image Checkpoint?
Image Checkpoint check the value of an image in your application or web page.

Which environments are supported by Image Checkpoint?


Image Checkpoint are supported only Web environment.
Whats the Bitmap Checkpoint?
Bitmap Checkpoint checks the bitmap images in your web page or application.
Which enviornment are supported by Bitmap Checkpoints?
Bitmap checkpoints are supported all add-in environment.
Whats the Table Checkpoints?
Table Checkpoint checks the information with in a table.
Which environments are supported by Table Checkpoint?
Table Checkpoints are supported only ActiveX environment.
Whats the Text Checkpoint?
Text Checkpoint checks that a test string is displayed in the appropriate place in your application or on web page.
Which environment are supported by Test Checkpoint?
Text Checkpoint are supported all add-in environments
How is it possible find position of X and Y coordinates on desktop screen?
If you want to find X and Y position of a particular object of the application under test relative to the screen,then using Object
SPY tool ,you just click on that particular object in the screen and find the X and Y position from the Test Object or Runtime
Object property list.
Data Table
Two Types of data tables
Global data sheet: Accessible to all the actions
Local data sheet: Accessible to the associated action only
Usage:
DataTable("Column Name",dtGlobalSheet) for Global data sheet
DataTable("Column Name",dtLocalSheet) for Local data sheet
If we change any thing in the Data Table at Run-Time the data is changed only in the run-time data table. The run-time data
table is accessible only through then test result. The run-time data table can also be exported using DataTable.Export or
DataTable.ExportSheet

How can i save the changes to my DataTable in the test itself?


Well QTP does not allow anything for saving the run time changes to the actual data sheet. The only work around is to share
the spreadsheet and then access it using the Excel COM Api's.
How can i check if a parameter exists in DataTable or not?

The best way would be to use the below code:


code:
-------------------------------------------------------------------------------on error resume nextval=DataTable("ParamName",dtGlobalSheet)if err.number<> 0 then 'Parameter does not existelse
'Parameter existsend if
-------------------------------------------------------------------------------How can i make some rows colored in the data table?
Well you can't do it normally but you can use Excel COM API's do the same. Below code will explain some expects of Excel
COM APIs

SMART Identification
Smart Identification is nothing but an algorithm used by QTP when it is not able to recognize one of the object. A very
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 it kind of PI (Programmed
intelligence) not AI.
When should i use SMART Identification?
Something that people don't think about too much. But the thing is that you should disable SI while creating your test cases.
So that you are able to recognize the objects that are dynamic or inconsistent in their properties. When the script has been
created, the SI should be enabled, so that the script does not fail in case of small changes. But the developer of the script
should always check for the test results to verify if the SI feature was used to identify a object or not. Sometimes SI 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 creationtime.
Descriptive Programming
Descriptive programming is nothing but a technique using which operations can be performed on the AUT object which are
not present in the OR. For more details refer to http://bondofus.tripod.com/QTP/DP_in_QTP.doc (right click and use save
as...)
Recovery Scenarios
What is a Recovery Scenario?
Recovery scenario gives you an option to take some action for recovering from a fatal error in the test. The error could
range in from occasional to typical errors. Occasional error would be like "Out of paper" popup error while printing
something and typical errors would be like "object is disabled" or "object not found". A test case have more then one
scenario associated with it and also have the priority or order in which it should be checked.
What does a Recovery Scenario consists of?
Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be any popup window, any test error,
particular state of an object or any application error.
Action: Action defines what needs to be done if scenario has been triggered. It can consist of a mouse/keyboard event,
close application, call a recovery function defined in library file or restart windows. You can have a series of all the specified
actions.
Post-recovery operation: Basically defined what need to be done after the recovery action has been taken. It could be to
repeat the step, move to next step etc....
When to use a Recovery Scenario and when to us on error resume next?

Recovery scenarios are used when you cannot predict at what step the error can occur or when you know that error won't
occur in your QTP script but could occur in the world outside QTP, again the example would be "out of paper", as this error
is caused by printer device driver. "On error resume next" should be used when you know if an error is expected and dont
want to raise it, you may want to have different actions depending upon the error that occurred. Use err.number &
err.description to get more details about the error.
Library Files or VBScript Files
How do we associate a library file with a test ?
Library files are files containing normal VBScript code. The file can contain function, sub procedure, classes etc.... You can
also use executefile function to include a file at run-time also. To associate a library file with your script go to Test>Settings... and add your library file to resources tab.
When to associate a library file with a test and when to use execute file?
When we associate a library file with the test, then all the functions within that library are available to all the actions present
in the test. But when we use Executefile function to load a library file, then the function are available in the action that called
executefile. By associated a library to a test we share variables across action (global variables basically), using association
also makes it possible to execute code as soon as the script runs because while loading the script on startup QTP executes
all the code on the global scope. We can use executefile in a library file associated with the test to load dynamic files and
they will be available to all the actions in the test.
Test and Run-time Object
What is the difference between Test Objects and Run Time Objects ?
Test objects are basic and generic objects that QTP recognize. Run time object means the actual object to which a test
object maps.
Can i change properties of a test object
Yes. You can use SetTOProperty to change the test object properties. It is recommended that you switch off the Smart
Identification for the object on which you use SetTOProperty function.
Can i change properties of a run time object?
No (but Yes also). You can use GetROProperty("outerText") to get the outerText of a object but there is no function like
SetROProperty to change this property. But you can use WebElement().object.outerText="Something" to change the
property.
Action & Functions
What is the difference between an Action and a function?
Action is a thing specific to QTP while functions are a generic thing which is a feature of VB Scripting. Action can have a
object repository associated with it while a function can't. A function is just lines of code with some/none parameters and a
single return value while an action can have more than one output parameters.
Where to use function or action?
Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. If the
functionality is not about any automation script i.e. a function like getting a string between to specific characters, now this is
something not specific to QTP and can be done on pure VB Script, so this should be done in a function and not an action.
Code specific to QTP can also be put into an function using DP. Decision of using function/action depends on what any one
would be comfortable using in a given situation.
Checkpoint & Output value
What is checkpoint?

Checkpoint is basically a point in the test which validates for truthfulness of a specific things in the AUT. There are different
types of checkpoints depending on the type of data that needs to be tested in the AUT. It can be text, image/bitmap,
attributes, XML etc....

What's the difference between a checkpoint and output value?


Checkpoint only checks for the specific attribute of an object in AUT while Output value can output those attributes value to
a column in data table.

How can i check if a checkpoint passes or not?


Because QTP uses VBScript as its scripting language you have a lot of reference code and sources out there to resolve
issues with. Case in point, if you want to write a function to compare files there are numerous VBScript examples (here and
via Google). If you want to make a call to the Windows System DLL's you can get code snippets from MSDN (VBSCript
language refence and the WSH language reference) and other sources (again via a Google search). If you want to query an
XML file for data there is both MSDN and Google searches that can be done (look for XPath and DOM references). If you
want to get information from the Registry there is a ton of code snippets via Google to help you figure it out.
Even then if you do searches for VB and VBA code snippets you will find them. Just got to convert them to VBScript
(stripped down version of VB & VBA).
Get out of the Tree View / Keyword View. Use the Expert View to develop your scripts with. The only time to really use the
other view is for creating CheckPoints and grabbing object information when you really need to.
Finally, realize that because QTP is VBScript and automation is really development work you will be "programming", and it
does take some effort and work to become good at it. Don't get frustrated with things. And be sure to do a Search first here
and at Google before asking questions that are very very basic and can be answered with a little bit of effort on your part.
Mercury Interactive, WinRunner, and QuickTest Pro
Introduction
This document was created because of the major amount of confusion out there about Mercury's intentions with WinRunner
and QuickTest Pro. There have been a lot of questions about whether scripts would have to be converted, thrown away, or
be reusable. I talked with Mercury over the span of a couple conference calls to get things cleared up. The content and
direction of the this document comes from questions that were offered by QAForums users and questions that I had for my
own knowledge.
This thread should not be replied to, please reference it in other threads. Thanks. I will update this thread as needed, with
information confirmed by Mercury.
From what I have gathered from questions that I've been asked and the statements that I'm hearing, I think *most* of
everyone's fears about this new dynamic can be summed up with what Mercury has been saying all along:
WinRunner and its support are not going away.
Now, the 'how will things be handled in the future' and 'will WR do this and will QTP do that' issues are going to take some
discussion. So, here we go.
"Ok, I got QTP and I've got an app that I'm testing with it. What about my WR stuff? Should I just throw those scripts out?"
No, no, no. Again, I say, "No." QTP is going to (if not already) have the ability to launch WR and have your scripts run.
You're not going to lose all the scripts, etc. that you've built. You've had your WR scripts call other WR scripts before... it's
going to be the same concept. And what's coming in the "near future" is a centralized results set. Where you run your
WR/QTP scripts and they call QTP/WR scripts and your reported results at the end of your test run are all in one place.
So an environment that has been using WR and need a .NET solution would build .NET app scripts in QTP and:
Have your WR scripts call your QTP/.Net tests
Run your QTP/.Net scripts and call your WR scripts as needed.
Mercury understands that with some 10,000 WR customers, there's an inordinate amount of architectures, frameworks,

harnesses... there's no way to come up with one catch-all that will "convert" WR stuff to QTP stuff. So the idea is to reuse
WR stuff via the QTP/WR Integration.
Let me reiterate this again, so there is no confusion:
WINRUNNER AND WINRUNNER SUPPORT ARE NOT GETTING PHASED OUT.
WinRunner will be able to call QuickTest Pro scripts.
QuickTest Pro will be able to call WinRunner scripts.
What one cannot do, the other will.
Licensing
To review, there are two ways to licenses a product: node-locked and floating. Node-locked refers to assigning the app to
one machine; floating allows a license to be shared between machines at any given point in time (2 floating licenses allow
the app to be accessible from an entire lab's worth of PC's but can only have 2 instances running at any given point in time).
Before I continue, I need to state that I cannot tell you exact pricing that MI has set up for the licenses, however, I *can* give
you an idea of what costs more one way than the other.
That said, we've got:WR Node-Locked
WR Floating
QTP Node-Locked
QTP Floating
OFT Node-Locked
OFT Floating
OFT? What's that? That is the new "Optane Functional Testing" license (NOTE: This is a working name for the license, it
may change). It is WR and QTP with the integration. I'll get to that later....
If you're using WR and now need the ability to test in an environment not supported by WR, you have 3 options:
Upgrade WR to QTP. You LOSE WinRunner here, trading it in for QTP. If you don't have a whole lot invested into
WinRunner yet, and you don't need to test in environments exclusive to WR, this might be a viable option for you. If you
have thousands of WinRunner scripts, this probably is not the way to go.
Add QTP. Given that there will be (is) an integration for WR and QTP, adding a couple QTP licenses may be an option.
Move to the Optane Functional Testing license. You can either purchase these outright or upgrade your WR license to an
OFT license. Upgrading a WR license to an OFT license sounds a lot like adding QTP, right? Sure does. But itll costs less.
It's VERY IMPORTANT to consider your node-locked vs. floating schema here. I can't tell you which way to go. You need to
look at your lab environment, and how many licenses of which you really need, but there are some caveats to this:
1 node-locked OFT license allows you to have both WR and QTP installed on ONE MACHINE, and a WR/QTP script can
call a QTP/WR script, on the one license.
1 floating OFT license allows you to have ONE INSTANCE of WR or QTP active, accessible from MULTIPLE MACHINES.
That means if you are in a floating license schema you CANNOT HAVE ONE APP CALL THE OTHER'S SCRIPTS WITH
ONLY ONE FLOATING OFT LICENSE. Those in smaller companies need to take this into consideration.
Big confusion: The original information about Optane Functional Testing licenses did not give the impression that there was
a node locked option. It looked like there was going to be "out of reach" costs to get into WR/QTP. Mercury is going back to
the wording on how the FT licensing schema is being described and make it less confusing.
There will even be a CD install for OFT: It will have both WR and QTP installs on the disk. Expect to see this at the end of
Q2 with the QTP 6.1 release.
WR/QTP Comparisons and "In The Future"
WinRunner 7.6 is scheduled to come out next quarter. WinRunner 8.0 is scheduled to be released at the end of the year.
Beyond that, yes, there will be enhancements made to WinRunner.
WinRunner Both QuickTest Pro

Classic Common Emerging


Custom C/S
PowerBuilder
Forte
Delphi
Centura
Stingray
SmallTalk
ERP/CRM
Baan
PeopleSoft Windows
Siebel 5, 6 GUI Clients
Oracle GUI Forms
Web-Related Environments
IE, Netscape, AOL
JDK, Java Foundation Classes, AWT
Symantec Visual Caf
ActiveX Controls
ERP/CRM
Oracle: Jinitiator, 11i, NCA
JD Edwards Web Client
Custom Client Server
Windows
C++/C
Visual Basic
Operating Systems
Win 98, 2000, NT, ME, XP
Legacy
3270, 5250 Emulators
vt100
ERP/CRM
mySAP
Siebel 7.x
PeopleSoft 8.x.
.NET
WinForms
WebForms
NET controls
Web Services
XML
WSDL
UDDI
Multimedia
RealAudio\Video
Flash
For both WinRunner and QuickTest Professional, Mercury Interactive will support all currently supported environments with
market traction. Examining the environments supported by WinRunner and QuickTest, one can classify them into three
groups: Classic, Common, and Emerging.
Classic: environments supported by only WinRunner. Includes client server environments such as PowerBuilder as well as
older ERP/CRM applications such as Siebel 5 and 6.

Common: environments supported by both WinRunner and QuickTest. Includes IE, Netscape, Windows, Java, Visual Basic,
and terminal emulator (green screen) applications.
Emerging: environments supported by only QuickTest. Includes .Net; newer ERP/CRM environments such as mySAP and
Siebel 7.x; and Macromedia Flash.
Mercury Interactive is committed to providing ongoing support for WinRunner in all Classic and Common environments, and
is committed to ensuring that QuickTest works in all Common and Emerging environments. This means that, for instance,
when a new version of PowerBuilder is released and gains market acceptance, Mercury Interactive will build support for that
new version of PowerBuilder into WinRunner. When a new version of IE is released, Mercury Interactive will build support
for it in both WinRunner and QuickTest. As new versions of .Net, SAP, and Siebel are released, Mercury Interactive will
support those environments in QuickTest. This level of environment support will continue through 2003 and beyond. Mercury
Interactives goal is to ensure that customers can continue to realize the benefits of using our functional testing solutions in
their existing environments as these environments evolve.
QuickTest Pro and...
...TestDirector
The integration of QTP and TD is the same as it is for WR and TD. Test Sets, Test Runs, etc. are able to be created using
QuickTest Pro scripts. Since TD can handle both WR and QTP scripts in a Test Set, both can be in the same run.
...MS Excel
Just like you can create data tables using Microsoft Excel for WR scripts, you can do the same thing for the QTP data driven
scripts that you will create.
...Databases
According to Mercury, database testing via QTP is equal or better than via WR. QTP has:
Enhanced ODBC database import engine.
Provides same DB verification wizard that is in WR
Open extension of VB engine (COM based replay engine: can make direct calls to ODBC db at the object level)
Conclusion
There was a question about when to use one over the other outside of a scripting preference. QTP has reusable actions,
icon based script, active screen, and an integrated data table. It is really up to the individual and how your environment is
going to get set up. Those that are new to automated testing may find QTP easier in the long run. According to Mercury,
many of the lessons learned from WinRunner have been incorporated into QTP.
There are certain environments that WinRunner won't be able to go. This may be a matter of business decision or simply
WinRunner's architecture. The impression that I got from my conversations with Mercury was that they have no intention of
abandoning WinRunner or its users. Mercury is responding to market conditions where there is a greater focus on QuickTest
Pro. So you may have to use a QuickTest Pro solution, but you won't be forced into phasing out WinRunner.
Which way should you go? Again, that depends on your environment. If you have been using WinRunner and now you find
you need QuickTest Pro, there are a number of upgrade paths available. You'll be able to trade in licenses, add, convert,
etc.
How to locate and click on an item in a web table
1. Get the number of columns and rows in the table. This can be done using the RowCount and ColumnCount methods.
2. Loop through the cells in the table.
3. Get the data value from the cell. This can be done using the GetCellData method.
Note:
If the value you are looking for is not a text value, you may need to use an alternate method.
4. If the data is the value you want, use the ChildItem method to get a reference to the object you wish to click.
5. Use the Click method to click on the data item.
Example:
' Get the row count
rowcount = Browser("Browser").Page("Page").WebTable("The Web Directory").RowCount

' Loop through the cells in the table


for r = 1 to rowcount
' Get the column count of row r
colcount = Browser("Browser").Page("Page").WebTable("The Web Directory").ColumnCount(r)
' Loop through columns of row r
for c = 1 to colcount
' Get the value from the cell.
value = Browser("Browser").Page("Page").WebTable("The Web Directory").GetCellData(r, c)
' Check if the value is the one you want.
if value = "Yahoo" then
' The object was found. Click on it.
Browser("Browser").Page("Page").WebTable("The Web Directory").ChildItem(r, c, "Link", 0).Click
' Set a flag to exit the loops.
found = true
' Exit the column loop.
exit for
end if
next
' Check whether item was found.
if found = true then
' Item was found, exit the row loop.
exit for
end if
next
WebTable(description).ChildItem(Row, Column, TO_Class, Index)
Row Row number where the cell is located. The first row in the table is numbered 1.
Column Column number where the cell is located. The first column in the table is numbered 1.
TO_Class Object type.
Index Index of the object of type TO_Class in the cell. It is used to specify the desired element when there is more then one
object of type TO_Class in the cell. The first object has an index of 0.
The third parameter for the ChildItem method is the MicClass of the object you want in the cell. The last parameter is the
index number of the object. If your cells only have one object in them, then use 0 for this parameter.
To determine what the MicClass of the object is, do the following.
1. Go to Tools -> GUI Spy.
2. Click on the hand button.
3. Click on the object in the table cell.
4. The MicClass is listed as the "Class Name" property.
QTP has a global object synchronization timeout. When a step attempts to interact with an object that is not available when
the application is still processing, QTP will wait for either the object to become available or for the object synchronization
timeout to occur.
If one process takes considerably longer than others, the global synchronization timeout may not be long enough for the
process to complete. And in this case, the next step might fail. To give these longer processes enough time to complete, we
add a synchronization point to extend the time QTP will wait before moving on to the next step.
Wait times often occur before an object becomes available for the next step.
Synchronization points instruct QuickTest to pause until an object property achieves a specified value.
The easiest way to add a synchronization point is while recording.
Always add the synchronization point immediately after the step to be synchronized.
From the QTP menu bar, choose INSERT STEP SYNCHRONIZATION POINT.
Step timeout values add to the global timeout values.
When the synchronization timeout is set for a step, this value is added to the global
timeout value.
QTP has a default timeout between test steps of 20000 milliseconds (20 seconds).
May not wait for the full timeout to arrive.

How to find a row in a WebTable using the text of a specifie


Use the GetRowWithCellText method
The GetRowWithCellText method returns the number of the first row found that contains a cell with the specified text.
object.GetRowWithCellText (Text, [Column], [StartFromRow])
object A test object of type WebTable
Text The text string for which to search
Column (Optional) The column number where the cell is located. The value can either be the column name or index. Index
values begin with 1.
StartFromRow (Optional) The number of the row in which to start the search. The first row in the table is numbered 1.
Example 1:
row = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").GetRowWithCellText("Price", 2, 2)
Set Link = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").ChildItem(row, 2, "Link", 0)
Link.Click
Example 2:
' Using the attached sample HTML page
row = Browser("Browser").Page("Page").WebTable("First item").GetRowWithCellText("Second item", 2)
Set chkbx = Browser
How to check if an Excel file is read-only before writing to
Check the ReadOnly Excel property
QuickTest Professional does not have a built-in method that will allow you to check whether the external Excel file is already
open and being edited. However, you can use the Excel Object Model methods and properties to check if the file is readonly.
Refer to "Microsoft Excel 2000 Visual Basic for Applications object model" for a complete listing of Excel methods and
properties that can be used within a QuickTest Professional (QTP) script. You can use these Excel object methods within a
QTP script to create workbooks, create new sheets, input data, etc.
The following example will loop until the file is not read-only (opened by another script). Within the loop, the file is opened
and then the ReadOnly property is retrieved. If the file is read-only, the file is closed and released. The script will wait a short
time (currently 500 milliseconds), then attempt to open the file again.
Example:
Set ExcelObj = CreateObject("Excel.Application")
excelreadonly = True
' Loop while the file is read-only
Do While excelreadonly
Set NewWorkbook = ExcelObj.Workbooks.Open("C:\temp\test.xls")
excelreadonly = NewWorkBook.ReadOnly
If excelreadonly Then ' If readonly
' Close the file and release the obect
ExcelObj.Application.Quit
Set NewWorkbook = Nothing
wait 0, 500
End If
Loop
msgbox "Excel file is not being used..."
msgbox "Doing something...."

' Release the excel objects


ExcelObj.Application.Quit
Set NewWorkbook = Nothing
Set ExcelObj = Nothing
Display bold text in the results:
Format the ReportEvent message text using the HTML <font> tag
Formatting, such as colored text, can be sent to the results using the HTML <font> tag.
Example 1:
' The following line of code sends red and blue text to the results:
Reporter.ReportEvent 0, "<font>Some Event</font>" ,"<font>Blue Text </font>"
Example 2:
' The following line of code sends some bolded text to the results:
Reporter.ReportEvent 0, "Bolded Event" ,"This text is bolded"
Is it possible to get properties from a virtual object
Test object properties for virutal objects can be captured
You can use the GetTOProperty method to retrieve the value of properties that are used in the object repository. There
is no way to retrieve other properties from a virtual object.
VirtualCheckBox.GetTOProperty(Property)
Property Property whose value is retrieved from the object description.
The GetTOProperty function returns the value of a specified property for a test object. The value is taken from the object
repository.
Note:
You can use the GetTOProperty method to retrieve the values of only those properties that are included in the test
object description. Specifying a property that is not included in the test object's description results in a warning status for
the step and the test.
Example:
msgbox Window("Flight Reservation").Window("Open
Order").VirtualCheckBox("CustomerName").GetTOProperty("name")
Inserting a Page object checkpoint
1. While recording, go to Insert -> Checkpoint -> Standard Checkpoint.
2. Using the pointing hand, click on an object on the Web application.
3. In the "Object Selection" dialog, select the Page object.
4. Click <OK>.
5. Select the desired Page Checkpoint Properties.
6. Click <OK>.
Resolving environmental conflicts :
Environmental issues are typically caused by a conflict with a running process or with an unexpected version of a DLL.
One or more of these suggestions, should help you determine what is causing the environmental issue.
1. Talk with your developers or technicians to determine if there are any processes, utilities, or services that are installed
or running on the problem machines but not on the working machines. This could be different virus scanners, network

connection utilities, mouse drivers, etc. It is possible that one of those processes, utilities, or services is causing a
conflict.
2. Check the processes that are running on the problem machine.
Start QuickTest Professional, and perform the actions needed to reproduce the problem.
Open the Task Manager (Start -> Run -> taskmgr.exe).
Note the processes which are running. Try to identify what the processes are for.
To determine if there is a conflict with a running process, end the processes one at a time. You can narrow down the list
somewhat by comparing the processes with those from a working machine. Once you have a list of unknown or different
processes, kill one of the processes and restart QuickTest Professional.
See if the problem reproduces. If the issue continues, repeat the steps with the next process in the Task Manager.
If you find a process that seems to be causing the problem, try killing that process only. Restart or relog into your
machine. Open the Task Manager and kill that process. Start QuickTest Professional and see if you can recreate the
problem. If you are unable to recreate the problem, then you most likely have found the conflicting process. Note, the
issue can be caused by a few processes running together (these processes are usually for the same utility or
application though).
3. Check the version of the DLLs that are in use. You will need to check the DLLs that are directly in use and, possibly,
the DLLs that are required by those DLLs. Use a utility that will give you a list of DLLs being used by an application.
Once you have this list, check the version of these DLLs with the versions from a working machine.
If you find versions that do not match, copy the DLLs from the working machine to the problem machine. Make sure you
back up the DLLs before replacing them. If the versions of those DLLs match, check the versions of the DLLs upon
which those DLLs rely. You can use Microsoft's Dependency Walker utility to determine which DLLs are used by another
DLL.
How to select a WebCheckBox using its adjacent text
Use the custom WebCheckBoxByLabel function (Internet Explorer only)
Note:
This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury
Customer Support. You are responsible for any and all modifications that may be required.
WebCheckBoxByLabel( parent, arg )
parent The Page object containing the checkbox item you want to select
arg The text to locate
This function uses the DOM object, so it will only work on Internet Explorer.
Function WebCheckBoxByLabel( parent, arg )
' Create a description for the WebCheckBox object
Set desc = Description.Create()
desc("type").Value = "checkbox"
desc("html tag").Value = "INPUT"
' Retrieve all WebCheckBox objects on the page
Set cbcol = parent.ChildObjects(desc)
cnt = cbcol.count
' Loop through the WebCheckBox objects
For obj = 0 to cnt-1
' Get the text next to the checkbox
text = cbcol(obj).object.getAdjacentText("afterend")
' Is this the text we're looking for?
If arg = Trim(text) Then
cbcol(obj).Set "ON"

Exit For
End If
Next
End Function
RegisterUserFunc "Page", "WebCheckBoxByLabel", "WebCheckBoxByLabel
Use the VBScript Filter function
Search value in an array:
The Filter function returns a zero-based array containing a subset of a string array based on a specified filter criteria.
Filter(InputStrings, Value[, Include[, Compare]])
InputStrings (Required) One-dimensional array of strings to be searched.
Value (Required) String to search for.
Include (Optional) Boolean value indicating whether to return substrings that include or exclude Value. If Include is True,
Filter returns the subset of the array that contains Value as a substring. If Include is False, Filter returns the subset of
the array that does not contain Value as a substring.
Compare (Optional) Numeric value indicating the kind of string comparison to use. See Settings section for values.
The Compare argument can have the following values:
vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Perform a textual comparison.

If no matches of Value are found within InputStrings, Filter returns an empty array (the Ubound will be -1). An error
occurs if InputStrings is Null or is not a one-dimensional array.
The array returned by the Filter function contains only enough elements to contain the number of matched items.
Example 1:
ReDim myArray(
myArray(0) = "Mon 2"
myArray(1) = "Tues 3"
myArray(2) ="Wed 4"
myArray(3) ="Thurs 5"
myArray(4) ="Fri 6"
myArray(5) ="Sat 7"
myArray(6) ="Sun 8"
myArray(7) = "Mon 9"
myIndex = Filter(myArray, "Mon")
For i = 0 to Ubound(myIndex)
msgbox myIndex(i)
Next
Example 2:
ReDim myArray(5)
myArray(0) = "Mon"
myArray(1) = "Tues"
myArray(2) ="Wed"
myArray(3) ="Thurs"
myArray(4) ="Fri"
myIndex = Filter(myArray, "Sat")
If Ubound(myIndex) < 0 Then

msgbox "Item not found in array"


else
For i = 0 to Ubound(myIndex)
msgbox myIndex(i)
Next
End If
Note:
The Filter function does not return the positions where the elements are found in the input array. If the indexes are
needed, you should loop through the elements in the array one by one.
Example:
For i = 0 to Ubound(myArray)
If instr(myArray(i), "Mon") Then
msgbox i & " " & myArray(i)
End If
How to synchronize on the mouse cursor
When the user's application is busy processing data or performing a task, the mouse cursor changes to indicate the
busy state (the cursor changes to an hourglass).
Is there a way to synchronize on the mouse cursor and make QuickTest Professional wait until the mouse is not busy
before proceeding to the next statement?
-------------------------------------------------------------------------------Solution: Use the custom function IsBusy
Note:
This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury
Customer Support. You are responsible for any and all modifications that may be required.
IsBusy( hwnd )
hwnd The handle of the application window or object
Use the customized IsBusy function located in the attached .zip file. IsBusy checks to see if the mouse cursor is
currently set to the busy icon. If it is, it returns a positive non-zero value, otherwise it returns 0.
1. Unzip the attached file to a temporary location.
2. Copy the CSyncDLL function to your desired location.
3. In the script, declare the IsBusy function.
Example:
extern.Declare micULong,"IsBusy","C:\temp\CSync.dll","IsBusy",micULong
4. Capture the handle of the application window.
Example:
hwnd=Window("MyWindow").GetROProperty("hwnd")
5. Call the IsBusy function as needed.
Example:
' Wait until the cursor is no longer an hourglass
While extern.IsBusy(hwnd)
wait 1
Wend
The IsBusy script demonstrates how to use the function.

The source directory contains the source code for the .DLL as well as the source code for the Visual Basic application
that the IsBusy script tests.
Note:
You can also synchronize on the cursor type (state). For information on how do get the cursor state, please refer to
Problem ID 44583 - How to determine the state of the mouse cursor.
Example:
' Get the handle of the application window or object
hwnd = Window("Notepad").GetROProperty("hwnd")
' Get the cursor type (state)
val = getCursorType (hwnd)
' Loop while the cursor is the specified type
Do While (val = "IDC_IBEAM") ' I-beam cursor
wait 1
val = getCursorType (hwnd)
Loop
The above example waits while the mouse cursor is in the I-Beam cursor state.
Use the custom FSBrowserRestore and FSBrowserMinimize functions
Note:
These functions are not part of QuickTest Professional. They are not guaranteed to work and are not supported by
Mercury Customer Support. You are responsible for any and all modifications that may be required.
To restore a full screen browser window to its original size, use the custom FSBrowserRestore function.
FSBrowserRestore(obj)
obj The Browser object
'@Description Restores a full screen browser to original size
'@Documentation Restore the full screen browser to its original size
Function FSBrowserRestore(obj)
' Press the Restore toolbar button.
obj.WinToolbar("nativeclass:=ToolbarWindow32", "window id:=0").Press "Restore"
End Function
RegisterUserFunc "Browser", "FSBrowserRestore", "FSBrowserRestore"
Example:
Browser("Yahoo!").FullScreen
wait 1
Browser("Yahoo!").FSBrowserRestore
To minimize a full screen browser, use the custom FSBrowserMinimize function.
FSBrowserMinimize(obj)
obj The Browser object
'@Description Minimizes a full screen browser
'@Documentation Minimize the full screen browser
Function FSBrowserMinimize(obj)
' Press the Minimize toolbar button.

obj.WinToolbar("nativeclass:=ToolbarWindow32", "window id:=0").Press "Minimize"


End Function
RegisterUserFunc "Browser", "FSBrowserMinimize", "FSBrowserMinimize"
Note:
To restore a minimized full screen browser, you need to use the Window object Restore method. The
FSBrowserRestore method will not work.
Example:
Browser("Yahoo!").FullScreen
Browser("Yahoo!").FSBrowserMinimize
' Restore the minimized browser
Window("Microsoft Internet Explorer").Restore
To record the restore method:
1. Start recording.
2. Go to Test -> Low-Level Recording. This step starts Low-Level recording.
3. Click on the browser in the system task bar.
4. Go to Test -> Low-Level Recording. This step stops Low-Level recording. Alternatively, you can stop recording
completely
Use the custom FSBrowserRestore and FSBrowserMinimize functions
Note:
These functions are not part of QuickTest Professional. They are not guaranteed to work and are not supported by
Mercury Customer Support. You are responsible for any and all modifications that may be required.
To restore a full screen browser window to its original size, use the custom FSBrowserRestore function.
FSBrowserRestore(obj)
obj The Browser object
'@Description Restores a full screen browser to original size
'@Documentation Restore the full screen browser to its original size
Function FSBrowserRestore(obj)
' Press the Restore toolbar button.
obj.WinToolbar("nativeclass:=ToolbarWindow32", "window id:=0").Press "Restore"
End Function
RegisterUserFunc "Browser", "FSBrowserRestore", "FSBrowserRestore"
Example:
Browser("Yahoo!").FullScreen
wait 1
Browser("Yahoo!").FSBrowserRestore
To minimize a full screen browser, use the custom FSBrowserMinimize function.
FSBrowserMinimize(obj)
obj The Browser object
'@Description Minimizes a full screen browser
'@Documentation Minimize the full screen browser
Function FSBrowserMinimize(obj)
' Press the Minimize toolbar button.
obj.WinToolbar("nativeclass:=ToolbarWindow32", "window id:=0").Press "Minimize"

End Function
RegisterUserFunc "Browser", "FSBrowserMinimize", "FSBrowserMinimize"
Note:
To restore a minimized full screen browser, you need to use the Window object Restore method. The
FSBrowserRestore method will not work.
Example:
Browser("Yahoo!").FullScreen
Browser("Yahoo!").FSBrowserMinimize
' Restore the minimized browser
Window("Microsoft Internet Explorer").Restore
To record the restore method:
1. Start recording.
2. Go to Test -> Low-Level Recording. This step starts Low-Level recording.
3. Click on the browser in the system task bar.
4. Go to Test -> Low-Level Recording. This step stops Low-Level recording. Alternatively, you can stop recording
completely.
Posted: Sun Oct 15, 2006 3:40 am

Post subject: How to single step through a script

Use the Debug menu "Step Into" and "Step Over" options (F11 and F10)
Single stepping through a script can be done with the "Step Over" and "Step Into" actions under the Debug menu. You can
also use the F11 hotkey for Step Into, or the F10 hotkey for Step Over.
The Step Into option runs the current line of the script. If the current line calls a method, the method is displayed in the view
but is not performed. The Step Over option runs the current line of the script. When the current line calls a method, the
method is performed in its entirety, but is not displayed in the view.
To launch and single step through a script:
1. Open the desired test.
2. Press F11 to start the script run.
3. Select the test results location, and click <OK>.
4. Press F11 twice to engage the test flow.
5. Press F11 or F10 to enter the first action.
6. Press F11 or F10 repeatedly to single step the script.
To single step through a specified section of a script:
1. Open the desired script.
2. Place a breakpoint on the step you wish to start from.
3. Right-click on that step, and select "Run from step."
4. Select the test results location, and click <OK>.
5. Press F11 or F10 to step through the script as needed.
Example:
msgbox "one"
msgbox "two"
msgbox "three"
msgbox "four"
msgbox "five"
msgbox "six"
In the above script, you want to execute (one at a time) lines 3, 4, and 5. Place a breakpoint on line 3 (this is the msgbox
"three" line). Then right-click on line 3 and select Run from Step. The Run dialog will appear. Select the location for the test
results. This will either be a "new run results folder" or the "temporary run results folder". Click <OK> to close the dialog. The
yellow execution arrow will appear next to the third line. At this point, because there is a breakpoint on line 3, QuickTest
Professional will be in run mode, but will not be executing the test. Press F11 or F10. A message box will appear with the
text "three". Close the message box. The execution arrow will move down to line 4. Press F11 or F10 again. A message box

with the text "four" will appear. Close the message box. The execution arrow will move to line 5. Press F11 or F10 again. A
message box with the text "five" will appear. Close the message box. Since there are additional lines still in the script,
QuickTest Professional will still be in run mode (though it will be idle). Click the Stop button to end test execution.

Posted: Sun Oct 15, 2006 3:40 am

Post subject: How to single step through a script

Use the Debug menu "Step Into" and "Step Over" options (F11 and F10)
Single stepping through a script can be done with the "Step Over" and "Step Into" actions under the Debug menu. You can
also use the F11 hotkey for Step Into, or the F10 hotkey for Step Over.
The Step Into option runs the current line of the script. If the current line calls a method, the method is displayed in the view
but is not performed. The Step Over option runs the current line of the script. When the current line calls a method, the
method is performed in its entirety, but is not displayed in the view.
To launch and single step through a script:
1. Open the desired test.
2. Press F11 to start the script run.
3. Select the test results location, and click <OK>.
4. Press F11 twice to engage the test flow.
5. Press F11 or F10 to enter the first action.
6. Press F11 or F10 repeatedly to single step the script.
To single step through a specified section of a script:
1. Open the desired script.
2. Place a breakpoint on the step you wish to start from.
3. Right-click on that step, and select "Run from step."
4. Select the test results location, and click <OK>.
5. Press F11 or F10 to step through the script as needed.
Example:
msgbox "one"
msgbox "two"
msgbox "three"
msgbox "four"
msgbox "five"
msgbox "six"
In the above script, you want to execute (one at a time) lines 3, 4, and 5. Place a breakpoint on line 3 (this is the msgbox
"three" line). Then right-click on line 3 and select Run from Step. The Run dialog will appear. Select the location for the test
results. This will either be a "new run results folder" or the "temporary run results folder". Click <OK> to close the dialog. The
yellow execution arrow will appear next to the third line. At this point, because there is a breakpoint on line 3, QuickTest
Professional will be in run mode, but will not be executing the test. Press F11 or F10. A message box will appear with the
text "three". Close the message box. The execution arrow will move down to line 4. Press F11 or F10 again. A message box
with the text "four" will appear. Close the message box. The execution arrow will move to line 5. Press F11 or F10 again. A
message box with the text "five" will appear. Close the message box. Since there are additional lines still in the script,
QuickTest Professional will still be in run mode (though it will be idle). Click the Stop button to end test execution.
Are checkpoints available in Business Components
-------------------------------------------------------------------------------Solution: Single property checks are available with Business Components
Multiple property checkpoints are not available to Keyword-driven Business Components. Checkpoints are not
recommended for use within Scripted Components. To check object properties in a component, use a single property
check.

The Business Components have some built-in methods you can use to verify the values or other properties of the
various controls in your application.
To verify whether a specified object is enabled:
VerifyEnable(obj)
obj The test object
To verify the value of a specified object:
VerifyValue(obj, ExpectedValue)
obj The test object
ExpectedValue The expected value to be compared and verified during the test run. The format of the expected value
depends on the type of test object.
To verify the value of a specified property:
VerifyProperty(obj, PropertyName, ExpectedValue)
obj The test object
PropertyName The property name to check
ExpectedValue The expected value of the property
Note:
QuickTest Professional passes the test objects to the functions automatically, so you do not need to pass a value to the
first parameter when calling these functions.
When working with Business Process Testing 8.2.1 via TestDirector for Quality Center, there is no default list of available
object properties from which a single property checkpoint can be created. The property must be entered manually. An
enhancement request for a default list of properties has been submitted.
You can use the QuickTest Professional Object Spy or refer to the QuickTest Professional Object Model Reference
description for a list of properties you can reference. For example, if your control is a standard windows button, refer to
the Object Model Reference -> Standard Windows -> WinButton Object -> Properties -> WinButton Identification
Properties.
Each of the functions will return True if the expected condition is met.
Parameterizing components
1. Create the component.
2. Select the Parameters tab. Add the input/output parameters as needed.
Click <New>.
Enter a descriptive name in the Parameter name, and click <OK>. To make the input and output parameters easier to
identify, you may want to add "_in" or "_out" to the end of the parameter name. The new parameter will appear in the
relevant list.
Select the Value Type for the parameter.
For input parameters, enter the default value that should be used. The default value must correspond to the selected
value type.
In the Description column, add a description for the parameter.
3. Select the Automation tab. (If you are using BPT 8.x select the Steps tab.)
4. In the Keyword View, select the step to be parameterized.
5. Click on the "Configure the value" button in the Value cell. The "Value Configuration Options" dialog will appear.
6. Select the "Parameter" radio button and "Component parameter" in the combobox.
7. Select the desired component parameter in the Name combobox.
8. Repeat steps 4 through 7 for each input parameter.
9. Select the step that will generate the output parameter.
10. Click on the "Specify parameter for output" button in the Output cell. The "Output Options" dialog will appear.
11. Select "Component parameter" in the Output Types combobox.
12. Select the desired component output parameter in the Name combobox.
13. Repeat steps 9 through 12 for each output parameter.
14. If the component should be iterated, make sure the "Allow Iterations" option on the Details tab is set to Y.

Data Table
Two Types of data tables

Global data sheet: Accessible to all the actions


Local data sheet: Accessible to the associated action only

Usage:

DataTable("Column Name",dtGlobalSheet) for Global data sheet


DataTable("Column Name",dtLocalSheet) for Local data sheet

If we change any thing in the Data Table at Run-Time the data is changed only in the run-time data table. The run-time data
table is accessible only through then test result. The run-time data table can also be exported using DataTable.Export or
DataTable.ExportSheet
How can i save the changes to my DataTable in the test itself?

Well QTP does not allow anything for saving the run time changes to the actual data sheet. The only work around is
to share the
spreadsheet and then access it using the Excel COM Api's.

How can i check if a parameter exists in DataTable or not?

The best way would be to use the below code:


code:

on error resume next


val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if

How can i make some rows colored in the data table?

Well you can't do it normally but you can use Excel COM API's do the same. Below code will explain some expects
of Excel COM APIs
code:

Set xlApp=Createobject("Excel.Application")
set xlWorkBook=xlApp.workbooks.add
set xlWorkSheet=xlWorkbook.worksheet.add

xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the color of the cells


xlWorkSheet.Range("A1:A10").value="text" 'Will set values of all 10 rows to "text"
xlWorkSheet.Cells(1,1).value="Text" 'Will set the value of first row and first col
rowsCount=xlWorkSheet.Evaluate("COUNTA(A:A)") 'Will count the # of rows which have non blank value in the
column A
colsCount=xlWorkSheet.Evaluate("COUNTA(1:1)") 'Will count the # of non blank columns in 1st row
xlWorkbook.SaveAs "C:\Test.xls"
xlWorkBook.Close
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
set xlApp=Nothing

SMART Identification
Smart Identification is nothing but an algorithm used by QTP when it is not able to recognize one of the object. A very
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 it kind of PI (Programmed
intelligence) not AI.
When should i use SMART Identification?

Something that people don't think about too much. But the thing is that you should disable SI while creating your
test cases. So that you are able to recognize the objects that are dynamic or inconsistent in their properties. When
the script has been created, the SI should be enabled, so that the script does not fail in case of small changes. But
the developer of the script should always check for the test results to verify if the SI feature was used to identify a
object or not. Sometimes SI 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 creationtime.

Descriptive Programming

Descriptive programming is nothing but a technique using which operations can be performed on the AUT object
which are not present in the OR. For more details refer to http://bondofus.tripod.com/QTP/DP_in_QTP.doc (right
click and use save as...)

Recovery Scenarios
What is a Recovery Scenario?

Recovery scenario gives you an option to take some action for recovering from a fatal error in the test. The error
could range in from occasional to typical errors. Occasional error would be like "Out of paper" popup error while
printing something and typical errors would be like "object is disabled" or "object not found". A test case have more
then one scenario associated with it and also have the priority or order in which it should be checked.

What does a Recovery Scenario consists of?

Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be any popup window, any test
error, particular state of an object or any application error.
Action: Action defines what needs to be done if scenario has been triggered. It can consist of a mouse/keyboard
event, close application, call a recovery function defined in library file or restart windows. You can have a series of
all the specified actions.
Post-recovery operation: Basically defined what need to be done after the recovery action has been taken. It could
be to repeat the step, move to next step etc....

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

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

Library Files or VBScript Files


How do we associate a library file with a test ?

Library files are files containing normal VBScript code. The file can contain function, sub procedure, classes etc....
You can also use execute file function to include a file at run-time also. To associate a library file with your script go
to Test->Settings... and add your library file to resources tab.

When to associate a library file with a test and when to use execute file?

When we associate a library file with the test, then all the functions within that library are available to all the actions
present in the test. But when we use Executefile function to load a library file, then the function are available in the
action that called executefile. By associated a library to a test we share variables across action (global variables
basically), using association also makes it possible to execute code as soon as the script runs because while
loading the script on startup QTP executes all the code on the global scope. We can use executefile in a library file
associated with the test to load dynamic files and they will be available to all the actions in the test.

Add-ins
Test and Run-time Object
What is the difference between Test Objects and Run Time Objects ?

Test objects are basic and generic objects that QTP recognize. Run time object means the actual object to which a
test object maps.

Can i change properties of a test object

Yes. You can use SetTOProperty to change the test object properties. It is recommended that you switch off the
Smart Identification for the object on which you use SetTOProperty function.

Can i change properties of a run time object?

No (but Yes also). You can use GetROProperty("outerText") to get the outerText of a object but there is no function
like SetROProperty to change this property. But you can use WebElement().object.outerText="Something" to
change the property.

Action & Functions


What is the difference between an Action and a function?

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

Where to use function or action?

Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. If the
functionality is not about any automation script i.e. a function like getting a string between to specific characters,
now this is something not specific to QTP and can be done on pure VB Script, so this should be done in a function

and not an action. Code specific to QTP can also be put into an function using DP. Decision of using function/action
depends on what any one would be comfortable using in a given situation.
Checkpoint & Output value
What is checkpoint?

Checkpoint is basically a point in the test which validates for truthfulness of a specific things in the AUT. There are
different types of checkpoints depending on the type of data that needs to be tested in the AUT. It can be text,
image/bitmap, attributes, XML etc....

What's the difference between a checkpoint and output value?

Checkpoint only checks for the specific attribute of an object in AUT while Output value can output those attributes
value to a column in data table.

How can i check if a checkpoint passes or not?


code:

chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))


if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if

My test fails due to checkpoint failing, Can i validate a checkpoint without my test failing due to checpoint failure?
code:

Reporter.Filter = rfDisableAll 'Disables all the reporting stuff


chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
Reporter.Filter = rfEnableAll 'Enable all the reporting stuff
if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if

Environment
How can i import environment from a file on disk

Environment.LoadFromFile "C:\Env.xml"

How can i check if a environment variable exist or not?

When we use Environment("Param1").value then QTP expects the environment variable to be already defined. But
when we use Environment.value("Param1") then QTP will create a new internal environment variable if it does not
exists already. So to be sure that variable exist in the environment try using Environment("Param1").value.

How to connect to a database?


code:

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DRIVER={Microsoft ODBC for Oracle};UID=<UID>;PWD=<PWD>"
objRecordset.CursorLocation = adUseClient
objRecordset.CursorType = adopenstatic
objRecordset.LockType = adlockoptimistic
ObjRecordset.Source="select field1,field2 from testTable"
ObjRecordset.ActiveConnection=ObjConnection
ObjRecordset.Open 'This will execute your Query
If ObjRecordset.recordcount>0 then
Field1 = ObjRecordset("Field1").Value
Field2 = ObjRecordset("Field2").Value
End if
How to create dialog box with option in QTP ?
res = msgbox ("Is it your first run (Yes/No) ? ", vbYesNo,"First run Indicator")
If res = 6 Then ' 6 = Yes ; 7 = No
some code ....
end if

Dim Sample
Sample = InputBox ("Checking", 65, "InputBox Sample")

Potrebbero piacerti anche