haripotter’s technorati

Just another WordPress.com weblog

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

December 28, 2010 Posted by | HP Quality Center and QTP | Leave a Comment

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

December 28, 2010 Posted by | HP Quality Center and QTP | Leave a Comment

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

December 28, 2010 Posted by | HP Quality Center and QTP | Leave a Comment

How to determine if a test is executed from Quality center test lab

Hmmm. I’m back after a long time.  Okay.. lets get started.. How do we know if the test is being executed from a testset in testlab module of HP Quality center ?.. During development of the test script, we have to execute the code to see if the testscript is performing the test the way we wanted it to. We execute them directly from QTP IDE, even though we have connected to QC from QTP IDE. Let’s say one of your function does something that is dependent on the testscript name. Usually we use qcutil.CurrentTest.Name to determine the testscript name. But if we are not connected to QC, then this call will fail. In that situation, if we want to know if the test is executed from QC or from local system, we can use this function. Here’s the function. Enjoy.. In another post, I’ll provide the code for determining the testscript name irespective of whether QTP is connected to QC or not.

Read more »

April 2, 2009 Posted by | HP Quality Center and QTP | Leave a Comment

How do we send email from QTP ?

We can send an email from a QTP testscript by using the below function. It uses CDO.Message object to perform that action. We use the SMTP Server to deliver the email message to the concerned email ID. Please update the values as per your environment. This function sends a email attachment to specified email address.
Read more »

August 8, 2008 Posted by | General, HP Quality Center and QTP | , , , | 7 Comments

How to reboot a Windows System using WMI ?

If you know the administrator password of a system that you are authorized to use, you can use this function to reboot it for some automation needs. please do not try this on systems that you are not authorized to use. I have shown only the function definition here. You can use this in a QTP function library.
Read more »

August 6, 2008 Posted by | Uncategorized | , , | Leave a Comment

How to map a network drive using vbscript ?

Sometime back I posted a code to disconnect a network drive using vbscript. Now here is the code to map a local drive to a network path. This again uses WScript.Network object to map the drive. We use the filesystem object to determine if the drive is already mapped. if yes, then disconnect it first and then map it to specified path. There are two functions. One will parse the arguments to make sure right number of parameters are passed to the script. Enjoy.
Read more »

August 5, 2008 Posted by | General | , | Leave a Comment

How do we use QC as Shared repository… ?

There was comment posted in this blog asking if we could use QC as a shared repository to store file and update it directly, without downloading to local desktop. I’m afraid that it is not possible to do without downloading the file to local desktop. But We certainly can use QC as a shared repository to store files and have it accessible to many tests. There are cases when multiple QTP tests may have a need to access the same file which is stored in the test’s project repository in QC. When we attach the file to a test, other tests will have to access this attachment through this test. Alternatively, a copy of the same file could be attached to each and every test. That would be a maintenance nightmare. So what would be the solution ? Read on…
Read more »

August 3, 2008 Posted by | HP Quality Center and QTP | , , , | Leave a Comment

How to disconnect a network drive using vbscript

Below is a script to disconnect a network drive using vbscript. We employ the services of WScript.Network object to do the same :) Enjoy!. There are two functions below. One is the actual disconnect drive and the other one is to parse the command line arguments. We want to make sure the drive letter that has to be disconnected, is specified as an input parameter to the script.
Read more »

August 2, 2008 Posted by | HP Quality Center and QTP | , , , , , | Leave a Comment

Executing a command on a remote windows system using WMI

Usually we use psexec tool from sysinternals to execute any program on a remote system. There is another way to execute a command on a remote windows system via WMI (Windows Management Instrumentation). This function would be beneficial to QTP automators because its a vbscript function and can be used in their function libraries (after some modifications). All you have to do is call this function with the target system name, username, password and the command to execute. The output would be the process if of the process that was initated on the target system. Have fun…

  Read more »

July 25, 2008 Posted by | HP Quality Center and QTP | , , , | 3 Comments

Follow

Get every new post delivered to your Inbox.