Creating User defined Functions:
Open QTP and Application --> type function header along with Unique function name and arguments --> Record
repatable operations in application as function body --> follow above navigation to create more then one functions --
> Save that functions in a file using 3rd party s/w with Extension .vbs( Copy the script, genarated in QTP and paste
in Notepad, MS.Word etc.) --> now goto Resource menu in QTP --> object Repository --> file menu --> Export Local
Objects --> Enter file name with Extension .tsr --> click Save.
Calling User defined Functions:
In QTP --> type Useer defined function name along with argument values --> file menu --> settings --> Resources
tab --> click + icon -->browse the path of the file --> click apply --> click OK --> Resources menu in QTP -->
Associate Repositories --> Click + icon --> browse the path of references file --> select current action --> click OK.
Example:( Creating User defined Function )
Public function login(x,y)
Dialog ("Login").winedit("User name").set x
Dialog ("Login").winedit("Password").setsecure
crypt.encrypt (y)
dialog ("Login").winbutton("OK").Click
End Function
Open QTP and Application --> type function header along with Unique function name and arguments --> Record
repatable operations in application as function body --> follow above navigation to create more then one functions --
> Save that functions in a file using 3rd party s/w with Extension .vbs( Copy the script, genarated in QTP and paste
in Notepad, MS.Word etc.) --> now goto Resource menu in QTP --> object Repository --> file menu --> Export Local
Objects --> Enter file name with Extension .tsr --> click Save.
Calling User defined Functions:
In QTP --> type Useer defined function name along with argument values --> file menu --> settings --> Resources
tab --> click + icon -->browse the path of the file --> click apply --> click OK --> Resources menu in QTP -->
Associate Repositories --> Click + icon --> browse the path of references file --> select current action --> click OK.
Example:( Creating User defined Function )
Public function login(x,y)
Dialog ("Login").winedit("User name").set x
Dialog ("Login").winedit("Password").setsecure
crypt.encrypt (y)
dialog ("Login").winbutton("OK").Click
End Function
User
defined function is nothing but we write our own functions to perform set of
action which contains a login to execute some steps on the application without
making use of inbuilt qtp functions or which contain full logical code by us.
For. Eg:
If you need to do some arithmetical operation and just return the value to some object (textbox) or some thing else. Then write a funcion on ur own and pass the value to do the operation and that's it.
Similary if u want to do some event handling like check, click, select object, do some decission making etc. based on
return value u can make use of functions effectively.
For. Eg:
If you need to do some arithmetical operation and just return the value to some object (textbox) or some thing else. Then write a funcion on ur own and pass the value to do the operation and that's it.
Similary if u want to do some event handling like check, click, select object, do some decission making etc. based on
return value u can make use of functions effectively.
advantages of using functions
in qtp?
creating generic functions?
Generic
functions
'######################################################
'Purpose: This Function is used to delete Cookies
'Prepared By: Nagesh
'######################################################
Function DeleteCookies()
SystemUtil.Run "iexplore.exe"
WebUtil.DeleteCookies
Set objBr=Description.Create
objBr("micclass").value="Browser"
Set objBrCount = Desktop.ChildObjects(objBr)
intBrCount = objBrCount.Count
Hwnd=Browser("creationtime:=" & intBrCount).GetROProperty("hwnd")
SystemUtil.CloseProcessByHwnd(Hwnd)
End Function
'#########################################################
'Purpose: This Function is used to send An Email
'Prepared By: Nagesh
'########################################################
Function SendMail()
Set oConfig = CreateObject("CDO.Configuration")
cdoSendUsingPort=2
sMailServerName="smtp.phx.move.com"
cdoAnonymous=cdoNONE
oConfig.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
oConfig.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServerName
oConfig.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous 'cdoBasic
oConfig.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
oConfig.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'oConfig.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "crp\ NRaoJ "
'oConfig.fields.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "123K!r45"
oConfig.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
oConfig.fields.Update
Set objectMsg = CreateObject("CDO.Message")
objectjMsg.Configuration = oConfig
objectjMsg.to = "Nagesh Jayampu@kkkk.com"
objectjMsg.From = " Nageswara.raoJ@kkkk.com"
objectjMsg.Subject = "Sample mail"
objectjMsg.TextBody =msgsub
doc="File path"
objectjMsg.AddAttachment(doc)
objectjMsg.Send
Set objectjMsg = Nothing
NewMail = True
End Function
'#################################################################
'Purpose: This Function is used to create append excel
'Prepared By: Nagesh
'##################################################################
Function LogFile
Set oExcel=CreateObject("Excel.Application")
oExcel.visible=False
oExcel.workbooks.open("pth of file")
r=1
Do Until len(oExcel.cells(r,1))=0
r=r+1
Loop
oExcel.cells(r,1).value="Step Name"
oExcel.cells(r,2).value="Step Description"
oExcel.cells(r,3).value="Test Results"
oExcel.DisplayAlerts = False
oExcel.Save
oExcel.Quit
Set oExcel = Nothing
End Function
'##############################################################################################
'Purpose: This Function is used to genarate the unique username
'Prepared By: Nagesh.J
'#############################################################################################
Function CreateUniqueUserId()
Dim intTime, intHour, intMin, intSec, strUnique, strUserName
Const strUserNamePrefix = "Nagesh"
Const strUserNameDomain = "@qtp.com"
intTime = Now
strUnique = Hour(intTime)
strUnique = strUnique & Minute(intTime)
strUnique = strUnique & Second(intTime)
strUserName = strUserNamePrefix & strUnique & strUserNameDomain
CreateUniqueUserId = strUserName
End Function
Creating Function libraries in
QTP?
Function Libraries in QTP
If you have repeatable steps in a test or an action then
consider using a user-defined function. User-defined
functions will make your
tests look shorter, easier to maintain, read and design. A user-defined
function can then be called from within an action.
Advantages of Function Library (functions)
1. Time and resources can be saved by implementing and
using user-defined reusable functions.
2. User-defined functions can be stored in a function
library or within an action in the test.
3. User-defined functions can be registered as a method
for a QTP test object.
[It is advisable not to give user-defined functions
same name as built-in functions (refer to the Built-in
functions list in the Step
Generator (Insert > Step Generator, in
theStep Generator dialog
box choose Built-in functions fromLibrary Combo box, it will show all of the Built-in functions in OperationCombo
box))]
If the function is stored in a function library then we
have to associate that
function library to a test so
that the test can call all the public functions listed in that library.
Functions in an associated function library are
accessible:
a) From Step Generator (for tests and function libraries),
b) From the Operation column in the Keyword View, or
c) Can be entered manually in the Expert View.
Functions directly stored in an action in a test can be
called from within that action only making them private from the outside world.
A Private function can also be created in a function
library and this private function can only be called from within the function
library itself in which it is defined.
Functions can be created manually or by using Function
Definition Generator.
It is easy to create
a function library:
1. Open a new function library (File->New->Function
library).
2. Add content to it (your function). Associate it with a
test (File-> Associate Library with Test).
3. You are ready to go.
Many different function libraries can be opened simultaneously
as each opens in its own separate window and you can work on them separately.
If a test is open you can view all the function libraries
associated with it. (Resources->Associated Function Libraries.)
You can save function library either from File->Save or
right click on function library tab on the top of function library and choose
save.
Some important points regarding Function
Libraries.
When we register a function, it applies to an entire test
object class and it's not possible to register a method for a specific test
object.
If we use options like Run from step or Debug from step,
to begin running a test from a point after method registration was performed in
a test step (and not in a function library), QTP does not recognize the method
registration because it occurred earlier to the beginning of the current run
session and this all is due to the reason that QTP clears all method
registrations at the beginning of each run session.
If you want to use Option Explicit statement in Function
Library, you must include it in all the function libraries associated with the
test otherwise QuickTest ignores all the Option Explicit statements in all
function libraries.
Steps using user-defined functions are not displayed in
the test results tree of the Test Results window by default. For function to
appear in the test results tree, you must add a Reporter.ReportEvent statement
to the function code.
If a function library that is referenced by a test is
modified by you or any other user using an external editor, the changes will
take effect only after the test is reopened.
Always make sure that each function has a unique name, if
more than one function with the same name exists in the test script or function
library, QTP will always call the last function because QuickTest searches the
test script for the function prior to searching the function libraries.
Most important of all: If you register a method within a
reusable action, it is strongly recommended to unregister the method at the end
of the action (and then re-register it at the beginning of the next action if
necessary), so that tests calling your action will not be affected by the method
registration.
We can re-register the same method with different
user-defined functions without first unregistering the method. When it is
unregistered it is reset to its original QTP functionality e.g.
RegisterUserFunc "WebEdit", "Set",
"MySet"
RegisterUserFunc "WebEdit", "Set",
"MySet2"
UnRegisterUserFunc "WebEdit", "Set"
After running the UnRegisterUserFunc statement, the Set
method stops using the functionality defined in the MySet2 function, and
returns to the original QuickTest Set functionality, and not to the
functionality defined in the MySet function.
If there are two associated function libraries that define
the same variable in the global scope using a Dim statement or define two
constants with the same name, the second definition causes a syntax error.
Include a Dim statement only in the last function library (since function
libraries are loaded in the reverse order). If you need to use more than one
variable with the same name in the global scope.
Associating Function Libraries in QTP?
Preparing Regression Test Automationsuites in
QTP?
Funtion Decomposition Implementation in QTP?
Functional Decomposition Framework
|
With the use of functional decomposition approach, test scripts are decomposed into their primary tasks such as login, navigation, data processing, logout, reporting etc. Then the scripts can be combined in a hierarchical fashion to build larger tests. The functional components are reusable.
Take an example of deleting email(s) from an Inbox, sent by a particular sender.
[This is just an example. It can be done in many other ways also, like you can combine some steps into one step or you can altogether change the steps according to your requirement.]
Above example will need lot of different input data (e.g. for username & login) and verification data files (e.g. count of emails in Trash etc) for various screens.
For an error a "FALSE" condition is returned to the calling script. The calling script in turn returns “FALSE” to its calling script until the control is returned back to driver script. The Driver can continue with the next Test Case or exit depending on how you have handled it.
Advantages:
It provides division between data and scripts which in turn provides better maintainability and reduces redundancy and repetitions in creating automated test scripts.
It delivers script reusability as individual scripts each identifying a business function can be combined into a higher level script(s) in order to create composite and large scripts.
It makes available single maintenance point for each functionality or screen. If functionality changes, we only need to update a particular "Business Function" script.
Limitations:
Team must have a programming background or expertise in any scripting language.
Multiple data-files may be required for each Test Case. Changes in Test Cases necessitate updates to propagate to several sets of input/verification files for each Test Case.
Also See:
What is Test Automation Framework
5 Generations of Test Automation
Keyword Driven Framework
Choose Your Test Automation Framework
Advanced VB Scripting
Working with Internet
Explorer Application for QTP?
Working with
FileSystemObject in QTP?
FileSystemObject
File
System Operations
File System Object Model:
The File System Object (FSO) model provides an
object-based tool for working with folders and files. It allows us to use the familiar object. method syntax with a rich set
of properties, methods, and events to process folders and files. We can
also employ the traditional Visual Basic statements and
commands.
The FSO model gives our application the ability to create, alter, move,
and delete folders, or to determine if
and where particular folders exist. It also enables us to get information about folders, such as their names and the date they were
created or last modified.
The FSO model makes processing
files much easier as well. When processing files, our primary goal is to store
data in an efficient, easy-to-access format. We need to be able to create
files, insert and change the data, and output (read) the data. Although we can
store data in a database, doing so adds a significant amount of overhead to our application. We may not want to have
such overhead, or our data access requirements may not call for the extra
functionality associated with a full-featured database. In this case, storing our
data in a text file or binary file is the most efficient solution.
The FSO model, contained in the
Scripting type library (Scrrun.dll), supports the creation and manipulation of
text files through the TextStream object; however, the FSO model does not support
binary files. To manipulate binary files, use the FileOpen Function with the
Binary keyword.
FileSystemObject
Main object. Contains methods and properties that allow you to
create, delete, gain information about, and generally manipulate drives, folders,
and files. Many of the methods associated with this object duplicate
those in other FSO objects; they are provided for convenience.
Drive Object
This Object Contains methods and properties that allow you to
gather information about a drive attached to the system, such as its share name and how much room is
available. Note that a "drive" isn't necessarily a hard disk, but can
be a CD-ROM drive, a RAM disk, and so forth. A drive doesn't need to be
physically attached to the system; it can be also be logically connected
through a network.
Folder Object
This Object contains methods and properties that allow you to
create, delete, or move folders. Also allows you to query the system for folder
names, paths, and various other properties.
TextStream Object
This Object allows you to read
and write text files.
Examples:
1) Read Content from a text file and Write in another text file
Dim objFso, myFile1, myFile2, x
Set objFso=createobject("Scripting.Filesystemobject")
Set myFile1=objFso.opentextfile("C:\Documents andSettings\gcr\Desktop\gcreddy.txt",1)
Set myFile2=objFso.createtextfile("C:\Documents andSettings\gcr\Desktop\gcrqtp.txt",1)
Do Until myFile1.AtEndOfStream=True
x=myFile1.Readline
myFile2.Writeline x
Loop
myFile1.Close
myFile2.Close
Set objFso=Nothing
Set objFso=createobject("Scripting.Filesystemobject")
Set myFile1=objFso.opentextfile("C:\Documents andSettings\gcr\Desktop\gcreddy.txt",1)
Set myFile2=objFso.createtextfile("C:\Documents andSettings\gcr\Desktop\gcrqtp.txt",1)
Do Until myFile1.AtEndOfStream=True
x=myFile1.Readline
myFile2.Writeline x
Loop
myFile1.Close
myFile2.Close
Set objFso=Nothing
2) Read Numbers only from a text
file and export to another text file
Dim objFso, objTextStream, myText, x
set objFso=createobject("Scripting.Filesystemobject")
set objTextStream=objFso.opentextfile("C:\Documents andSettings\gcr\Desktop\gcreddy.txt",1)
Set objTextStream2=objFso.opentextfile("C:\Documents andSettings\gcr\Desktop\gcrqtp.txt",2)
objTextStream2.WriteLine "Numbers"
objTextStream2.WriteLine "---------"
Do Until objTextStream.AtEndOfStream
myText=objTextStream.ReadLine
x=split(myText," ")
For i=lbound(x) to ubound(x)
If isnumeric(x(i)) =True Then
objTextStream2.WriteLine x(i)
End if
Next
Loop
objTextStream.Close
objTextStream2.Close
Set objFso=Nothing
3) 'Count Lines in a Text File
Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.filesystemobject")
Set objTextstream=objFso.OpenTextFile("C:\Documents andSettings\gcr\Desktop\abc.txt")
Do While Not objTextstream.AtEndOfStream
LineCount = LineCount + 1
objTextstream.ReadLine
Loop
Msgbox LineCount
objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing
Working with Database Connection Object in
QTP?
QTP & SQL-Server Database
Connection
|
The below QTP script shows a simple example of connecting QTP with SQL Server. For the purpose of this example I have created a simple table with three columns as shown below. The QTP script here is showing the values of second column in the message box one by one. In the below script do not forget to use your own server, username, password, database etc.
Option Explicit Dim con,rs 'The ADO Connection Object is used to create an open connection to a data source.Set con=createobject("adodb.connection") 'The ADO Recordset object is used to hold a set of records from a database table. 'A Recordset object consist of records and columns (fields). When you first open a Recordset, 'the current record pointer will point to the first record and the BOF and EOF properties are False. 'If there are no records, the BOF and EOF property are True. Set rs=createobject("adodb.recordset") 'Below it shows provider, server, username, password, databasecon.open"provider=sqloledb.1;server=server2008;uid=rts_dev1;pwd=password;database=model" 'See all the parameters to recordset "Open" command - http://www.w3schools.com/ado/met_rs_open.asprs.open"select * from person",con Do while not rs.eof 'will show the SECOND column values msgbox rs.fields.Item(1) rs.MoveNext Loop con.Close
Working with RecordSet Object in QTP?
Working
with COM Objects in QTP?
Working
with Word Application Object in QTP?
Working with Outlook Application Object in QTP?
Error handling with Err Object using QTP?
Working with Dictionary Object in QTP?
Dictionary Object in QTP. A complete
guide.
Today we will see a less talked about and not so often used ‘Dictionary Object‘ in QTP. Note that, this is not something very QTP specific. Dictionary object was developed by Microsoft and is part of VB Scripting.
What is
Dictionary Object?
In simple terms, Dictionary object is similar to a typical array. The difference between a dictionary object and an array is that there is a unique key associated with every item of dictionary object. This unique key can help you in calling that item as and whenever required.
What is the
syntax and how can we use dictionary object?
Shown below is a typical script.
Dim dict ‘ Create a variable.
Set dict = CreateObject(“Scripting.Dictionary”)
dict.Add “Company”, “HP” ‘ Adding keys and corresponding items.
dict.Add “Tool”, “QuickTest Pro”
dict.Add “Website”, “LearnQTP”
dict.Add “Country”, “India”
dict is an object of class Scripting.Dictionary. Company-HP, Tool-QuickTest Pro, Website-LearnQTP, Country-India are key-item pairs that were added using Add method on dict object.
Other methods available for dictionary object are Exists Method,Items Method, Keys Method, Remove Method, RemoveAll Method
Using Exists Method to check whether the
key Country exists?
If dict.Exists(“Country”) Then
msg = “Specified key exists.”
Else
msg = “Specified key doesn’t exist.”
End If
Using Items and Keys method to retrieve
ALL items and keys respectively from inside dictionary object.
i = dict.Items ‘ Get the items.
k = dict.Keys ‘ Get the keys.
For x = 0 To dict.Count-1 ‘ Iterate the array.
msgbox i(x) & ” :” & k(x)
Next
Using Remove method to remove Website –
LearnQTP pair from the object.
dict.Remove(“Website”)
dict.RemoveAll ‘ Clear the dictionary.
What are
the places where it can be used?
When you want to share data between different actions in a test, dictionary object can be used. To do this you should create a reserved test object for the Dictionary object. Here is a process to set up a reserved dictionary object. [Source]
- Open Window’s registry by opening a Run window and
enteringregedit.
- Navigate to HKEY_CURRENT_USER\Software\Mercury
Interactive\QuickTest Professional\MicTest\ReservedObjects.
- Create a new key (folder) named GlobalDictionary by
right-clicking on the ReservedObjects key and selecting New -> Key.
- Under the new key, create a String value named ProgID by
right-clicking on GlobalDictionary and selecting New -> String Value.
- Assign “Scripting.Dictionary” to the new ProgID string
value by right-clicking on ProgID and selecting “Modify.”
- If QTP window is already open you need to close and
restart it.
- Now to check whether dictionary object was installed
successfully in registry, simple write GlobalDictionary. (don’t forget the dot) and you
should see a drop-down containing all methods and properties associated
with dictionary object.
Why
dictionary object and why not array only?
As shown in the example above, dictionary object was used with the index (key) being string. In the case of array, the index can be ONLY numeric. Then of course we have some obvious advantages like referencing a value with a meaningful keys etc.
What are
the other places where it can be used?
Alex Dinu has written a good article where he found the usefulness of dictionary object. Microsoft has another nice article on where Dictionary Object can be used.
Working with XMLUtil Object in QTP?
The
below mentioned code is developed for Working With XMLUtil Object using
QTP
'Create a
XMLUtil Object
Set xmlUtilObj = XMLUtil.CreateXML
Set xmlUtilObj = XMLUtil.CreateXML
'Load
a XML file using XMLUtil Object
xmlUtilObj.LoadFile "c:\plant_catalogue.xml"
xmlUtilObj.LoadFile "c:\plant_catalogue.xml"
msgbox
xmlUtilObj.GetRootElement()
' Get the
Child elements of XML File
Set xmlChildList = xmlUtilObj.ChildElementsByPath( "/CATALOG/PLANT/COMMON")
Set xmlChildList = xmlUtilObj.ChildElementsByPath( "/CATALOG/PLANT/COMMON")
' Traverse
through the XML File to read ans display the contents
For i = 1 to xmlChildList.count
For i = 1 to xmlChildList.count
print xmlChildList.item(i).value
Next
'Destroy the
XMLUtil Object
Set xmlUtilObj = Nothing
Set xmlUtilObj = Nothing
Working with QCUtil Object in QTP?
Q: What are the prerequisites to
connect QTP with QC?
A:
- Check Allow other Mercury products to run tests and components present under Tools > Options
> Run in QTP
- If you
are running the tests on the same computer where you have QC client
installed, then you will need:
1. QTP Connectivity
Add-In
2. QTP Add-in
- If you
are running the tests on the different computer than where you have QC
client installed, then you will need:
1. QTP Add-in where QC
client is installed.
2. QTP Add-in and QC
connectivity Add-in where QTP is installed.
- QC
connectivity can be found at QC server URL > ‘Add-Ins Page’ link >
‘QC Connectivity’ link > ‘Download Add-in’
- QTP
Add-in can be found at QC server URL > ‘Add-Ins Page’ link > ‘More
QC Add-ins’ link > Download and install QTP Add-in according to its
version.
Q: How can
we connect QC with QTP usingAutomation
Object Model (AOM)?
A:
Use
TDConnection Object.
Example:
‘ Create the
QuickTest Professional application object.
Set qtqcApp = CreateObject(“QuickTest.Application”)qtqcApp.Launch ‘Launch QTP
qtqcApp.Visible = True ‘Make it visible
Set qtqcApp = CreateObject(“QuickTest.Application”)qtqcApp.Launch ‘Launch QTP
qtqcApp.Visible = True ‘Make it visible
‘Connect
to Quality Center
‘qtqcApp.TDConnection.Connect
<QC Server path>, <Domain name that contains QC project>,
‘<Project Name in QC you want to connect to>, <UserName>, <Password>,
‘ <Whether ‘password is entered in encrypted or normal. Value is True for encrypted and FALSE for normal>
‘<Project Name in QC you want to connect to>, <UserName>, <Password>,
‘ <Whether ‘password is entered in encrypted or normal. Value is True for encrypted and FALSE for normal>
qtqcApp.TDConnection.Connect “http://QualityCenterServer/tdbin”,
“FR”, “Flights”, “learnqtp”, “welcome”, False
“FR”, “Flights”, “learnqtp”, “welcome”, False
Q: How can we automatically connect
QTP with QC on start up?
A: Go
to File > Quality Center Connection. Check the box markedReconnect to server on start-up.
Q: What if QTP tries to connect
with QC automatically but QC login credentials had changed?
A: Change
the following properties from 1 to 0. They are present in mic.ini file under
QTP installation generally found under C:\Program Files\Mercury
Interactive\QuickTest Professional\bin
- LoginAutomatically=0
- ReconnectToDB=0
- ReconnectToServer=0
Q: How can we access Quality Center
Open Test Architecture (OTA) using AOM?
A: Using QCUtil object
(AKA TDUtil for QTP 6.5 and backwards). You can find details of all associated
properties like CurrentRun, TestRun, Current Testset, CurrentTestSetTest,
IsConnected, QCConnection under QTP Help > Quick Test Object Model Reference > Utility Objects> QCUtil Object.
Q: Where can we find all methods and
properties present under TDConnection Object?
A: Refer
QTP Help > QTP Advanced References > QuickTest Automation >
TDConnection Object.
Q: How can we upload QTP scripts to
QC using AOM?
A: Once
connected to Quality Center, open the test using AOM and save it to QC.
Example:
qtqcApp.Open
“C:\Temp\Project\QTPTestScript1″,
True
‘ Get the Test object
Set qtqcTest = qtqcApp.Test
‘ Use the SaveAs method to upload the test to Quality Center
qtqcApp.Test.SaveAs “[QualityCenter] Subject\FolderName\QTPTScript”
‘ Get the Test object
Set qtqcTest = qtqcApp.Test
‘ Use the SaveAs method to upload the test to Quality Center
qtqcApp.Test.SaveAs “[QualityCenter] Subject\FolderName\QTPTScript”
Q: Which version of QTP is
compatible with which version of Quality Center?
A: QC
9.0 integrates with QTP 8.2 SP1, QTP 8.2 SP2, QTP 9.0, QTP 9.1 and QTP 9.2. To
check the compatibility of your QTP version, check out the ReadMe that comes pre-installed with QTP
Q: Can we record Quality Center
operations with QTP?
A: Yes,
only with QC 9.2 and above. Use .NET Add-in.
Q: Can we schedule a test run from
Quality Center?
A: Yes,
use ‘Test Run Scheduler’ utility that comes with QC.
Q: Is there version control in QC with
QTP?
A: Yes,
QTP 10.0 provides you the version control feature under the name of Quality
Center Version Control present under File Menu.
Earlier versions of QTP can work with 3rd party version control tools.
Q: I am a beginner to Quality
Center. Is there any help available?
A: Yes.
Check this site on Quality Center.
It has many step-by-step articles to Learn Quality Center.
Working with DOM Object in QTP?
What is Document object Model?
A
platform- and language-independent standard object model for representing HTML
or XML and related formats.
For
QTP’s sake, I would redefine it to make it simpler. DOM is a method for QTP
engineers to access the source (IE –> View –> Source) of any webpage
direct through VB Scripting.
When can we use DOM?
One of the very important
places you can use it is when a QTP web table checkpoint doesn’t
show you the desired content in a cell. I mean the content in the cell is in a
format that is not supported by the web table checkpoint. Another use can be
when you want to access all the HTML tags used in a webpage. You can get the
names, the innertext, innerHTML property of all these tags. The possibilities
are endless.
How can we use DOM to access the source
page?
We can access the source page
of any webpage using .objectnotation.
Any practical example of using DOM?
I have created a demo web
page to
show you document object model in action. Say you want to find the font color
used for writing HappyHolidays Everyone in
cells of the webtable given on this page.
The algorithm would be:
- Access
the DOM of webtable using .object notation.
- Access
the tagname corresponding to the property you wish to find out. In our
case tagname is “font” and property to be explored is “color”.
- Find
the count of total number of tags and loop it find out the font-color.
The
corresponding VB script would be:
WSH Scripting basics in QTP?
Working with shell in QTP?
Shell Scripting Examples
1) How to display a message with some wait time?
Dim WshShell
Set WshShell = CreateObject(
"WScript.Shell")
WshShell.Popup "G C Reddy", 5, "QTP Training"
WshShell.Popup "G C Reddy", 5, "QTP Training"
2) How to run DOS
commands using windows shell script?
3) How to display
Current User Name?
Dim objNetwork,
objShell
Set objNetwork = CreateObject( "WScript.Network")
Current_User = objNetwork.username
Set objShell = CreateObject( "WScript.Shell")
objShell.Popup Current_User , 5, " User Name "
Set objNetwork = CreateObject( "WScript.Network")
Current_User = objNetwork.username
Set objShell = CreateObject( "WScript.Shell")
objShell.Popup Current_User , 5, " User Name "
4) How to send
keyboard inputs?
set oShell =
CreateObject( "WScript.Shell")
oShell.SendKeys "G C Reddy"
oShell.SendKeys "G C Reddy"
5)
How to get Local Computer Information?
Set objComputer = CreateObject("Shell.LocalMachine")
Wscript.Echo "Computer name: " & objComputer.MachineName
Wscript.Echo "Shutdown allowed: " & objComputer.IsShutdownAllowed
Wscript.Echo "Friendly UI enabled: " & objComputer.IsFriendlyUIEnabled
Wscript.Echo "Guest access mode: " & objComputer.IsGuestAccessMode
Wscript.Echo "Guest account enabled: " & _
objComputer.IsGuestEnabled(0)
Wscript.Echo "Multiple users enabled: " & _
objComputer.IsMultipleUsersEnabled
Wscript.Echo "Offline files enabled: " & _
objComputer.IsOfflineFilesEnabled
Wscript.Echo "Remote connections enabled: " & _
objComputer.IsRemoteConnectionsEnabled
Wscript.Echo "Undock enabled: " & objComputer.IsUndockEnabled
Note: Run the above script as vbscript file(.vbs), It may not work in QTP Test Pane.
----------------------------------------------------------------
We
can run VBScript code file directly.
But WSH also supports an XML file format called .WSF (Windows Script File).
WSF file offers an
XML structure to define script jobs and group jobs into a package
<package>
<job
id="VBScriptJob">
<script language="VBScript">
WScript.Echo "Hello G C Reddy! - VBScriptJob"
</script>
</job>
<job
id="JScriptJob">
<script language="JScript">
WScript.Echo("Hello G C Reddy! - JScriptJob");
</script>
</job>
</package>
Synchronization
Need of Synchronization in QTP?
Synchronization makes available specified amount of time for
an object to process prior to moving on to the next step.
Wait is like forcing the QTP to wait for a
specified amount of time while synchronization is not a 'forced' wait e.g.
whenever a specific page loads QTP moves forward in case of synchronization,
but in case of wait, if the wait is for 10 seconds and a webpage loads in 3
seconds then it still waits for 7 seconds.
Synchronization is there to take
care of the timing problems between QTP and the AUT. Examples where
synchronization can be used:
For a web page to load.
For a button to become enabled or disabled.
For client-server communications to finish.
For a button to become enabled or disabled.
For client-server communications to finish.
Synchronization is possible in many ways:
1)
We can insert a synchronization point for example for a progress bar to reach 100%. QTP will generate a WaitProperty statement in the Expert View in case of synchronization.
We can insert a synchronization point for example for a progress bar to reach 100%. QTP will generate a WaitProperty statement in the Expert View in case of synchronization.
2)
We can use Exist or Wait statements. Exist statements always return a Boolean (0 or 1) value.
We can use Exist or Wait statements. Exist statements always return a Boolean (0 or 1) value.
3)
We can also modify the default amount of time that QTP waits for a Web page to load.
(Browser Navigation Timeout, File(menu)-> Settings-> Web tab)
We can also modify the default amount of time that QTP waits for a Web page to load.
(Browser Navigation Timeout, File(menu)-> Settings-> Web tab)
4)
When working with tests, we can increase the default timeout settings for a test to instruct QuickTest to allow more time for objects to appear.
(Object Synchronization Timeout, File(menu)-> Settings-> Run tab)
When working with tests, we can increase the default timeout settings for a test to instruct QuickTest to allow more time for objects to appear.
(Object Synchronization Timeout, File(menu)-> Settings-> Run tab)
Synchronization is enabled only
during recording.
I will be talking about Sync,
Wait, WaitProperty-->result of synchronization).
Different ways of Synchronizing the tests in QTP?
No comments:
Post a Comment