About Me

Gaurav Seth is a a Senior Automation Test Analyst with experience in QTP, Selenium and Ranorex tools and currently working on Automating in C# for a FX trading Client

Java Table - Click any Cell

' Following Snippet of Code will click any Cell Randomly in the Column 1 in the Java Table. a ( Row) is generated randomly and column is fixed 1



tname=Fn_Get_Object_Name(tablename)
Dim a
a=Int((15-0+1)*Rnd+2)

JavaWindow("title:="&whome).JavaTable("tagname:="&tname,"abs_y:=601").ClickCell a,1,"LEFT"

Java Table - Select a Row

Following snippet of code will select a Row in a Java Table using Regular Expressions. It will search for rows where allercalm medicine has been prescribed and select this row

rows=JavaWindow("SystmOne GP: VNISThreeTester").JavaTable("View").GetRoProperty("rows")
cols=JavaWindow("SystmOne GP: VNISThreeTester").JavaTable("View").GetRoProperty("cols")
For i =0 to rows-1
data=JavaWindow("SystmOne GP: VNISThreeTester").JavaTable("View").GetCellData(i,"Drug")
searchval="allercalm"
Dim ObjRegExp
Set ObjRegExp=new regexp
ObjRegExp.pattern=searchval
ObjRegExp.Global=True
ObjRegExp.IgnoreCase=True
Set matches=ObjRegExp.Execute(data)
For each objmatch in matches
tmpVar=objmatch.value
If searchval=tmpVar Then
JavaWindow("SystmOne GP: VNISThreeTester").JavaTable("View").SelectRow(i)
Exit For
End If
Next
Next





HP QTP FAQ 2

In what situations QTP will not recognize the Objects or it finds that two objects have same name ?

QTP provides two options for object identification Tool->Object Identification it provides a furthur option under it called smart Identification..u can configure it to recognize the objects which are not recognised by QTP normally!!

QTP has a unique feature called Smart Object Identification/recognition. QTP generally identifies an object by matching its test object and run time object properties. QTP may fail to recognise the dynamic objects whose properties change during run time. Hence it has an option of enabling Smart Identification, wherein it can identify the objects even if their properties changes during run time.

Check this out-

If QuickTest is unable to find any object that matches the recorded object description, or if it finds more than one object that fits the description, then QuickTest ignores the recorded description, and uses the Smart Identification mechanism to try to identify the object.

While the Smart Identification mechanism is more complex, it is more flexible, and thus, if configured logically, a Smart Identification definition can probably help QuickTest identify an object, if it is present, even when the recorded description fails.

The Smart Identification mechanism uses two types of properties:

Base filter properties—The most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object. For example, if a Web link's tag was changed from to any other value, you could no longer call it the same object.

Optional filter properties—Other properties that can help identify objects of a particular class as they are unlikely to change on a regular basis, but which can be ignored if they are no longer applicable.


How to handle dynamic objects in QTP?
1. Dynamic object is an object which changes its properties at the run time and thus its mandatory properties cant be predicted from the starting.
To automate these objects properties objects should be used. Here a property object is created using the description class.
Set Obj1 = Description.Create()
n then you can assign the name and title values to this custom object and these values can be captured during the runtime and hence using these values this custom object will identify the dynamic object in your application.
2. Regular Expression solves the problem of dynamic values in QTP.
3. GETROProperty

How many types of Actions are there in QTP?

There are three kinds of actions:
Non-reusable action—an action that can be called only in the test with which it is stored, and can be called only once.

Reusable action—an action that can be called multiple times by the test with which it is stored (the local test) as well as by other tests.

External action—a reusable action stored with another test. External actions are read-only in the calling test, but you can choose to use a local, editable copy of the Data Table information for the external action.

What is the difference between Call to Action and Copy Action.?

Call to Action : The changes made in Call to Action , will be reflected in the orginal action( from where the script is called).But where as in Copy Action , the changes made in the script ,will not effect the original script(Action)

What are the Test Objects and the Run Time Objects and the difference between them

Test objects are basic and generic objects that QTP recognize. Run time object means the actual object to which a test object maps.
Can i change properties of a test object

Yes. You can use SetTOProperty to change the test object properties. It is recommended that you switch off the Smart Identification for theobject on which you use SetTOProperty function.
Can i change properties of a run time object?

No (but Yes also). You can use GetROProperty(“outerText”) to get the outerText of a object but there is no function like SetROProperty tochange this property. But you can use WebElement().object.outerText=”Something” to change the property.

Library Files or VBScript Files
How do we associate a library file with a test ?


