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")

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

Friday, September 30, 2011

Working with Dictionary Object

Set dictObj=Createobject("Scripting.Dictionary")
dictObj.Add "1","One"
dictObj.Add "2","Two"
dictObj.Add 3,"Three" 'Observe here i am passing key as a integer meaning we can pass different types as Key

msgbox dictObj.Count 'This method returns the number of keys

If dictObj.Exists(3) Then 'This method looks for the Key
msgbox "Key exists"
else
msgbox "Key does not exist"
End If

a=dictObj.Keys 'This method assigns all the keys to an array
For i=1 to dictObj.Count
msgbox dictObj.Item(a(i-1)) 'This method retrieves the value of the key
Next

Sunday, July 24, 2011

How to select a check box\click a link in a web table with text

This is one of the most common interview question.
The first column of a web table contains checkboxs, and in the second column have some text.
If any row in the second column contains a text say "uday", then the corresponding checkbox in the first column should be selected.
How can we do that?

It is pretty simple: :)
rowNo=B().P().WT().getrowwithcelltext("uday",2) 'Here "uday" is my search string and 2 the column number
set childObj=B().P().WT().ChileItem(rowNo,1,"webcheckbox")
childObj.set "ON"

Friday, July 22, 2011

Different ways of synchronizing in QTP

In QTP, we can do synchronizing between QTP tool and application in many ways:

1. The best one is, use synchronization point, which waits until the object meets the criteria. The general syntax is:
Object.waitproperty "your criteria"
Ex: B().P().WB().Waitproperty "enabled",1,10000
B().P().WE().WaitProperty "text",micNotEmpty(var)
(Here the tool waits until the object meets the criteria).

2. Wait(least preferred): It is like hard coding the time. The syntax is:
Wait(x) ' waits x seconds irrespective of the object state. For Ex. If we set the x as 60 Seconds and the object is ready by 2 seconds, even then it waits for 60 seconds.
If the object is not ready by 60 seconds, it wont bother and it moves to the next step(may causes script fail).

3. We can use Wait and Exists in some cases

4. And also we can use Wait and CheckProperty, which almost works like synchronization point.

5. You can also configure the default settings in the tool.
Browser navigation timeout : File -> Settings -> Web ->Browser navigation timeout
Object synchronization timeout : File -> Settings ->Run -> Object synchronization timeout.

6. We can also write custom script for QTP like below to wait till the application is loaded.

Set oPage=B().P().Object
While oPage.readystate=”Completed”
Wend

While oPage.Busy
Wend