I found people forget the all the built-in environmental variables, so thought of putting all built-in variables here in this post.
ActionIteration - Indicates which action iteration is currently running.
ActionName - Indicates which action is currently running
ControllerHostName - the name of the computer which serves as a controller
GroupName - The scenario identification number
LocalHostName - Local Host Name
OS - Operation System
OSVersion - Operating system version
ProductDir - folder path where the product is installed
ProductName - Product Name
ProductVer - Product Version
ResultDir - Folder path where the results are saved
Scenarioid - The scenario identification number
SystemTempDir - System Temporary Directory
TestDir - Path of the Test
TestIteration - Indicates which test iteration is currently running
TestName - The name of the test
UpdatingActiveScreen -
UpdatingCheckpoints -
UpdatingTODescriptions -
UserName - Windows Login User Name
VUserId -
Wednesday, December 19, 2012
Friday, November 9, 2012
How to find CPU and Memory Usage using QTP
How to find out CPU utilization and Memory usage as displayed in the Windows Task Manager.
We can get these values using WMI service.
Below is the code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Get the CPU utilization %
myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"
For Each objItem in objWMIService.ExecQuery(myQuery)
print "Processor time " & objItem.PercentProcessorTime & " %"
next
'Get the total Physical Memory
myQuery="Select * from Win32_ComputerSystem"
Set colItems = objWMIService.ExecQuery(myQuery)
For each objitem in colItems
print "Total Physical Memory "&objitem.TotalPhysicalMemory/1024
Next
'Get the total available physical memory
myQuery="Select * from Win32_PerfFormattedData_PerfOS_Memory"
Set colItems = objWMIService.ExecQuery(myQuery)
For Each objItem in colItems
print "Available GB: " & objItem.AvailableKBytes
Next
We can get these values using WMI service.
Below is the code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Get the CPU utilization %
myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"
For Each objItem in objWMIService.ExecQuery(myQuery)
print "Processor time " & objItem.PercentProcessorTime & " %"
next
'Get the total Physical Memory
myQuery="Select * from Win32_ComputerSystem"
Set colItems = objWMIService.ExecQuery(myQuery)
For each objitem in colItems
print "Total Physical Memory "&objitem.TotalPhysicalMemory/1024
Next
'Get the total available physical memory
myQuery="Select * from Win32_PerfFormattedData_PerfOS_Memory"
Set colItems = objWMIService.ExecQuery(myQuery)
For Each objItem in colItems
print "Available GB: " & objItem.AvailableKBytes
Next
Wednesday, November 7, 2012
How to execute QTP scripts in a remote machine when the window is minimized?
QTP Version : 11 or later
RDP Version : 6 or later
If you want to run QTP scripts run on a remote machine and if that Remote machine/Window is minimized, then the scripts will fail.
In order to overcome the issue, you need to add a registry key in Windows registry on your client machine/from the machine where you initiating the remote desktop.
1. Close all your remote desktops.
2. Create a registry "RemoteDesktop_SuppressWhenMinimized" if does not exist in the below path:
HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized
or
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized
3. Set the value for this data to 2.
If you would like to add the registry key by just running a .reg file follow below steps:
1. Open Notepad.
2. Cope the below content:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002
3. Save the file as "FileName.reg" format
4. Now, double click on this reg file, so that registry keys will be added.
RDP Version : 6 or later
If you want to run QTP scripts run on a remote machine and if that Remote machine/Window is minimized, then the scripts will fail.
In order to overcome the issue, you need to add a registry key in Windows registry on your client machine/from the machine where you initiating the remote desktop.
1. Close all your remote desktops.
2. Create a registry "RemoteDesktop_SuppressWhenMinimized" if does not exist in the below path:
HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized
or
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized
3. Set the value for this data to 2.
If you would like to add the registry key by just running a .reg file follow below steps:
1. Open Notepad.
2. Cope the below content:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002
3. Save the file as "FileName.reg" format
4. Now, double click on this reg file, so that registry keys will be added.
Saturday, July 28, 2012
How to activate, minimize, maximize a browser using QTP
You 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
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
Saturday, June 30, 2012
How to verify a Browser Window is minimized
The bad part is QTP does not support retrieving RO Properties of a browser.
If it has supported, then we would have use a method like
Browser("Browser Name").GetROProperty("minimized")
But we can use Extern to use some of the methods from Windows user32.dll
Following are the two ways to verify the window minimized.
Extern.Declare micHwnd, "FindWindow", "user32.dll","FindWindowA", micString,micString 'this method returns a handle
Extern.Declare micLong,"GetWindowMinimizeState", "user32.dll" ,"IsZoomed",micLong 'IsZoomed meaning IsMaximized
hwnd=extern.FindWindow(NULL,"Links - Windows Internet Explorer")
print Extern.GetWindowMinimizeState(hwnd) 'Similar way
Const GA_ROOT = 2
'Declare Function GetAncestor Lib "user32.dll" (ByVal hwnd As Long, ByVal gaFlags As Long) As Long Extern.Declare micLong, "GetMainWindow", "user32" ,"GetAncestor",micLong, micLong
hwnd = browser("name:=Links.*").GetROProperty("hwnd") 'this returns the handle of the Browser Tab hwnd = Extern.GetMainWindow(hwnd , GA_ROOT) 'This returns the handle of the browser(which means handle of the browser)
msgbox Window("hwnd:=" & hwnd ).GetROProperty("minimized")
But we can use Extern to use some of the methods from Windows user32.dll
Following are the two ways to verify the window minimized.
Extern.Declare micHwnd, "FindWindow", "user32.dll","FindWindowA", micString,micString 'this method returns a handle
Extern.Declare micLong,"GetWindowMinimizeState", "user32.dll" ,"IsZoomed",micLong 'IsZoomed meaning IsMaximized
hwnd=extern.FindWindow(NULL,"Links - Windows Internet Explorer")
print Extern.GetWindowMinimizeState(hwnd) 'Similar way
Const GA_ROOT = 2
'Declare Function GetAncestor Lib "user32.dll" (ByVal hwnd As Long, ByVal gaFlags As Long) As Long Extern.Declare micLong, "GetMainWindow", "user32" ,"GetAncestor",micLong, micLong
hwnd = browser("name:=Links.*").GetROProperty("hwnd") 'this returns the handle of the Browser Tab hwnd = Extern.GetMainWindow(hwnd , GA_ROOT) 'This returns the handle of the browser(which means handle of the browser)
msgbox Window("hwnd:=" & hwnd ).GetROProperty("minimized")
Labels:
FindWindow,
GetAncestor,
Window minimized using QTP
How to find and fill a color in Excel Cell
Set xlObj=getobject("","Excel.Application")
Set xlWBObj=xlObj.workbooks.open("c:\delete.xls")
set xlWSObj=xlWBObj.worksheets(1)
xlWSObj.cells(1,1).Font.Color=vbRed 'This statement changes the color of the Text in the specified cell
xlWSObj.cells(2,1).Interior.ColorIndex=4 'This method changes the color of the background of the cell
print xlWSObj.cells(1,1).Font.Color
print xlWSObj.cells(2,1).Interior.ColorIndex
xlWBObj.save
xlWBObj.close
xlObj.application.quit
Set xlObj=nothing
Set xlWBObj=xlObj.workbooks.open("c:\delete.xls")
set xlWSObj=xlWBObj.worksheets(1)
xlWSObj.cells(1,1).Font.Color=vbRed 'This statement changes the color of the Text in the specified cell
xlWSObj.cells(2,1).Interior.ColorIndex=4 'This method changes the color of the background of the cell
print xlWSObj.cells(1,1).Font.Color
print xlWSObj.cells(2,1).Interior.ColorIndex
xlWBObj.save
xlWBObj.close
xlObj.application.quit
Set xlObj=nothing
Monday, April 30, 2012
How to copy content to Clipboard
We can use clipboard using two ways.
One is using Mercury.Clipboard.
Second one is using DotNetFactory.
Using Mercury.Clipboard:
'Creates an instance of Mercury.Clipboard
set objCB=createobject("Mercury.Clipboard")
'Here i am clearing already existing content in clipboard
objCB.Clear()
'Copying some text into Clipboard
objCB.SetText("Hello Uday")
'Retrieving the content from Clipboard
print objCB.GetText
Using DotNetFactory:
'Creates an instance of DotNetFactory Computer Object
Set objDFComputer=DotNetFactory("Microsoft.VisualBasic.Devices.Computer","Microsoft.VisualBasic")
'Here i am clearing already existing content in clipboard
Set objCB=objDFComputer.ClipBoard
objCB.clear()
'Copying some text into Clipboard
objCB.SetText("Hello Uday")
'Retrieving the content from Clipboard
print objCB.GetText
One is using Mercury.Clipboard.
Second one is using DotNetFactory.
Using Mercury.Clipboard:
'Creates an instance of Mercury.Clipboard
set objCB=createobject("Mercury.Clipboard")
'Here i am clearing already existing content in clipboard
objCB.Clear()
'Copying some text into Clipboard
objCB.SetText("Hello Uday")
'Retrieving the content from Clipboard
print objCB.GetText
Using DotNetFactory:
'Creates an instance of DotNetFactory Computer Object
Set objDFComputer=DotNetFactory("Microsoft.VisualBasic.Devices.Computer","Microsoft.VisualBasic")
'Here i am clearing already existing content in clipboard
Set objCB=objDFComputer.ClipBoard
objCB.clear()
'Copying some text into Clipboard
objCB.SetText("Hello Uday")
'Retrieving the content from Clipboard
print objCB.GetText
Sunday, April 29, 2012
"Setting" utility object to access registry values
We can obtain and configure all the QTP configurable parameters(all parameters in MicTest) using "Setting" utility object. Ex: BrowserType, DefaultLoadTime etc...
For Ex: If you want to retrieve the default location of saving your tests, which exists in HKLM\Software\Mercury Interactive\QuickTest Professional\MicTest\TestsDirectory, you can use below line of code:
Setting
print Setting("TestsDirectory")
You can also use Setting.Item to retrieve the value of the parameter. For the above, you can also use like:
print Setting.Item("TestsDirectory")
If you want to access a parameter exists in folders, then you can use
Setting("")("Child1")("Child2)("PropertyName")
Here is the Ex. to access the Add-In Manager name for Visual Basic.
print Setting("AddIn Manager")("VisualBasic")("Name")
For Ex: If you want to retrieve the default location of saving your tests, which exists in HKLM\Software\Mercury Interactive\QuickTest Professional\MicTest\TestsDirectory, you can use below line of code:
Setting
print Setting("TestsDirectory")
You can also use Setting.Item to retrieve the value of the parameter. For the above, you can also use like:
print Setting.Item("TestsDirectory")
If you want to access a parameter exists in folders, then you can use
Setting("")("Child1")("Child2)("PropertyName")
Here is the Ex. to access the Add-In Manager name for Visual Basic.
print Setting("AddIn Manager")("VisualBasic")("Name")
Thursday, March 15, 2012
Pure virtual function call
Suddenly QTP behaves very strangely. You cannot save any Tests etc etc... and it throws an error message saying R6025 - Pure Virtual Function call. You cannot do much after this error.
Reinstalling QTP also less useful.
Possible causes might be:
QTP configuration files might be corrupt.
Not properly handling pointers in QTP, meaning not properly releasing the objects like Excel, ObjectRepository objects etc...
QTP provides patch for this. Install the patch QTP_00604 or QTP_00626.
IE scripts are failing or Objects are not recognized in IE.
Scripts are failing when IE is upgraded.
User has scripts developed in IE 6 and they worked fine.
But user updated his IE to IE7, then the scripts which worked earlier are failing now in IE 7.
Reasons could be:
BHOManager add-in could be disabled in IE7.
This add-in is needed for QTP to interact with IE.
Enable this Add-in by:
Open IE -> Tools Menu -> Manage Add-ons -> Enable or Disable add-ons -> Select BHOManager Class
Check whether the add-on is enabled or not. It should be enabled.
Objects are properly recognized in IE 7, but not recognized in IE 8.
Reason could be: Protected mode in IE 8.
Check the above solution, then follow to disable the protected mode in IE.
Open IE -> Tools Menu -> Internet Options -> Security Tab -> Uncheck "Enable Protected Mode" check box.
User has scripts developed in IE 6 and they worked fine.
But user updated his IE to IE7, then the scripts which worked earlier are failing now in IE 7.
Reasons could be:
BHOManager add-in could be disabled in IE7.
This add-in is needed for QTP to interact with IE.
Enable this Add-in by:
Open IE -> Tools Menu -> Manage Add-ons -> Enable or Disable add-ons -> Select BHOManager Class
Check whether the add-on is enabled or not. It should be enabled.
Objects are properly recognized in IE 7, but not recognized in IE 8.
Reason could be: Protected mode in IE 8.
Check the above solution, then follow to disable the protected mode in IE.
Open IE -> Tools Menu -> Internet Options -> Security Tab -> Uncheck "Enable Protected Mode" check box.
Wednesday, March 14, 2012
All menu options are missing in QTP
Sometime you are strange to see that all menu options are missing in QTP.
Ex: File -> Setting etc... You may miss lot of menu options in QTP.
Fix:
Open QTP -> Tools menu -> Customize -> Click on Toolbars Tab -> Restore All ->click on Close button.
If you miss options in Tools Menu, then in QTP right click on the tool bar and choose customize.
Ex: File -> Setting etc... You may miss lot of menu options in QTP.
Fix:
Open QTP -> Tools menu -> Customize -> Click on Toolbars Tab -> Restore All ->click on Close button.
If you miss options in Tools Menu, then in QTP right click on the tool bar and choose customize.
Sunday, March 11, 2012
How to get the source code of a Webpage using QTP
print browser("name:=AAA").page("title:=AAA").Object.documentElement.innerHTML
Saturday, February 25, 2012
How to find the Memory usage and Processor usage using QTP
QTP provides the object called "SystemMonitor" which can be used to get Memory and Processor usage.
'To find the Memory usage of an application, use below:
SystemMonitor.GetValue("Application name without extension", "counter name")
Ex: msgbox SystemMonitor.GetValue("QTPro","Memory Usage (in MB)")
'To find the Processor usage of an application, use below:
Ex: msgbox SystemMonitor.GetValue("javaw","% Processor Time")
'To find the Memory usage of an application, use below:
SystemMonitor.GetValue("Application name without extension", "counter name")
Ex: msgbox SystemMonitor.GetValue("QTPro","Memory Usage (in MB)")
'To find the Processor usage of an application, use below:
Ex: msgbox SystemMonitor.GetValue("javaw","% Processor Time")
Tuesday, February 21, 2012
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
Subscribe to:
Posts (Atom)