Tuesday, December 15, 2015

UFT

HP Unified Functional Testing (UFT) software, formerly known as HP QuickTest Professional (QTP), provides functional and regression test automation for software applications and environments. HP Unified Functional Testing can be used for enterprise quality assurance.

Saturday, October 10, 2015

Activate an Edit Box's Native Focus Method

Sub Object_Example()
'The following example uses the .Object property to activate an
'edit box's native focus method:

Set MyWebEdit = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").Object
MyWebEdit.focus

End Sub

Input Parameter vs Output Parameter


Sunday, September 27, 2015

Reporter Object || Results Formatting

Description
The object used for sending information to the test results.
Associated Methods

  • ReportEvent Method
  • Syntax
    Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]
  • Examples
    The following examples use the ReportEvent method to report a failed step.
    Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."
    or
    Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."
    The following example uses the ReportEvent method to include a captured bitmap in the test results.
    Browser("Browser").Page("WebPage").Image("MyLogo").CaptureBitmap("MyLogo.bmp")
    Reporter.ReportEvent micDone, "Display Logo", "This is my logo", "MyLogo.bmp"
  • Status of the Test Results step:
    0 or micPass: Causes the status of this step to be passed and sends the specified message to the Test Results window.
    1 or micFail: Causes the status of this step to be failed and sends the specified message to the Test Results window. When this step runs, the test fails.
    2 or micDone: Sends a message to the Test Results window without affecting the pass/fail status of the test.
    3 or micWarning: Sends a warning message to the Test Results window, but does not cause the test to stop running, and does not affect the pass/fail status of the test. 
Associated Properties


  • Filter Property
  • Syntax
  • Reporter.Filter = NewMode
  • Reporter.ReportEvent micGeneral, "2", ""
    Reporter.Filter = rfDisableAll 
  • Mode
    Description
    0 or
    rfEnableAll
    Default. All reported events are displayed in the Test Results.
    1 or rfEnableErrorsAndWarnings
    Only event with a warning or fail status are displayed in the Test Results.
    2 or
    rfEnableErrorsOnly
    Only events with a fail status are displayed in the Test Results.
    3 or
    rfDisableAll
    No events are displayed in the Test Results. 

  • ReportPath Property
  • Description
    Retrieves the folder path in which the current test's results are stored.
    Note: Do not use this property to attempt to set the results folder path.
    Syntax
    Path = Reporter.ReportPath
    Argument
    Type
    Description
    Path
    String
    The folder path in which the current test's results are stored.
    Example
    The following example uses the ReportPath property to retrieve the folder in which the results are stored and displays the folder in a message box.
    dim Path
    Path = Reporter.ReportPath
    MsgBox (Path) 

  • RunStatus Property
  • Description
    Retrieves the run status at the current point of the run session. For tests, it returns the status of current test during the test run. For business components, it returns the status of current business component (not the entire business process test).
    Syntax
    Reporter.RunStatus
    Example
    The following example uses the RunStatus property to retrieve the status of the run session at a specific point and exit the action if the test status is fail. If the test status is not fail, the test run continues.
    If Reporter.RunStatus = micFail Then ExitAction

  • Source: QuickTest Professional Help 

Thursday, September 3, 2015

How to work with Windows registry

To work with Windows registry using WScript.Shell object.