Library files are files containing normal VBScript code. The file can contain function, sub procedure, classes etc.... You can also use executefile function to include a file at run-time also. To associate a library file with your script go to Test->Settings... and add your library file to resources tab.

PDF Manipulation with QTP

We can Use LearnQuickTestPDF to Manipulate PDF Using QTP

Download http://www.mediafire.com/?y1ytzwmerly
and run exe to extract file to hard drive, extract to “C:\LearnQTP”.
Open directory LearnQuickTestPDF and find the Install.vbs, this will make the API ready to use. But before this, read the terms and conditions first and then execute the install.vbs file by double clicking it. Accept terms and condition by clicking on ‘Yes’ button and proceed. That’s it you are now ready to use this into QTP.

Use this in the same way you do with other COM APIs.

Once we get the object, we can now proceed with using different methods to manipulate the documents

Set oPDF=createobject("LearnQuickTest.ManipulatePDF")

1. ' Get the Text of PDF . The Second Parameter is the Start Page and Third End Page

Print oPDF.GetPdfText ("C:\LearnQTP\LearnQuickTestPDF\fw4.pdf", 1,2)

2. ' Get the No of Pages of the PDF
Print oPDF.GetNumberOfPages ("C:\LearnQTP\LearnQuickTestPDF\fw4.pdf")

Windows Registry with QTP

The following snippet of code will create an entry in the Registry and give the Value to it.

Sub SetRegistryValue(strRegPath, strRegValue)
Set shObj = CreateObject("WScript.Shell")
shObj.RegWrite strRegPath, strRegValue
End Sub

Function GetRegistryValue(strRegPath)
Set shObj = CreateObject("WScript.Shell")
GetRegistryValue = shObj.RegRead(strRegPath)
End Function


SetRegistryValue "HKEY_CLASSES_ROOT\.ANUNAY\KEY2", "http://hpqtpautomation.blogspot.com/"
Msgbox GetRegistryValue("HKEY_CLASSES_ROOT\.ANUNAY\KEY2")






'You can use the Following Code to delete the Registry Entry
Set shObj = CreateObject("WScript.Shell")
shObj.RegDelete "HKEY_CLASSES_ROOT\.ANUNAY\KEY"


XML With QTP

Following Snippet of code will Print the contents of the XML File

Set xmlObj = XMLUtil.CreateXML()
xmlObj.LoadFile("C:\artifacts.xml")
Print xmlObj.ToString()
'Using a XML file stored on the hard drive




' This will Load any Web Page into an XML File and Print to see the ContentsSet xmlObj = XMLUtil.CreateXML()
xmlObj.LoadFile("http://www.w3schools.com/xml/cd_catalog.xml")
Print xmlObj.ToString()






'The Following Snippet of Code will create an XML File and add Chidren (Nodes) including values
Set doc = XMLUtil.CreateXML()

doc.CreateDocument "Papa"

Set root = doc.GetRootElement()
root.AddChildElementByName "Bambino","Valuable"

doc.SaveFile "C:\one..xml"


' The Following snippet of code will Load an XML File and Save it to another place giving it a different name
Set doc = XMLUtil.CreateXML()

doc.LoadFile "C:\artifacts.xml"

doc.SaveFile "C:\artifacts1.xml"

' Following snippet of code will display the name of the particular child and display the occurences of this
Set doc = XMLUtil.CreateXML()

doc.LoadFile "C:\artifacts.xml"

Set root = doc.GetRootElement()

Set children = root.ChildElements()

if children.Count() <> 0 then

Set firstChild = children.Item(2)

firstChildName = firstChild.ElementName()

Set sameNameChildren = children.AllItemsByName(firstChildName)

msg = "My first child name is " + firstChildName + " and I have " + FormatNumber(sameNameChildren.Count(),0) + " of them."

End If

msgbox msg


' Using the below snippet of code in the Above Mentioned XML will tell you how many children (nodes) does XML Have.
msgbox (children.count)


Parsing the XML

Once we have the XML data loaded with the XML object pointing to it, our job is very simple. We need to navigate through the structure looking for the data we want. In this example we wish to retrieve all the data related a particular CD in the CD Catalog. So what we do is that we utilize the ChildElementsByPath(Path) method do retrieve the data from each element of the XML. Here, "Path" is something common to the kind of path we specify in our PC for locating a particular file. Here, each XML tag can be considered as a folder with the XML Element value as a file. So the topmost folder becomes CATALOG, then comes CD, then (TITLE, ARTIST, COUNTRY, COMPANY, PRICE,YEAR) become the individual folders with CD. So in case you wish to find the Title of a particular CD, you use ChildElementsByPath("/CATALOG/CD/TITLE"). This will actually return a collection of titles of all the Cds and you can iterate through each to get your desired CD title. A similar approach may be employed for getting the other data like, artist, company, price and year. This is just a simple example, there are a number of other XMl methods in QTP that can be used as well. Have a look at the code below -


