Professional Documents
Culture Documents
A) You can
then enter test data into the Data Table, an integrated spreadsheet with the full
functionality of Excel, to manipulate data sets and create multiple test iterations,
without programming, to expand test case coverage. Data can be typed in or
imported from databases, spreadsheets, or text files.
3) Explain about the Test Fusion Report of QTP ?A) Once a tester has run a
test, a TestFusion report displays all aspects of the test run: a high-level results
overview, an expandable Tree View of the test specifying exactly where application
failures occurred, the test data used, application screen shots for every step that
highlight any discrepancies, and detailed explanations of each checkpoint pass and
failure. By combining TestFusion reports with QuickTest Professional, you can share
reports across an entire QA and development team.
6) Explain QTP Testing process ?A) The QuickTest testing process consists of 6
main phases:
Prior to automating there should be a detailed description of the test including the
exact steps to follow, data to be input, and all items to be verified by the test. The
verification information should include both data validations and existence or state
verifications of objects in the application.
As you navigate through your application, QuickTest graphically displays each step
you perform in the form of a collapsible icon-based test tree. A step is any user
action that causes or makes a change in your site, such as clicking a link or image,
or entering data in a form.
1. Enhancing your test
o Inserting checkpoints into your test lets you search for a specific value
of a page, object or text string, which helps you identify whether or
not your application is functioning correctly.
NOTE: Checkpoints can be added to a test as you record it or after the fact via the
Active Screen. It is much easier and faster to add the checkpoints during the
recording process.
1.
o Broadening the scope of your test by replacing fixed values with
parameters lets you check how your application performs the same
operations with multiple sets of data.
o Adding logic and conditional statements to your test enables you to
add sophisticated checks to your test.
If changes were made to the script, you need to debug it to check that it operates
smoothly and without interruption.
You run a test to check the behavior of your application. While running, QuickTest
connects to your application and performs each step in your test.
1. Reporting defects
As you encounter failures in the application when analyzing test results, you will
create defect reports in Defect Reporting Tool.
How QTP recognizes Objects in AUT? A) QuickTest stores the definitions for
application objects in a file called the Object Repository. As you record your test,
QuickTest will add an entry for each item you interact with. Each Object Repository
entry will be identified by a logical name (determined automatically by QuickTest),
and will contain a set of properties (type, name, etc) that uniquely identify each
object. Each line in the QuickTest script will contain a reference to the object that
you interacted with, a call to the appropriate method (set, click, check) and any
parameters for that method (such as the value for a call to the set method). The
references to objects in the script will all be identified by the logical name, rather
than any physical, descriptive properties.
9) What are the types of Object Repositorys in QTP? A) QuickTest has two
types of object repositories for storing object information: shared object repositories
and action object repositories. You can choose which type of object repository you
want to use as the default type for new tests, and you can change the default as
necessary for each new test. The object repository per-action mode is the default
setting. In this mode, QuickTest automatically creates an object repository file for
each action in your test so that you can create and run tests without creating,
choosing, or modifying object repository files. However, if you do modify values in an
action object repository, your changes do not have any effect on other actions.
Therefore, if the same test object exists in more than one action and you modify an
object’s property values in one action, you may need to make the same change in
every action (and any test) containing the object.
10) Explain the check points in QTP?A) . A checkpoint verifies that expected
information is displayed in a Application while the test is running. You can add eight
types of checkpoints to your test for standard web objects using QTP.
11) In how many ways we can add check points to an application using
QTP.A) We can add checkpoints while recording the application or we can add after
recording is completed using Active screen (Note : To perform the second one The
Active screen must be enabled while recording).
12) How does QTP identifes the object in the applicationA) QTP identifies the
object in the application by LogicalName and Class. For example : The Edit box is
identified by Logical Name : PSOPTIONS_BSE_TIME20Class: WebEdit
14) What is Parameterizing Tests?A) When you test your application, you may
want to check how it performs the same operations with multiple sets of data. For
example, suppose you want to check how your application responds to ten separate
sets of data. You could record ten separate tests, each with its own set of data.
Alternatively, you can create a parameterized test that runs ten times: each time the
test runs, it uses a different set of data.
15) What is test object model in QTP ? A) The test object model is a large set of
object types or classes that QuickTest uses to represent the objects in your
application. Each test object class has a list of properties that can uniquely identify
objects of that class and a set ofrelevant methods that QuickTest can record for it.A
test object is an object that QuickTest creates in the test or component to represent
the actual object in your application. QuickTest stores information about the object
that will help it identify and check the object during the run session.A run-time
object is the actual object in your Web site or application onwhich methods are
performed during the run session.When you perform an operation on your
application while recording,QuickTest:➤ identifies the QuickTest test object class that
represents the object on whichyou performed the operation and creates the
appropriate test object➤ reads the current value of the object’s properties in your
application andstores the list of properties and values with the test object➤ chooses
a unique name for the object, generally using the value of one of itsprominent
properties➤ records the operation that you performed on the object using the
appropriate QuickTest test object methodFor example, suppose you click on a Find
button with the following HTMLsource code:<INPUT TYPE=”submit” NAME=”Find”
VALUE=”Find”>QuickTest identifies the object that you clicked as a WebButton test
object.It creates a WebButton object with the name Find, and records the
followingproperties and values for the Find WebButton:It also records that you
performed a Click method on the WebButton.QuickTest displays your step in the
Keyword View like this:QuickTest displays your step in the Expert View like
this:Browser(”Mercury Interactive”).Page(”Mercury
Interactive”).WebButton(”Find”).Click
16) What is Object Spy in QTP?A) Using the Object Spy, you can view the
properties of any object in an openapplication. You use the Object Spy pointer to
point to an object. The ObjectSpy displays the selected object’s hierarchy tree and
its properties and valuesin the Properties tab of the Object Spy dialog box.
1 How many ways we can parameterize data in QTP ?A) There are four
types of parameters:Test, action or component parameters enable you to use values
passedfrom your test or component, or values from other actions in your test. Data
Table parameters enable you to create a data-driven test (or action)that runs several
times using the data you supply. In each repetition, oriteration, QuickTest uses a
different value from the Data Table. Environment variable parameters enable you to
use variable values fromother sources during the run session. These may be values
you supply, orvalues that QuickTest generates for you based on conditions and
optionsyou choose. Random number parameters enable you to insert random
numbers asvalues in your test or component. For example, to check how
yourapplication handles small and large ticket orders, you can have
QuickTestgenerate a random number and insert it in a number of tickets edit field.
22. what does it mean when a check point is in red color? what do u do?
Ans : A red color indicates failure. Here we analyze the the cause for failure whether
it is a Script Issue or Envronment Issue or a Application issue.
24. how do u create new test sets in TD Ans : Login to TD. Click on
“Test Lab” tab. Select the Desired folder under which we need to Create the
Test Set. ( Test Sets can be grouped as per module.) Click on “New Test Set or
Ctrl+N” Icon to create a Test Set.
27. what does it mean when a check point is in red color? what do u do?
Ans : A red color indicates failure. Here we analyze the the cause for failure whether
it is a Script Issue or Envronment Issue or a Application issue.
29. how do u create new test sets in TD Ans : Login to TD. Click on
“Test Lab” tab. Select the Desired folder under which we need to Create the
Test Set. ( Test Sets can be grouped as per module.) Click on “New Test Set or
Ctrl+N” Icon to create a Test Set.
30. How to Import data from a “.xls” file to Data table during
Runtime. Ans : Datatable.Import “…XLS file name…”
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
DataTable.ImportSheet “C:\name.xls” ,1 ,”name”
32. How to get Traceability matrix from TD? 33. How to import a test case
present in “.xls” file to TD under a Test set?
34. How to attach a file to TD? 35. What do you to script when objects are
removed from application? 36. Syntact for how to call one script from
another? and Syntax to call one “Action” in another? Ans: RunAction
ActionName, [IterationMode , IterationRange , Parameters] Here the actions
becomes reusable on making this call to any Action. IterationRange String Not
always required. Indicates the rows for which action iterations will be performed.
Valid only when the IterationMode is rngIterations. Enter the row range (i.e. “1-7″),
or enter rngAll to run iterations on all rows. If the action called by the RunAction
statement includes an ExitAction statement, the RunAction statement can return the
value of the ExitAction’s RetVal argument.
37. How to export QTP results to an “.xls” file? Ans : (a) By default it
creates an “XML” file and displays the results
38. 3 differences between QTP & Winrunner? Ans : (a) QTP is object
bases Scripting ( VBS) where Winrunner is TSL (C based) Scripting. (b) QTP
supports “.NET” application Automation not available in Winrunner (c) QTP
has “Active Screen” support which captures the application, not available in
WR. (d) QTP has “Data Table” to store script values , variables which WR
does not have. (e) Using a “point and click” capability you can easily
interface with objects, their definitions and create checkpoints after having recorded
a script – without having to navigate back to that location in your application like you
have to with WinRunner. This greatly speeds up script development.
42. Analyzing the Checpoint results Standard Checpoint :By adding standard
checkpoints to your tests or components, you can compare the expected values of
object properties to the object’s current values during a run session. If the results
do not match, the checkpoint fails.
43.Table and DB Checkpoints: By adding table checkpoints to your tests or
components, you can check that a specified value is displayed in a cell in a table on
your application. By adding database checkpoints to your tests or components, you
can check the contents of databases accessed by your application. The
results displayed for table and database checkpoints are similar. When you run your
test or component, QuickTest compares the expected results of the checkpoint to the
actual results of the run session. If the results do not match, the checkpoint fails.
You can check that a specified value is displayed in a cell in a table by adding
a table checkpoint to your test or component. For ActiveX tables, you can also check
the properties of the table object. To add a table checkpoint, you use the Checkpoint
Properties dialog box. Table checkpoints are supported for Web and ActiveX
applications, as well as for a variety of external add-in environments. You can
use database checkpoints in your test or component to check databases accessed by
your Web site or application and to detect defects. You define a query on your
database, and then you create a database checkpoint that checks the results of the
query. Database checkpoints are supported for all environments supported
by QuickTest, by default, as well as for a variety of external add-in environments.
There are two ways to define a database query: (a) Use Microsoft
Query. You can install Microsoft Query from the custom installation of Microsoft
Office. (b) Manually define an SQL statement. The Checkpoint timeout
option is available only when creating a table checkpoint. It is not available
when creating a database checkpoint
49. How to handle Run-time errors? (a) On Error Resume Next : causes
execution to continue with the statement immediately following the statement that
caused the run-time error, or with the statement immediately following the most
recent call out of the procedure containing the On Error Resume Next statement.
This allows execution to continue despite a run-time error. You can then build the
error-handling routine inline within the procedure. Using “Err” object msgbox
“Error no: ” & “ ” & Err.Number & “ ” & Err.description & “ ” & Err.Source &
Err.HelpContext
50. How to change the run-time value of a property for an object? Ans
: SetTOProperty changes the property values used to identify an object during the
test run. Only properties that are included in the test object description
can be set
53. Types of properties that Quick Test learns while recording? Ans :
(a) Mandatory (b) Assistive . In addition to recording the mandatory
and assistive properties specified in the Object Identification dialog box, QuickTest
can also record a backup ordinal identifier for each test object. The ordinal identifier
assigns the object a numerical value that indicates its order relative to other objects
with an otherwise identical description (objects that have the same values for all
properties specified in the mandatory and assistive property lists). This ordered value
enables QuickTest to create a unique description when the mandatory and assistive
properties are not sufficient to do so.
54. What is the extension of script and object repository files? Ans :
Object Repository : .tsr , Script : .mts, Excel : Default.xls
55. How to supress warnings from the “Test results page”? Ans :
From the Test results Viewer “Tools > Filters > Warnings”…must be “Unchecked”. 55.
When we try to use test run option “Run from Step”, the browser is not launching
automatically why? Ans : This is default behaviour.
56. Does QTP is “Unicode” compatible? Ans : QTP 6.5 is not but
QTP 8.0 is expected to be Unicode compatabile by end of December 2004.
57. How to “Turn Off” QTP results after running a Script? Ans : Goto
“Tools > Options > Run Tab” and Deselect “View results when run session ends”. But
this supresses only the result window, but a og will be created and can viewed
manulaly which cannot be restricted from getting created.
60. How to verify the Cursor focus of a certain field? Ans : Use “focus”
property of “GetRoProperty” method” 6
You can use the QuickTest Professional Automation Object Model to write programs that
automate your QuickTest operations. The QuickTest Automation Object Model provides
objects, methods, and properties that enable you to control QuickTest from another
application.
The new QuickTest Professional Automation Object Model enables you to automate test
management.
You can now control virtually every QuickTest feature and capability using the objects,
methods and properties included in the QuickTest Professional Automation Object
Model. Automation scripts make it easy to perform any QuickTest operation multiple
times in multiple tests without having to open the QuickTest application, for example,
• You can write a script that modifies the test object description properties in the
Object Identification dialog box and performs an update run on all tests in a
specified file folder.
• After installing a new add-in, an automation script can associate this add-in to all
relevant tests.
• You can write an automation script to run a selected batch of tests. For each test,
you can retrieve the associated add-ins list. Then, if the necessary add-ins are not
already loaded, you can close QuickTest, load the necessary add-ins, reopen
QuickTest, and run the test.
• You can define your settings for a test in QuickTest, then click “Generate Script”
in the Generate tab of the Test Settings dialog box to generate an automation
script based on the current test settings. You can then apply those same settings
automatically to multiple tests using the whole automation script or excerpts from
the generated file.
Example:
You can create and run an automation program from Microsoft Visual Basic that loads
the required add-ins for a test, starts QuickTest in visible or minimized mode, opens the
test, configures settings that correspond to those in the Options, Test Settings, and Record
and Run Settings dialog boxes, runs the test, and saves the test.
Creating automation programs:
The Properties tab of the Test Settings dialog box, the General tab of the Options dialog
box, and the Object Identification dialog box each contain a “Generate Script” button.
Clicking this button generates a automation script file (.vbs) containing the current
settings from the corresponding dialog box.
You can run the generated script as is to open QuickTest with the exact configuration of
the QuickTest application that generated the script, or you can copy and paste selected
lines from the generated files into your own automation script.
Generating an automation script for QuickTest Professional options:
1. Go to Tools -> Options.
2. Select the General tab.
3. Click <Generate Script>.
4. Save the script to the desired location.
5. Click <OK> to close the Options dialog.
Generating an automation script for test settings:
1. Go to Test -> Settings.
2. Select the Properties tab.
3. Click <Generate Script>.
4. Save the script to the desired location.
5. Click <OK> to close the Test Settings dialog.
Generating an automation script for object identification settings:
1. Go to Tools -> Object Identification.
2. Click <Generate Script>.
3. Save the script to the desired location.
4. Click <OK> to close the Object Identification dialog.
The QuickTest Automation Object Model Reference file is a help file that provides
detailed descriptions, syntax information, and examples for the objects, methods, and
properties in the QuickTest Automation Object Model.
When QuickTest Professional 6.5 is installed you can open the QuickTest Automation
Object Model Reference from:
• The QuickTest program folder (Start -> Programs -> QuickTest Professional ->
Documentation -> Automation Object Model Reference)
• The QuickTest Help menu (Help -> QuickTest Automation Object Model
Reference)
browserCnt = browserColl.Count
Next ‘ i
‘************************************************************************************************
******************‘
‘Created On :
Step Results
Pass Step Result: Reporter.ReportEvent 0,”Step-1”, “Message: Logged in
Successfully” Or Reporter.ReportEvent micPass,”Step-
1”, “Message: Logged in Successfully” Fail Step Result: Reporter.ReportEvent
1,”Step-ER-1”, “Error Message: Log in Failed”
Or Reporter.ReportEvent micFail,”Step-ER-1”, “Error Message: Log in Failed”
Repair your test on the fly, this will assists you to adding the steps or uodating the object
proprties in OR on the fly.i.e. if your object properties are changed after a new build, you
just run the Maintenance Run Mode and update your OR according to that on the fly.
Process Guidance :
This is little more than more accessible help files. Maybe this is good for when you are
first learning to record a test, but it doesn’t seem to add much utility.
Flow Pane
All Test Objects and functions in one handy location.Rapid test development with drag &
drop.Object repository now also supports drag & drop
Resources Pane :
All resources associated with the test. You can see all your library file in this pane
Missing Resources Pane
Relative Path Helper
Improved Bitmap Checkpoint
Web Extensibility :
Tabbed browsing :
Tabs identified as separate browsers.Same test compatible with tabbed and non tabbed
browsers.
New Technologies :
1.PowerBuilder
2. Oracle − Forms 10 −Apps 12
New environments :
3.Record on SWT
4. Firefox 3.0
5.Netscape 9
Reference: HP website
Syntax
Set fc = f.SubFolders
If folderName <> “” Then
Set nf =
fc.Add(folderName)
Else
Set nf = fc.Add(“New Folder”)
End If End Sub
Remarks
In the following example, Asc returns the ANSI character code of the first letter of each
string:
‘ Returns 65.
MyNumber = Asc(“a”)
‘ Returns 97.
Remarks
Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example,
Chr(10) returns a linefeed character.
The following example uses the Chr function to return the character associated with the
specified character code:
Dim MyChar
MyChar = Chr(65) ‘ Returns A.
MyChar = Chr(97) ‘ Returns a.
MyChar = Chr(62) ‘ Returns >. MyChar = Chr(37) ‘ Returns %.
Note The ChrB function is used with byte data contained in a string. Instead of
returning a character, which may be one or two bytes, ChrB always returns a single byte.
ChrW is provided for 32-bit platforms that use Unicode characters. Its argument is a
Unicode (wide) character code, thereby avoiding the conversion from ANSI to Unicode.
5)Accessing User-Defined Properties of Web Objects
You can use the attribute/<property name> notation to access native properties of Web
objects and use these properties to identify such objects with programmatic descriptions.
For example, suppose a Web page has the same company logo image in two places on the
page: <IMG src=”logo.gif” mce_src=”logo.gif” LogoID=”122″> <IMG src=”logo.gif”
mce_src=”logo.gif” LogoID=”123″> You could identify the image that you want to click
using a programmatic description by including the user-defined property LogoID in the
description as follows: Browser(”Mercury Tours”).Page(”Find
Flights”).Image(”src:=logo.gif”,”attribute/LogoID:=123″).Click 68, 12 Note: The
attribute/<property name> notation is not supported in Netscape 4.x.
There are several applications available for running automation programs. You can also
run automation programs from command line using Microsoft’s Windows Script Host.
For example, you could use the following command line to run your automation program:
WScript.exe /E:VBSCRIPT myScript.vbs 7) What is the other way of making coments
instead of astrik(‘)
8)How to run commands in command prompt from qtpAns:You can run standard
DOS commands in your QuickTest test using the VBScript Windows Scripting Host
Shell object (WSCript.shell). For example, you can open a DOS command window,
change the path to C:\, and execute the DIR command using the following statements:
Dim oShell Set oShell = CreateObject (”WSCript.shell”) oShell.run “cmd /K CD C:\ &
Dir” Set oShell = Nothing 9) what is optional stepAns:
Description
Syntax
OptionalStep.StatementToMakeOptional
Example
The following example uses the OptionalStep object to make the Paris selection from
the Depart WebList an optional step. OptionalStep.Browser(”Mercury
Tours”).Page(”Find Flights”).WebList(”depart”).Select “Paris” 10)What is the
alternative way to getROpropertyAns) object.QueryValue(property to get)11)How
to get the number of childs in a tree a) Object.children.lengthex:
Browser(”xxx”).Page(”xxx”).Image(”xxx”).Object.children.length11)How to
know that the table has no recordsa) rs.RecordCount 12)What are the types of
parameters available in QTPa) 3 types 1) Action Parameters(Input ,output)These
parameters are restricted to that action only.i.e we can not use them for another
action.Note:Don’t think that the output action parameter can pass values between
action.The only purpouse with output action parameter is to assign the values at run time
rather than design time from the external source(application)Advantage: These
parameters are bound to the action even this action is called from another test.How to
Declare: Using Action property tabSyntax: Input parameter —variable=
parameter(“name”) Output parameter—Parameter(“name”)=value 2)
Test Parameters(Input ,output)These parameters are not restricted to that action i.e we
can use them for any nother action.Note These parameters are not found and unable to
use them in any action is called from another test.Advantage: test parameters can pass
values between action.How to Declare: Using Test Setting- parameters tabSyntax:
Input parameters— variable= TestArgs (“name”)Output parameters– TestArgs
(“name”)=value3)Local ParametersThese are also same as test parameters but we need
to Declare and use them from code not from IDE.Advantage:These parameters still can
used even the actions are called from any testSyntax:Declaration
LocalParameter(“name”)=valueUse: variable= LocalParameter(“name”)13)what are the
different ways to delay the execution steps in QTPAns)3 ways1) object.waitProperty
”propertyName”,”value”,”time in milli sec”This is called conditional wait This will
pauses the execution as long as the specified value of the property exist in the AUT or
specified time out which ever is earlier2) Wait(seconds)This is called unconditional
wait.i.e it will wait for the specified time3) Services.ThinkTime 10Same as wait14) How
to minimize QTP while runninga) Set qtApp = CreateObject(”QuickTest.Application”)
qtApp.WindowState = “Minimized”
Set qtApp = Nothing
Test Scripts
VBS Files
Functions
• Object repository file name must consist of alphabets and should be like
project_Module_Function.tsr.
• If the name of an object or window is ambiguous, then it must be
renamed in the format ObjectType_Label. Eg: Button_Done,
Window_EngagementSummry, Checkbox_Overage, Radio_Awarded etc.
• If more than one word is used, the starting of every word should be in
capitals.
Recovery Manager
If you are getting problem like ,Activex Component can’t create object Then use Set sh
=CreateObject(”WScript.Shell”)
Now… where ever you are having “msgbox” replace it with.. sh.Popup “message
content”, 5, “msg header”, (0+4
the above line will show the message content for 5 seconds(and vanishes after that).
The alert-box’s header will have “header info”. Last parameter(0+4 is actually two
things. 0 -> show OK button in the alertBox 48 -> “!” icon… if you use 64 u will see X
icon instead BTW… since u need the message to be displayed
February 14, 2008 Posted by quicktestprofessional | QTP Tips and Faqs | AOM,
Automation Testing, Excel Automation, QTP, QTP Additional Faqs, QTP AOM, VBS,
VBScripting, word automation | 2 Comments
Usage:
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 onlythrough then test
result. The run-time data table can also be exported using DataTable.Export or
DataTable.ExportSheetHow 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 thespreadsheet and then
access it using the Excel COM Api’s.
code:
• 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.worksheets.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
xlWorkbook.SaveAs “C:\Test.xls”
xlWorkBook.Close
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
set xlApp=Nothing
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
• 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 youare 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
Descriptive Programming
• Recovery scenario gives you an option to take some action for recovering
from a fatal error in the test. The error could range in fromoccasional 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.
• Trigger: Trigger is nothing but the cause for initiating the recovery scenario.
It could be any popup window, any test error, particular stateof 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 arecovery
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, moveto next
step etc….
• 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 yourQTP 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. “Onerror 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 are files containing normal VBScript code. The file can contain
function, sub procedure, classes etc…. You can also use executefilefunction 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 resourcestab.
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. Butwhen we
use Executefile function to load a library file, then the function are available in
the action that called executefile. By associated a library toa 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 objects are basic and generic objects that QTP recognize. Run time
object means the actual object to which a test object maps.
• Yes. You can use SetTOProperty to change the test object properties. It is
recommended that you switch off the Smart Identification for theobject on
which you use SetTOProperty 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 repositoryassociated 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 canhave more than one
output parameters.
• 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 anyautomation
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 onpure 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 only checks for the specific attribute of an object in AUT while
Output value can output those attributes value to a column in datatable.
chk_PassFail = Browser(…).Page(…).WebEdit(…).Check
(Checkpoint(”Check1″))
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”
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
‘Clean up objects
Set oADO_CMD = Nothing
End Function
‘Clean up objects
Set oADO_CMD = Nothing
End Function
Some Web objects will perform actions when certain key commands, such as
ALT+RETURN, are entered. These Web objects do not have a type method associated
with them that can be used to replay these keys. How can the key combination be
replayed?
The following code popup a dialog with a edit box for a password entry when it run
from the QTP
objForm.Controls.Add(objEdit1)
objBtn1.Text=”OK”
p1.Y=Cint(p1.Y)+CInt(objEdit1.Height)+20
objBtn1.Location=p1
objForm.CancelButton=objBtn1
objForm.Controls.Add(objBtn1)
objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog
objRd1.Text=”Radio1″
objGb.Location=p1
p1.Y=30
objRd1.Location=p1
p1.Y=CInt(objRd1.Height)+CInt(objRd1.Top)+10
objRd2.Location=p1
objRd2.Text=”Radio2″
objGb.Text=”Select The Radio Button”
objGb.Controls.Add(objRd1)
objGb.Controls.Add(objRd2)
objBtn2.Text=”OK”
p1.X=60
p1.Y=CInt(objGb.Height)+20
objBtn2.Location=p1
objForm.CancelButton=objBtn2
objForm.Controls.Add(objGb)
objForm.Controls.Add(objBtn2)
objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog
If objRd1.Checked Then
msgbox “You have selected Radio 1″
elseif objRd2.Checked Then
msgbox “You have selected Radio 2″
else
msgbox “No Radio button was selected”
End If
Dim objIE
‘ Create an IE object
Set objIE = CreateObject( “InternetExplorer.Application” )
‘ specify the IE settings
objIE.Navigate “about:blank”
objIE.Document.Title = “Password”
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 300
objIE.Height = 180
‘ Center the dialog window on the screen
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width ) \ 2
objIE.Top = (.Availheight - objIE.Height) \ 2
End With
Descriptive programming
Descriptive programming
Below are some of the situations when Descriptive Programming can be considered
useful:
1. The objects in the application are dynamic in nature and need special handling to
identify the object. The best example would be of clicking a link which changes
according to the user of the application, Ex. “Logout <>”.
2. When object repository is getting huge due to the no. of objects being added. If the size
of Object repository increases too much then it decreases the performance of QTP while
recognizing a object.
3. When you don’t want to use object repository at all. Well the first question would be
why not Object repository? Consider the following scenario which would help
understand why not Object repository Scenario 1: Suppose we have a web application
that has not been developed yet. Now QTP for recording the script and adding the objects
to repository needs the application to be up, that would mean waiting for the application
to be deployed before we can start of with maki! ng QTP scripts. But if we know the
descriptions of the objects that will be created then we can still start off with the script
writing for testing Scenario 2: Suppose an application has 3 navigation buttons on each
and every page. Let the buttons be “Cancel”, “Back” and “Next”. Now recording action
on these buttons would add 3 objects per page in the repository. For a 10 page flow this
would mean 30 objects which could have been represented just by using 3 objects. So
instead of adding these 30 objects to the repository we can just write 3 descriptions for
the object and use it on any page.
4. Modification to a test case is needed but the Object repository for the same is Read
only or in shared mode i.e. changes may affect other scripts as well. 5. When you want to
take action on similar type of object i.e. suppo! se we have 20 textboxes on the page and
there names are in the form txt_1, txt_2, txt_3 and so on. Now adding all 20 the Object
repository would not be a good programming approach. How to use Descriptive
programming? There are two ways in which descriptive programming can be used
1. By creating properties collection object for the description. To use this method you
need first to create an empty description Dim obj_Desc ‘Not necessary to declare
When you use a property name for the first time the property is added to the collection
and when you use it again the property is modified. By default each property that is
defined is a regular expression. Suppose if we have the following
This would mean an object with html tag as INPUT and name starting with txt. Now
actually that “.*” was considered as regular expression. So, if you! want the property
“name” not to be recognized as a regular expression then you need to set the
“regularexpression” property as FALSE
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*” o
bj_Desc(“name”).regularexpression= “txt.*”
This is how of we create a description. Now below is the way we can use it
Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test”
When we say .WebEdit(obj_Desc) we define one more property for our description that
was not earlier defined that is it’s a text box (because QTPs WebEdit boxes map to text
boxes in a web page). If we know that we have more than 1 element with same
description on the page then we must define “index” property for the that description
Consider the HTML code given below
Now the html code has two objects with same description. So distinguish between these 2
objects we will use the “index” property.
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “0”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “1”
We can use the same description for both the objects and still distinguish between both of
them
When I want to refer to the textbox then I! will use the inside a WebEdit object and to
refer to the radio button I will use the description object with the WebRadioGroup object.
Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test” ‘
Refers to the radio button But if we use WebElement object for the description then we
must define the “index” property because for a webelement the current description would
return two objects. Hierarchy of test description: When using programmatic descriptions
from a specific point within a test object hierarchy, you must continue to use
programmatic descriptions from that point onward within the same statement. If you
specify a test object by its object repository name after other objects in the hierarchy have
been described using programmatic descriptions, QuickTest cannot identify the object.
since it uses programmatic descriptions throughout the entire test object hierarchy. You
can also use
Browser(”Index”).Page(Desc1).Link(desc3),
since it uses programmatic descriptions from a certain point in the description (starting
from the Page object description). However, you cannot use
Browser(Desc1).Page(Desc1).Link(”Example1″),
since it uses programmatic descriptions for the Browser and Page objects but then
attempts to use an object repository name for the Link test object (QuickTest tries to
locate the Link object based on its name, but cannot locate it in the repository because the
parent objects were specified using programmatic descriptions).
Getting Child Object: We can use description object to get all the objects on the page
that matches that specific description. Suppose we have to check all the checkboxes
present on a web page. So we will first create an object description for a checkboxe and
then get all the checkboxes from the page
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
The above code will check all the check boxes present on the page.!
To get all the child objects we need to specify an object description i.e. we can’t use the
string arguments that will be discussed later in the 2nd way of using the programming
description. Possible Operation on Description Object Consider the below code for all the
solutions
Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“type”).value = “checkbox”
A: obj_ChkDesc.remove “html tag” ‘would delete the html tag property from the
collection
A: The answer is that it’s not possible. Because whenever we try to access a property
which is not defined its automatically added to the collection. The only way to determine
is to check its value that is use a if statement “
Value=desc.Value R
E = desc.regularexpression
Next
2nd:
Name= obj_ChkDesc(i).Name
Value= obj_ChkDesc(i).Value
RE = obj_ChkDesc(i).regularexpression
Next
2. By giving the description in form of the string arguments. You can describe an object
directly in a statement by specifying property:=value pairs describing the object instead
of specifying an object’s name.
TestObject(”PropertyName1:=PropertyValue1″, “…” ,
“PropertyNameX:=PropertyValueX”)
Each property:=value pair should be separated by commas and quotation marks. Note
that you can enter a variable name as the property value if you want to find an object
based on property values you retrieve during a run session. Consider the HTML Code
given below:
Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txt_Name”,”html
tag:=INPUT”).set “Test”
And to refer to the radio button the statement would be as given below
Browser(“Browser”).Page(“Page”).WebRadioGroup(“Name:=txt_Name”,”html
tag:=INPUT”).set “Test”
If we refer to them as a web element then we will have to distinguish between the 2 using
the index property
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html
tag:=INPUT”,”Index:=0”).set “Test” ‘
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html
tag:=INPUT”,”Index:=1”).set “Test” ‘