Wednesday, October 24, 2007

Computer details....

Below script will tell you about your account details, OS details and installed printer details ->

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOS in colOSes
Wscript.Echo "Computer Name: " & objOS.CSName
Wscript.Echo "Caption: " & objOS.Caption 'Name
Wscript.Echo "Version: " & objOS.Version 'Version & build
Wscript.Echo "Build Number: " & objOS.BuildNumber 'Build
Wscript.Echo "Build Type: " & objOS.BuildType
Wscript.Echo "OS Type: " & objOS.OSType
Wscript.Echo "Other Type Description: " & objOS.OtherTypeDescription
Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "User Domain = " & WshNetwork.UserDomain
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
WScript.Echo "User Name = " & WshNetwork.UserName
Set objComputer = CreateObject("Shell.LocalMachine")
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 "Unlock enabled: " & objComputer.IsUndockEnabled
Set WshNetwork = WScript.CreateObject("WScript.Network")

Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo "Network drive mappings:"

For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
Next
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
Next

Set objWMIService = Nothing
Set WshNetwork = Nothing
Set colOSes = Nothing

Wednesday, October 10, 2007

How to load vbs file dynamically to QTP?

Public Sub Imports( ByVal fullFileNameStr )
Const ForReading = 1
Dim oFileDim
ReadAllTextFile
On Error Goto 0

If fullFileNameStr = vbNullstring Then
Reporter.ReportEvent micFail, “FileNotFoundException”, “Unable to find the specified file: ” & libName
Exit Sub
End If
Set oFile = FsoUtil.OpenTextFile( fullFileNameStr, ForReading )

ReadAllTextFile = oFile.ReadAll()
oFile.Close : Set oFile = Nothing

‘ ** Executing the text, to load file to memory.
ExecuteGlobal( ReadAllTextFile )

End Sub

Call the function as the follows

Imports “C:\Automation\MyFile.vbs”

qtp programmer

The software industry is at a level where the time spent to look down on earth seems crazy. Testing world is growing day by day and so the automation industry. QTP counts as one of the best available tools to be used for automation. But are we the users to use it we are the programmers to program it. Why just be happy with record and playback? Let's go ahead and learn all that makes QTP the best automation tool and us the best automation engineers.
Using Windows Shell scripts and the best of VB, let's take the biggest deal with QTP features.....


I start a code snippet "How to verify that a particular window appears at the center of monitor screen? "

' To verify that the 'X' window(.net application should be displayed at the center of the screen

intScreenabsx=SwfWindow("X").GetROProperty("abs_x")
intScreenabsy=SwfWindow("X").GetROProperty("abs_y")
intScreenHeight=SwfWindow("X").GetROProperty("Height")
intScreenWidth=SwfWindow("X").GetROProperty("Width")
blnCentered = IsWindowCentered(intScreenabsx,intScreenabsy,intScreenHeight,intScreenWidth)

If blnCentered= True Then
Reporter.ReportEvent micPass,"Test Step Passed","The window is displayed at the center of the screen"
Else
Reporter.ReportEvent micFail ,"Test Step Failed"," The window is not displayed at the center of the screen"
End If

Function IsWindowCentered(intABSX,intABSY,intHeight,intWidth)
Dim strComputer : strComputer = "." ' The local computer
Dim objWMIService ' objects to get the WMI service
Dim ItemsCollection ' objects used to get the collection of all items
Dim ObjItem
Dim intScreenHeight 'The actual screen resolution (height)
Dim intScreenWidth 'The actual screen resolution (Width)

'Following code is to get the the desktops resolution
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set ItemsCollection = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor")
For Each objItem in ItemsCollection
intScreenHeight = objItem.ScreenHeight
intScreenWidth=objItem.ScreenWidth
Next

'Verify whether the window is centered
If (cint(intABSX) +cint(intWidth/2)) =(cint(intScreenWidth/2)) And (cint(intABSY) +cint(intHeight/2)) =cint(intScreenHeight/2) Then
IsWindowCentered = True
Else
IsWindowCentered = False
End If
End Function