Set xmlObj = XMLUtil.CreateXML()
xmlObj.LoadFile("http://www.w3schools.com/xml/cd_catalog.xml")
Print xmlObj.ToString()
Print " ========================================================================= "


Set myCDTitle= xmlObj.ChildElementsByPath("/CATALOG/CD/TITLE")
'Get the titles
Set myCDArtist = xmlObj.ChildElementsByPath("/CATALOG/CD/ARTIST")
'Get the Artists
Set myCDCountry = xmlObj.ChildElementsByPath("/CATALOG/CD/COUNTRY")
'Get the Country
Set myCDPrice = xmlObj.ChildElementsByPath("/CATALOG/CD/PRICE")
'Get the Prices
Set myCDYear = xmlObj.ChildElementsByPath("/CATALOG/CD/YEAR")
'Get the Year

'Now iterate through the collection to get the values
For i = 1 to myCDTitle.Count
Print myCDTitle.Item(i).Value()
Print myCDArtist.Item(i).Value()
Print myCDCountry.Item(i).Value()
Print myCDPrice.Item(i).Value()
Print myCDYear.Item(i).Value()
Print " "
Next

Windows Scripting

There are some Web/Windows objects which will perform actions when certain key commands, such as CTRL+SHIFT+ESC are entered. These Web/Windows objects do not have a type method associated with them that can be used to replay these keys. In these cases you can use SendKeys method to send keyboard input to your application.
Download and install the Windows Scripting Host.

1. Create a WScript.Shell object.
2. Activate the browser in which you want to execute the keys.
3. Use the SendKeys method to type the key combination.

Example:

' This code executes the CTRL+F key combination (search) on a browser.
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Put the label of the browser" ' Activate the browser window
wait(3)
WshShell.SendKeys "^f" ' The caret (^) represents the CTRL key.
wait(2)
The SendKeys method will send keystroke(s) to the active window. To send a single character (for example, x), use "x" as the string argument. To send multiple characters (for example, abc), use "abc" as the string argument. You can also send special characters such as SHIFT, CTRL, and ALT, which are represented by the plus sign (+), the caret (^), and the percent sign (%), respectively.



' Below Piece of Snippet will Type in the notepad

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Notepad"
WshShell.AppActivate "Notepad"
wait (3)
WshShell.SendKeys "x"

'Below Piece of code will open the Page Setup from the Notepad

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Notepad"
WshShell.AppActivate "Notepad"
wait (3)
WshShell.SendKeys "%f"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Down}"
WshShell.SendKeys "{Enter}"

Delete browser Cookies

We can use WebUtil.(Method)

webutil.DeleteCookie
or

webutil.DeleteCookies

Automating MS Word Documents

Following Snippet will inform you how to add a Text to the Tables in the Word document.

Set oWord = CreateObject("Word.Application")
oWord.Visible = True

Set oDoc = oWord.Documents.Add()
Set oRange = oDoc.Range()
oDoc.Tables.Add oRange,1,3
Set objTable = oDoc.Tables(1)
objTable.style = "Table Grid"

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process")

nRow = 1
objTable.Cell(nRow, 1).Range.Font.Bold = True
objTable.Cell(nRow, 1).Range.Text = "Process"
objTable.Cell(nRow, 2).Range.Font.Bold = True
objTable.Cell(nRow, 2).Range.Text = "Description"
objTable.Cell(nRow, 3).Range.Font.Bold = True
objTable.Cell(nRow, 3).Range.Text = "Path"

For Each objItem in colItems

nRow = nRow + 1
objTable.Rows.Add()
objTable.Cell(nRow, 1).Range.Font.Bold = True
objTable.Cell(nRow, 1).Range.Text = objItem.Name
objTable.Cell(nRow, 2).Range.text = objItem.Description
If objItem.Executablepath <> "" then objTable.Cell(nRow, 3).Range.text = objItem.Executablepath
Next

QTP - Menu bar / Menu Items missing

To enable missing items or display all menu items in the menu bar, follow the following steps:-

1. Go to Start page of QTP
2. Go to Tools-->Options
3. In the general section, click on Restore Layout button.