This post will help you in reading data from a virtual table. This is really helpful and we took a very long time to come up with this solution. It is very simple but that thought process took some time to set in ;). So here we go.
Create the virtual table using the virtual objects manager. The properties available to you would be Width, Height, Rows, Columns, x, y.
Get the height and width of a single cell by dividing the table width and height by the column and row values respectively.
x and y are the values of the top left corner of the first cell, to get the bottom right corner add the height and width calculated for a single cell. Now use the GetVisibleText property with the parent object.
Like,
Say you have a grid or table that is recognized as a winobject, and you create a virtual table for it. Now the code to read the data from the first cell of the table would be:
val = Window(" ").Page(" ").WinObject(" ").GetVisibleText(x,y,x1,y1)
msgbox val
Search This Blog
Monday, January 3, 2011
Wednesday, December 1, 2010
Setting the same value in all child objects
There might be cases where you want to enter the same value in all the objects of the same class like an edit box. This is particularly useful when checking for field level validations. The approach to be followed can be to identify all the childobjects in the page belonging to the same class, and then trying to set the value or retrieve a value. The below piece of code can be used to enter the same text in all the WebEdit objects in the YahooMail page.
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "www.yahoomail.com"
Browser("Google").Page("Yahoo! Mail: The best").Sync
Set objDesc = Description.Create
objDesc("micclass").Value = "WebEdit"
Set Child = Browser("Google").Page("Yahoo! Mail: The best").ChildObjects(objDesc)
For iCount = 0 to Child.count -1
Child(iCount).Highlight
Child(iCount).Set "Divya Rakesh"
Next
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "www.yahoomail.com"
Browser("Google").Page("Yahoo! Mail: The best").Sync
Set objDesc = Description.Create
objDesc("micclass").Value = "WebEdit"
Set Child = Browser("Google").Page("Yahoo! Mail: The best").ChildObjects(objDesc)
For iCount = 0 to Child.count -1
Child(iCount).Highlight
Child(iCount).Set "Divya Rakesh"
Next
Associating all the library files from a folder before start
Using the below code you can add all the library files in folder from a vbs script at the beginning of the session. This same vbs file can be used for doing all the settings as well, like opening QTP, opening the test, associating all resources and then running the test. You can easily get the script by modifying the script that is generated when the user gives Generate script in the File Settings. The below part of the code can be updated to this vbs file to associate all the library file from a given folder.
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFile.GetFolder("E:\Automation\Library")
Set objFiles = objFolder.Files
For each sFile in objFiles
sExtn = Right (sFile, 3)
If sExtn = "vbs" or sExtn = "qfl" Then
App.Test.Settings.Resources.Libraries.Add sFile
End If
Next
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFile.GetFolder("E:\Automation\Library")
Set objFiles = objFolder.Files
For each sFile in objFiles
sExtn = Right (sFile, 3)
If sExtn = "vbs" or sExtn = "qfl" Then
App.Test.Settings.Resources.Libraries.Add sFile
End If
Next
Wednesday, October 27, 2010
Lock your machine through the script
Add the below code to end of script to lock the machine automatically
Set obj = CreateObject("WScript.Shell")
sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
obj.Run sCmnd, 0, False
Set obj =nothing
Set obj = CreateObject("WScript.Shell")
sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
obj.Run sCmnd, 0, False
Set obj =nothing
Tuesday, October 19, 2010
Getting the Machine Name through the Script
The below piece of code will give you the machine name and the user name of the pc where it is running. This is particularly useful when we need system parameters:
Set oWshNetwork = CreateObject("WScript.Network")
sMachine = oWshNetwork.ComputerName
sUser = oWshNetwork.UserName
msgbox sMachine
msgbox sUser
You can get all other system params also using similar codes using WScript.Network
Set oWshNetwork = CreateObject("WScript.Network")
sMachine = oWshNetwork.ComputerName
sUser = oWshNetwork.UserName
msgbox sMachine
msgbox sUser
You can get all other system params also using similar codes using WScript.Network
Thursday, October 14, 2010
Memory Usage Using WMI
The below code can be used to get the memory usage, peak memory usage and the virtual memory usage as in the Task Manager without opening it. Here we are using the WMI object methods:
' To get the Machine Name
Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
PCName = objItem.Name
Next
'To get the Memory Values
On Error Resume Next
arrComputers = Array(PCName)
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objItem In colItems
If objItem.Name = "ProcessNameYouWant.exe" Then
VM = objItem.PageFileUsage/1024
End If
Next
Set MemItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In MemItems
If objItem.Name = "ProcessNameYouWant" Then
mem = objItem.WorkingSet/1024
peak = objItem.WorkingSetPeak/1024
End If
Next
Next
' To get the Machine Name
Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
PCName = objItem.Name
Next
'To get the Memory Values
On Error Resume Next
arrComputers = Array(PCName)
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objItem In colItems
If objItem.Name = "ProcessNameYouWant.exe" Then
VM = objItem.PageFileUsage/1024
End If
Next
Set MemItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In MemItems
If objItem.Name = "ProcessNameYouWant" Then
mem = objItem.WorkingSet/1024
peak = objItem.WorkingSetPeak/1024
End If
Next
Next
Wednesday, October 13, 2010
Add or Remove the Recovery Scenario dynamically from tge script
The below code is helpful in adding and removing the Recovery Scenario dynamically from the settings. This case would be particularly required in case where there is a looping of the recovery scenarios, i.e, a recovery scenario is triggered when inside another recovery scenario.
Here goes the code:
Set qtApp = CreateObject("QuickTest.Application")
Set qtTestRecovery = qtApp.Test.Settings.Recovery
'This part of the code is used to remove all the existing recovery scenarios associated with the test
If qtTestRecovery.Count > 0 Then
qtTestRecovery.RemoveAll
End If
' This is used to add the recovery scenarios. The first parameter is the location of the qrs file. 2nd parameter is the scenario name as given at the time of creating the recovery scenario and 3rd is the priority (used when multiplr scenarios need to be added. At that time we can have 1,2,3 etc)
qtTestRecovery.Add "E:\RecoveryScenario.qrs", "RecoveryScenario" , 1
For intIndex = 1 To qtTestRecovery.Count
qtTestRecovery.Item(intIndex).Enabled = True
Next
qtTestRecovery.Enabled = true
qtTestRecovery.SetActivationMode "OnError"
Set qtApp = Nothing
Set qtTestRecovery = Nothing
'Only if the below line of code is added the recovery scenario would be added to your code.
Recovery.Enabled= True
Here goes the code:
Set qtApp = CreateObject("QuickTest.Application")
Set qtTestRecovery = qtApp.Test.Settings.Recovery
'This part of the code is used to remove all the existing recovery scenarios associated with the test
If qtTestRecovery.Count > 0 Then
qtTestRecovery.RemoveAll
End If
' This is used to add the recovery scenarios. The first parameter is the location of the qrs file. 2nd parameter is the scenario name as given at the time of creating the recovery scenario and 3rd is the priority (used when multiplr scenarios need to be added. At that time we can have 1,2,3 etc)
qtTestRecovery.Add "E:\RecoveryScenario.qrs", "RecoveryScenario" , 1
For intIndex = 1 To qtTestRecovery.Count
qtTestRecovery.Item(intIndex).Enabled = True
Next
qtTestRecovery.Enabled = true
qtTestRecovery.SetActivationMode "OnError"
Set qtApp = Nothing
Set qtTestRecovery = Nothing
'Only if the below line of code is added the recovery scenario would be added to your code.
Recovery.Enabled= True
Subscribe to:
Posts (Atom)