How to determine the QTP test script name?
For reporting purposes, there may be a need for you to determine the current testscript name within the code. Below is the code. Please see this to get the code for determinining if the test is being executed from QC or not.
Public function sGetCurrentTestScriptName()
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTestName
if(IsExecutedFromQC()) then
sGetCurrentTestScriptName = qcutil.CurrentTest.Name
else
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
sGetCurrentTestScriptName = qtApp.Test.Name
Set qtApp = Nothing ' Release the Application object
end if
End Function
How to determine the IP address of local system?
Ofcourse, this is trivial. You open a command prompt and type IPCONFIG to see the ip address of the local system. On Linux System you would type ifconfig eth0 in a shell window to see the ip address in eth0. But how do we do this within QTP for automation purposes ? There are many ways. Below is one way to get the IP address.
Below is the code to obtain the ipaddress using WMI
Function LocalHostIPAddress()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set ColItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objitem In ColItems
strIP = Join(objitem.IPAddress, ",")
strIPAddress = strIP
Next
LocalHostIPAddress = strIPAddress
End Function
How to determine the date and time on a remote system using WMI ?
How to determine the date and time on a remote system using WMI ?
At times, there may be a need to sync your QTP client systems time with a remote system before executing a test. There are otherways to sync windows system time such as NTP servers. Below is one way to getting the target system time using WMI. Setting the local system time will be another function that I’ll post later.
Function tGetTargetSystemDateTime(ByVal hostname, ByVal username, ByVal password)
Reporter.Filter=3
tGetTargetSystemDateTime = ""
wbemImpersonationLevelImpersonate = 3
wbemAuthenticationLevelPktPrivacy = 6
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer _
(hostname, "root\cimv2",username ,password)
objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems
strTime = objItem.LocalDateTime
tGetTargetSystemDateTime = WMIDateStringToDate(strTime)
Exit For
Next
Set colItems = nothing
Set objWMIService = nothing
Set objLocator = nothing
Reporter.Filter=0
End Function
Private Function WMIDateStringToDate(ByVal strTime)
WMIDateStringToDate = CDate(Mid(strTime, 5, 2) & "/" & _
Mid(strTime, 7, 2) & "/" & Left(strTime, 4) _
& " " & Mid (strTime, 9, 2) & ":" & _
Mid(strTime, 11, 2) & ":" & Mid(strTime, _
13, 2))
End Function
-
Archives
- December 2010 (3)
- April 2009 (1)
- August 2008 (5)
- July 2008 (4)
- May 2008 (2)
- April 2008 (3)
- February 2008 (3)
-
Categories
-
RSS
Entries RSS
Comments RSS