If you want to read a specific Key from registry
Set wscriptObj=createobject("WScript.Shell")
objProperties=wscriptObj.RegRead("HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\")
msgbox objProperties
The above will give you the "Default" property value

If you want to read a specific property name in the registry:
objProperties=wscriptObj.RegRead("HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\Sync")

If you want to update a specific property value in the registry:
wscriptObj.RegWrite "HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\Sync",0,"REG_DWORD"

If you want to delete a specific property from the registry:
wscriptObj.RegDelete "HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\Sync"


You can also use DotNetFactory to retrieve any retrieve any value
registryPath1="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE"
'Here i am creating an instance of DotNet Factory computer object
Set objDFComputer=DotNetFactory("Microsoft.VisualBasic.Devices.Computer","Microsoft.VisualBasic")
'Here i am creating an instance of Registry Object
Set objRegistry=objDFComputer.Registry
'The below will retrieve the "Default" Property
print objRegistry.GetValue(registryPath1,"","")

'The below retrieves the property of the regsitry
print objRegistry.GetValue(registryPath1,"Path","")
Set objRegistry=nothing
Set objDFComputer=nothing

Tuesday, August 11, 2015

How to copy content to Clipboard

Using Mercury.Clipboard:

'Creates an instance of Mercury.Clipboard
set objCB=createobject("Mercury.Clipboard")
'Here i am clearing already existing content in clipboard
objCB.Clear()
'Copying some text into Clipboard
objCB.SetText("Hello Uday")
'Retrieving the content from Clipboard
print objCB.GetText

Using DotNetFactory:
'Creates an instance of DotNetFactory Computer Object
Set objDFComputer=DotNetFactory("Microsoft.VisualBasic.Devices.Computer","Microsoft.VisualBasic")
'Here i am clearing already existing content in clipboard
Set objCB=objDFComputer.ClipBoard
objCB.clear()
'Copying some text into Clipboard
objCB.SetText("Hello Uday")
'Retrieving the content from Clipboard
print objCB.GetText

Sunday, August 2, 2015

CPU Utilization

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Get the CPU utilization %
myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"
For Each objItem in objWMIService.ExecQuery(myQuery)
   print "Processor time " & objItem.PercentProcessorTime & "  %"
next

'Get the total Physical Memory
myQuery="Select * from Win32_ComputerSystem"
Set colItems = objWMIService.ExecQuery(myQuery)
For each objitem in colItems
    print "Total Physical Memory "&objitem.TotalPhysicalMemory/1024
Next

'Get the total available physical memory
myQuery="Select * from Win32_PerfFormattedData_PerfOS_Memory"
Set colItems = objWMIService.ExecQuery(myQuery)
For Each objItem in colItems
    print "Available GB: " & objItem.AvailableKBytes
Next

Saturday, May 30, 2015

Execute QTP scripts in a remote machine when the window is minimized

QTP Version : 11 or later

RDP Version : 6 or later

If you want to run QTP scripts run on a remote machine and if that Remote machine/Window is minimized, then the scripts will fail.

In order to overcome the issue, you need to add a registry key in Windows registry on your client machine/from the machine where you initiating the remote desktop.
1. Close all your remote desktops.
2. Create a registry "RemoteDesktop_SuppressWhenMinimized" if does not exist in the below path:
   HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized
   or
   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized
3. Set the value for this data to 2.

If you would like to add the registry key by just running a .reg file follow below steps:
1. Open Notepad.
2. Cope the below content:
 Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002
3. Save the file as "FileName.reg" format
4. Now, double click on this reg file, so that registry keys will be added.

Tuesday, April 14, 2015

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

Monday, January 12, 2015

Working with File System Objects (FSO)

Option Explicit

Const DeleteReadOnly = True 
Dim oFSO, oDrive, sFileName

Set oFSO   = CreateObject("Scripting.FileSystemObject") 
sFileName  = ".exe"

For Each oDrive In oFSO.Drives 
  If oDrive.DriveType = 2 Then Recurse oFSO.GetFolder("F:\")
Next 

Sub Recurse(oFolder)
  Dim oSubFolder, oFile
wscript.echo oFolder.name
  If IsAccessible(oFolder) Then
    For Each oSubFolder In oFolder.SubFolders
     Recurse oSubFolder
    Next 

    For Each oFile In oFolder.Files
        sFileName = oFolder.name & ".exe"
      If oFile.Name = sFileName Then
        oFile.Delete ' or whatever
      End If
    Next 
  End If
End Sub

Function IsAccessible(oFolder)
  On Error Resume Next
  IsAccessible = oFolder.SubFolders.Cont >= 0
End Function

Saturday, January 10, 2015

Working With Dictionary Objects

Object that stores data key, item pairs.

A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

Methods

Add Method (Dictionary) | Exists Method | Items Method | Keys Method | Remove Method | RemoveAll Method

Properties

Count Property | Item Property | Key Property

Dim d   ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens"   ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"

Functions can return a dictionary object and it can indeed use to return multiple values from a Functions. Alternately Function can return multiple value using Array as well 


Dim dicObj
Set dicObj = CreateObject("Scripting.Dictionary")

Set obj=getname
MsgBox(obj.item("name"))


Public Function getname()
dicObj.add "name","Uday Kumar"
Set getname=dicObj
End function

Tuesday, January 6, 2015

Using Excel as Database

Option Explicit
Dim objConn,objRS
 
Set objConn = CreateObject("ADODB.Connection") 
Set objRS = Createobject("ADODB.Recordset")

objConn.Open "Driver={Microsoft Excel Driver (*.xls),(*.xlsx)(*.xlsm),(*.xlsb)};DBQ=C:\USERS\Desktop\FileName.xlsx;"
objRS.Open "Select [UN],[PW] FROM [TABLE1$]", objConn

Do while not objRS.EOF
 Browser("Gmail").WebEdit("username").Set objRS.FIELDS("UN")
 Browser("Gmail").WebEdit("password").Set objRS.FIELDS("PW")
 Browser("Gmail").WebBotton("LogIn").CLICK
 objRS.MOVENEXT
Loop

'Release created objects
Set objRS= NOTHING
Set objConn= NOTHING


Note: The database we are using here is MS Excel2007(*.xlsx). Create a table/sheet name in MS Excel2007 called "TABLE1" and column 'names as "UN" and "PW" and path of the table which we create is C:\USERS\Desktop\FileName.xlsx.