Monday, November 3, 2014
Sunday, November 2, 2014
Parametrization in QTP
Test can be enhanced by parameterizing the values that it uses. A parameter is a variable that is assigned a value from an external data source or generator.
Following values can be parametrized:
Values can be parameterized using:
Following are the parameter types used for parametrization
Following values can be parametrized:
- Checkpoints
- Object properties for a selected step
- Operation arguments defined for a selected step.
- One or more properties of an object stored in the local object repository.
- Test/action parameters
- DataTable parameters
- Environment Variable parameters
- Using Random number parameters
Following are the parameter types used for parametrization
Test/action parameters: Test parameters enable to use values passed from the test. Action parameters enable to pass values from other actions in the test.
Data Table parameters: Enables to create a data-driven test (or action) that runs several times using the data supplied. In each repetition, or iteration, QTP uses a different value from the data table
Environment variable parameters: Enables to use variable values from other sources during the run session. These may be values supplied, or values that QTP generates based on conditions and options
Random number parameters. Enables to insert random numbers as values in the test
Saturday, November 1, 2014
Visual Relation Identifiers
A visual relation identifier (VRI) is a set of definitions that enable you to identify the object in the application according its neighbouring objects in the application.
You can select neighbouring objects that will maintain the same
relative location to your object, even if the user interface design changes.
This helps UFT to identify similar objects much as a human tester would, and helps in creating more stable object repositories that can withstand predictable changes to the application’s user interface.
You define visual relations in the Visual Relation Identifier dialog box, which is accessible from the local or shared object repository, and from the Object Properties dialog box
Creating a visual relation identifier for an object
1. To create a visual relation identifier for an object, go to object repository window and select the object for which visual relation identifier needs to be created.
2. In the Visual Relation Identifier Settings row, click in the Value cell.
3. Click the Browse button in the text box.
4. Define relation of object relative to other objects.
Some Important points to remember about visual relation identifier are:
1. Visual relation identifier are taken into consideration if object is not uniquely identified using the object identification Properties.
2. Visual relation identifier have preference on smart identification for object recognition.
3. Ordinal Identifiers are ignored if visual relation identifier is defined for an object.
4. Visual Relation identifier are created for an object based on relative position of other stable object, i.e. objects existing left, right, top , bottom relative to object to be identified can be used for relative identifier.
5. Relative Objects should exist in object repository before a relation can be created.
6. Relative visual identifier cannot be used in Descriptive Programming as objects should exist in OR.
7. This is used to filter in case of multiple objects in the application matching object definition but are placed relative to other object in application.
8. If no objects in the application match the test object’s description properties, then the visual relation identifier you defined is ignored.
9. Visual relation identifiers are not supported for WebService test objects.
Friday, October 17, 2014
QTP: MS Access Connectivity
Option Explicit Dim objConn,objRS Set objConn = CreateObject("ADODB.Connection") Set objRS = Createobject("ADODB.Recordset") objConn.Open "Driver={Microsoft Access Driver (*.mdb),(*.accdb)};DBQ=C:\USERS\Desktop\FileName.accdb;" objRS.Open "Select * FROM TABLE1", objConn Do while not objRS.EOF Browser("Gmail").WebEdit("username").Set objRS.FIELDS("UN") Browser("Gmail").WebEdit("password").Set objRS.FIELDS("PW") Browser("Gmail").WebBotton("LogIn").CLICK
objRS.MOVENEXT
Loop 'Release created objects Set objRS= NOTHING Set objConn= NOTHING
Note: The database we are using here is MS Access 2007(*.accdb). Create a table in MS Acess 2007 called "TABLE1" and column 'names as "UN" and "PW" and path of the table which we create is C:\USERS\Desktop\FileName.accdb.
Saturday, September 6, 2014
Monday, May 26, 2014
Mercury Timer Object
Mercury Timer Object
An internal timer object that measures the passage of time in milliseconds.
Important Information
The MercuryTimer object is an internal timer item of the MercuryTimers collection object.
Associated Methods
Associated Property
How to compare two images using QTP
We know by using Bitmap checkpoint, we can compare two images.
But is there a other way we can compare?
Yes, we can use "IsEqualBin" method from Mercury.FileCompare
sImgPath1="C:\Users\user\Downloads\SAI 01461_exposure.JPG"
'sImgPath2="C:\Users\user\Downloads\SAI 01462_exposure.JPG"
sImgPath2="C:\Users\user\Downloads\SAI 0175_exposure.JPG"
Set obj=createobject("Mercury.FileCompare")
retVal=obj.IsEqualBin(sImgPath1,sImgPath2,1,1)
print retVal
Set obj=nothing
The retVal=1 if both the images are same
else retVal=0
But is there a other way we can compare?
Yes, we can use "IsEqualBin" method from Mercury.FileCompare
sImgPath1="C:\Users\user\Downloads\SAI 01461_exposure.JPG"
'sImgPath2="C:\Users\user\Downloads\SAI 01462_exposure.JPG"
sImgPath2="C:\Users\user\Downloads\SAI 0175_exposure.JPG"
Set obj=createobject("Mercury.FileCompare")
retVal=obj.IsEqualBin(sImgPath1,sImgPath2,1,1)
print retVal
Set obj=nothing
The retVal=1 if both the images are same
else retVal=0
Right click on a weblink using QTP
'The below scripts selects the second pop up item after right clicking on the weblink.
'Open the Yahoo website in IE and execute the script.
'Opens the images webpage(open in new tab) in a new tab
Setting.WebPackage("ReplayType") = 2
'This statement makes the replay type to Mouse from event. Without this configuration the script may or may not work.
Set link=browser("Yahoo!").Page("Yahoo!").Link("Images")
link.highlight
index=2
Set obj = CreateObject("Mercury.DeviceReplay")
Set WshShell = CreateObject("WScript.Shell")
'Get the absolute coordinates of the object
absx = link.GetROProperty("abs_x")
absy = link.GetROProperty("abs_y")
'Right click on the Object
obj.MouseClick absx+5, absy+5, 2 'Here 2 is for right click
'Optional wait statement
wait 2
'Clicking number of downs
For i = 1 To index
WshShell.sendkeys "{DOWN}"
Next
WshShell.sendkeys "{ENTER}"
Setting.WebPackage("ReplayType") = 1
Set WshSEll = nothing
Set obj = nothing
'Open the Yahoo website in IE and execute the script.
'Opens the images webpage(open in new tab) in a new tab
Setting.WebPackage("ReplayType") = 2
'This statement makes the replay type to Mouse from event. Without this configuration the script may or may not work.
Set link=browser("Yahoo!").Page("Yahoo!").Link("Images")
link.highlight
index=2
Set obj = CreateObject("Mercury.DeviceReplay")
Set WshShell = CreateObject("WScript.Shell")
'Get the absolute coordinates of the object
absx = link.GetROProperty("abs_x")
absy = link.GetROProperty("abs_y")
'Right click on the Object
obj.MouseClick absx+5, absy+5, 2 'Here 2 is for right click
'Optional wait statement
wait 2
'Clicking number of downs
For i = 1 To index
WshShell.sendkeys "{DOWN}"
Next
WshShell.sendkeys "{ENTER}"
Setting.WebPackage("ReplayType") = 1
Set WshSEll = nothing
Set obj = nothing
Thursday, April 17, 2014
Master list of VBScript Built-in functions
Abs Function: Returns the absolute
value of a number.
Array Function: Returns a Variant containing an array.
Asc Function: Returns the ANSI character code corresponding to the first letter in a string.
Atn Function: Returns the arctangent of a number.
CBool Function: Returns an expression that has been converted to a Variant of subtype Boolean.
CByte Function: Returns an expression that has been converted to a Variant of subtype Byte.
CCur Function: Returns an expression that has been converted to a Variant of subtype Currency.
CDate Function: Returns an expression that has been converted to a Variant of subtype Date.
CDbl Function: Returns an expression that has been converted to a Variant of subtype Double.
Chr Function: Returns the character associated with the specified ANSI character code.
CInt Function: Returns an expression that has been converted to a Variant of subtype Integer.
CLng Function: Returns an expression that has been converted to a Variant of subtype Long.
Cos Function: Returns the cosine of an angle.
CreateObject Function: Creates and returns a reference to an Automation object.
CSng Function: Returns an expression that has been converted to a Variant of subtype Single.
CStr Function: Returns an expression that has been converted to a Variant of subtype String.
Date Function: Returns the current system date.
DateAdd Function: Returns a date to which a specified time interval has been added.
DateDiff Function: Returns the number of intervals between two dates.
DatePart Function: Returns the specified part of a given date.
DateSerial Function: Returns a Variant of subtype Date for a specified year, month, and day.
DateValue Function: Returns a Variant of subtype Date.
Day Function: Returns a whole number between 1 and 31, inclusive, representing the day of the month.
Eval Function: Evaluates an expression and returns the result.
Exp Function: Returns e (the base of natural logarithms) raised to a power.
Filter Function: Returns a zero-based array containing subset of a string array based on a specified filter criteria.
Fix Function: Returns the integer portion of a number.
FormatCurrency Function: Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.
FormatDateTime Function: Returns an expression formatted as a date or time.
FormatNumber Function: Returns an expression formatted as a number.
FormatPercent Function: Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.
GetLocale Function: Returns the current locale ID value.
GetObject Function: Returns a reference to an Automation object from a file.
GetRef Function: Returns a reference to a procedure that can be bound to an event.
Hex Function: Returns a string representing the hexadecimal value of a number.
Hour Function: Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
InputBox Function: Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
InStr Function: Returns the position of the first occurrence of one string within another.
InStrRev Function: Returns the position of an occurrence of one string within another, from the end of string.
Int Function: Returns the integer portion of a number.
IsArray Function: Returns a Boolean value indicating whether a variable is an array.
IsDate Function: Returns a Boolean value indicating whether an expression can be converted to a date.
IsEmpty Function: Returns a Boolean value indicating whether a variable has been initialized.
IsNull Function: Returns a Boolean value that indicates whether an expression contains no valid data (Null).
IsNumeric Function: Returns a Boolean value indicating whether an expression can be evaluated as a number.
IsObject Function: Returns a Boolean value indicating whether an expression references a valid Automation object.
Join Function: Returns a string created by joining a number of substrings contained in an array.
LBound Function: Returns the smallest available subscript for the indicated dimension of an array.
LCase Function: Returns a string that has been converted to lowercase.
Left Function: Returns a specified number of characters from the left side of a string.
Len Function: Returns the number of characters in a string or the number of bytes required to store a variable.
LoadPicture Function: Returns a picture object. Available only on 32-bit platforms.
Log Function: Returns the natural logarithm of a number.
LTrim Function: Returns a copy of a string without leading spaces.
Mid Function: Returns a specified number of characters from a string.
Minute Function: Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.
Month Function: Returns a whole number between 1 and 12, inclusive, representing the month of the year.
MonthName Function: Returns a string indicating the specified month.
MsgBox Function: Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Now Function: Returns the current date and time according to the setting of your computer's system date and time.
Oct Function: Returns a string representing the octal value of a number.
Replace Function: Returns a string in which a specified substring has been replaced with another substring a specified number of times.
RGB Function: Returns a whole number representing an RGB color value.
Right Function: Returns a specified number of characters from the right side of a string.
Rnd Function: Returns a random number.
Round Function: Returns a number rounded to a specified number of decimal places.
RTrim Function: Returns a copy of a string without trailing spaces.
ScriptEngine Function: Returns a string representing the scripting language in use.
ScriptEngineBuildVersion Function: Returns the build version number of the scripting engine in use.
ScriptEngineMajorVersion Function: Returns the major version number of the scripting engine in use.
ScriptEngineMinorVersion Function: Returns the minor version number of the scripting engine in use.
Second Function: Returns a whole number between 0 and 59, inclusive, representing the second of the minute.
SetLocale Function: Sets the global locale and returns the previous locale.
Sgn Function: Returns an integer indicating the sign of a number.
Sin Function: Returns the sine of an angle.
Space Function: Returns a string consisting of the specified number of spaces.
Split Function: Returns a zero-based, one-dimensional array containing a specified number of substrings.
Sqr Function: Returns the square root of a number.
StrComp Function: Returns a value indicating the result of a string comparison.
String Function: Returns a repeating character string of the length specified.
StrReverse Function: Returns a string in which the character order of a specified string is reversed.
Tan Function: Returns the tangent of an angle.
Time Function: Returns a Variant of subtype Date indicating the current system time.
Timer Function: Returns the number of seconds that have elapsed since 12:00 AM (midnight).
TimeSerial Function: Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.
TimeValue Function: Returns a Variant of subtype Date containing the time.
Trim Function: Returns a copy of a string without leading or trailing spaces.
TypeName Function: Returns a string that provides Variant subtype information about a variable.
UBound Function: Returns the largest available subscript for the indicated dimension of an array.
UCase Function: Returns a string that has been converted to uppercase.
VarType Function: Returns a value indicating the subtype of a variable.
Weekday Function: Returns a whole number representing the day of the week.
WeekdayName Function: Returns a string indicating the specified day of the week.
Year Function: Returns a whole number representing the year.
Array Function: Returns a Variant containing an array.
Asc Function: Returns the ANSI character code corresponding to the first letter in a string.
Atn Function: Returns the arctangent of a number.
CBool Function: Returns an expression that has been converted to a Variant of subtype Boolean.
CByte Function: Returns an expression that has been converted to a Variant of subtype Byte.
CCur Function: Returns an expression that has been converted to a Variant of subtype Currency.
CDate Function: Returns an expression that has been converted to a Variant of subtype Date.
CDbl Function: Returns an expression that has been converted to a Variant of subtype Double.
Chr Function: Returns the character associated with the specified ANSI character code.
CInt Function: Returns an expression that has been converted to a Variant of subtype Integer.
CLng Function: Returns an expression that has been converted to a Variant of subtype Long.
Cos Function: Returns the cosine of an angle.
CreateObject Function: Creates and returns a reference to an Automation object.
CSng Function: Returns an expression that has been converted to a Variant of subtype Single.
CStr Function: Returns an expression that has been converted to a Variant of subtype String.
Date Function: Returns the current system date.
DateAdd Function: Returns a date to which a specified time interval has been added.
DateDiff Function: Returns the number of intervals between two dates.
DatePart Function: Returns the specified part of a given date.
DateSerial Function: Returns a Variant of subtype Date for a specified year, month, and day.
DateValue Function: Returns a Variant of subtype Date.
Day Function: Returns a whole number between 1 and 31, inclusive, representing the day of the month.
Eval Function: Evaluates an expression and returns the result.
Exp Function: Returns e (the base of natural logarithms) raised to a power.
Filter Function: Returns a zero-based array containing subset of a string array based on a specified filter criteria.
Fix Function: Returns the integer portion of a number.
FormatCurrency Function: Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.
FormatDateTime Function: Returns an expression formatted as a date or time.
FormatNumber Function: Returns an expression formatted as a number.
FormatPercent Function: Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.
GetLocale Function: Returns the current locale ID value.
GetObject Function: Returns a reference to an Automation object from a file.
GetRef Function: Returns a reference to a procedure that can be bound to an event.
Hex Function: Returns a string representing the hexadecimal value of a number.
Hour Function: Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
InputBox Function: Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
InStr Function: Returns the position of the first occurrence of one string within another.
InStrRev Function: Returns the position of an occurrence of one string within another, from the end of string.
Int Function: Returns the integer portion of a number.
IsArray Function: Returns a Boolean value indicating whether a variable is an array.
IsDate Function: Returns a Boolean value indicating whether an expression can be converted to a date.
IsEmpty Function: Returns a Boolean value indicating whether a variable has been initialized.
IsNull Function: Returns a Boolean value that indicates whether an expression contains no valid data (Null).
IsNumeric Function: Returns a Boolean value indicating whether an expression can be evaluated as a number.
IsObject Function: Returns a Boolean value indicating whether an expression references a valid Automation object.
Join Function: Returns a string created by joining a number of substrings contained in an array.
LBound Function: Returns the smallest available subscript for the indicated dimension of an array.
LCase Function: Returns a string that has been converted to lowercase.
Left Function: Returns a specified number of characters from the left side of a string.
Len Function: Returns the number of characters in a string or the number of bytes required to store a variable.
LoadPicture Function: Returns a picture object. Available only on 32-bit platforms.
Log Function: Returns the natural logarithm of a number.
LTrim Function: Returns a copy of a string without leading spaces.
Mid Function: Returns a specified number of characters from a string.
Minute Function: Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.
Month Function: Returns a whole number between 1 and 12, inclusive, representing the month of the year.
MonthName Function: Returns a string indicating the specified month.
MsgBox Function: Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Now Function: Returns the current date and time according to the setting of your computer's system date and time.
Oct Function: Returns a string representing the octal value of a number.
Replace Function: Returns a string in which a specified substring has been replaced with another substring a specified number of times.
RGB Function: Returns a whole number representing an RGB color value.
Right Function: Returns a specified number of characters from the right side of a string.
Rnd Function: Returns a random number.
Round Function: Returns a number rounded to a specified number of decimal places.
RTrim Function: Returns a copy of a string without trailing spaces.
ScriptEngine Function: Returns a string representing the scripting language in use.
ScriptEngineBuildVersion Function: Returns the build version number of the scripting engine in use.
ScriptEngineMajorVersion Function: Returns the major version number of the scripting engine in use.
ScriptEngineMinorVersion Function: Returns the minor version number of the scripting engine in use.
Second Function: Returns a whole number between 0 and 59, inclusive, representing the second of the minute.
SetLocale Function: Sets the global locale and returns the previous locale.
Sgn Function: Returns an integer indicating the sign of a number.
Sin Function: Returns the sine of an angle.
Space Function: Returns a string consisting of the specified number of spaces.
Split Function: Returns a zero-based, one-dimensional array containing a specified number of substrings.
Sqr Function: Returns the square root of a number.
StrComp Function: Returns a value indicating the result of a string comparison.
String Function: Returns a repeating character string of the length specified.
StrReverse Function: Returns a string in which the character order of a specified string is reversed.
Tan Function: Returns the tangent of an angle.
Time Function: Returns a Variant of subtype Date indicating the current system time.
Timer Function: Returns the number of seconds that have elapsed since 12:00 AM (midnight).
TimeSerial Function: Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.
TimeValue Function: Returns a Variant of subtype Date containing the time.
Trim Function: Returns a copy of a string without leading or trailing spaces.
TypeName Function: Returns a string that provides Variant subtype information about a variable.
UBound Function: Returns the largest available subscript for the indicated dimension of an array.
UCase Function: Returns a string that has been converted to uppercase.
VarType Function: Returns a value indicating the subtype of a variable.
Weekday Function: Returns a whole number representing the day of the week.
WeekdayName Function: Returns a string indicating the specified day of the week.
Year Function: Returns a whole number representing the year.
Saturday, March 1, 2014
How to activate, minimize, maximize a browser
We can use below code to active, minimize, maximize a browser. I put all these three methods in a single function, but you need to tweek this code as per your needs.
Function WinActivate(Object)
Dim hWnd
hWnd = Object.GetROProperty("hwnd") 'First get the window handle
On Error Resume Next
Window("hwnd:=" & hWnd).Activate 'Put fouse on the window
If Err.Number <> 0 Then
hWnd=Browser("hwnd:=" & hWnd).Object.hWnd 'now get the browser handle
Window("hwnd:=" & hWnd).Activate
'Window("hwnd:=" & hWnd).minimize 'To minimize the browser
'Window("hwnd:=" & hWnd).maximize
Err.Clear
End If
On Error Goto 0
End Function
RegisterUserFunc "Browser","Activate","WinActivate"
RegisterUserFunc "Browser","Minimize","WinMinimize"
RegisterUserFunc "Browser","Maximize","WinMaximize"
Browser(objBrowser).Activate
Browser(objBrowser).Minimize
Browser(objBrowser).Maximize
Sunday, January 26, 2014
Library Files
Inorder to modularize the script, library Files are added to the QTP Script. It contains variable declaration, Functions, Classes etc. They enable reusability that can be shared across test scripts. They are saved with an extenstion .vbs or .qfl
A New Library File can be Created by Navigating to "File" >> "Function Library"
Associating Function Libraries
1 : By using "File" > "Settings" > Resources > Associate Function Library option. Click on "+" Button to Add Function Library File and add it using actual path or relative path.
2 : Using ExecuteFile method.
'Syntax : ExecuteFile(Filepath) ExecuteFile "C:\lib1.vbs" ExecuteFile "C:\lib2.vbs"
3 : Using LoadFunctionLibrary Method.
'Syntax : LoadFunctionLibrary(Filepath) LoadFunctionLibrary "C:\lib1.vbs" LoadFunctionLibrary "C:\lib2.vbs"
4 : Automation Object Model(AOM) - It is a mechanism using which we can control various QTP operations outside QTP. Using AOM, we can launch QTP, Open the Test, Associate Function Libraries etc. The Following Vbscript should be saved with Extension .vbs and upon executing the same, QTP will be launched and test would start executing. AOM will be discussed in detail in the later chapters.
'Launch QTP Set objQTP = CreateObject("QuickTest.Application") objQTP.Launch objQTP.Visible = True 'Open the test objQTP.Open "D:\GUITest2", False, False Set objLib = objQTP.Test.Settings.Resources.Libraries 'Associate Function Library if NOT associated already. If objLib.Find("C:\lib1.vbs") = -1 Then objLib.Add "C:\lib1.vbs", 1 End
Sunday, January 5, 2014
Subscribe to:
Posts (Atom)