Sunday 8 June 2014

QTP - UFT - What is AOM ( Automation Object Model)

                                        Link to Mandatory QTP /UFT Interview Questions to read before Interview

AOM Stands for Automation Object Model 

You can use UFT Object Model to write programs that automate your UFT operations. The UFT Automation Object Model provides objects, methods, and properties that enable you to control UFT from another application.

You can now control virtually every UFT feature and capability using the objects, methods and properties included in the UFT Automation Object Model.

You can write an automation script to run a selected batch of tests. For each test, you can retrieve the associated add-ins list. Then, if the necessary add-ins are not already loaded, you can close UFT, load the necessary add-ins, reopen UFT and run the test.

You can define your settings for a test in UFT then click “Generate Script” in the Generate tab of the Test Settings dialog box to generate an automation script based on the current test settings. You can then apply those same settings automatically to multiple tests using the whole automation script or excerpts from the generated file.

                                        Link to Mandatory QTP /UFT Interview Questions to read before Interview

Wednesday 4 June 2014

QTP - UFT - What is the object needed to use sendkeys and show how to scroll up on the web page


We need to create an object of WScript.Shell

The below example shows how to use Page Up key to scroll up on the web page

Function navigateTOPageTop()
     Set o1 =Createobject("Wscript.Shell")
     browser("name:=browsername").Page("title:=.*")
.Highlight
     
For s =1to  4
        o1.SendKeys "{PGUP}"
     Next
     Set o1 =nothing
EndFunction 




Sunday 1 June 2014

QTP - UFT - How to handle multiple objects with same properties - example


Solution - Use Ordinal Identifiers

we can use the following ordinal identifiers depending on the object
1) Creation Time ( only for browsers)
2) Index
3) Location

here is a scenario that describes it. I have created two buttons with same properties and when you spy using object spy on the buttons object spy displays same object properties.

Here is the above snapshot html code ( Copy the code in notepad and save with extension html)

<html>
<Head> <title> Object Identification </title> </head>
<body>
<Center>
<br>When you use object Spy on both the objects the properties will be same.
<br>
<br><Input type=Button name="s1" value="Button1"></Input>
<br>
<br>
<br><Input type=Button name="s1" value="Button1"></Input>
</Center>
</body>
</html>

When you use object Spy the following is displayed

Object Spy - Properties of first button"Class Name:=WebButton",
"abs_x:=649",
"abs_y:=118",
"class:=",
"disabled:=0",
"height:=23",
"html id:=",
"html tag:=INPUT",
"innerhtml:=",
"innertext:=",
"name:=Button1",
"outerhtml:=<input name=""s1"" type=""Button"" value=""Button1"">",
"outertext:=",
"title:=",
"type:=button",
"value:=Button1",
"visible:=True",
"width:=68",
"x:=649",
"y:=63"

Object Spy - Properties of second button
"Class Name:=WebButton",
"abs_x:=649",
"abs_y:=178",
"class:=",
"disabled:=0",
"height:=23",
"html id:=",
"html tag:=INPUT",
"innerhtml:=",
"innertext:=",
"name:=Button1",
"outerhtml:=<input name=""s1"" type=""Button"" value=""Button1"">",
"outertext:=",
"title:=",
"type:=button",
"value:=Button1",
"visible:=True",
"width:=68",
"x:=649",
"y:=123"

If you ignore the "y" and "abs_y" property, rest of the properties are unique.

If you add these properties to Object Repository, UFT/QTP adds the objects to OR with ordinal identifiers as Index.

 
 

'when recording
Browser("Object Identification").Page("Object Identification").WebButton("Button1").Click
Browser("Object Identification").Page("Object Identification").WebButton("Button1_2").Click

' when using descriptive programming
Browser("name:=Object Identification").page("title:=Object Identification").webbutton("name:=Button1","Index:=0").Click
Browser("name:=Object Identification").page("title:=Object Identification").webbutton("name:=Button1","Index:=1").Click

 

QTP-UFT - How to Click on Links or Buttons in the Table Cell


How to click on Links or Buttons with in WebTable Cell or Table cell

Some time automation engineers may need to click on Button/Links/Images/Radio buttons/select items from List boxes in a given table cell. To achieve that goal uses can use the following

Syntax
Tableobject.ChildItem(row,column,micclass,index)

Note:- micclass field is case sensitive.
Index will start from zero and will vary by no of similar objects in the given cell.

Below is the an example which can give an overview how it works

 
Note :- If you are looking to reproduce the table above copy the below code and save the code in notepad with file extension as "html"
 
<html>
<body>
<table border="1">
<TR><TD>Sample Buttons</TD><TD> Demo </TD></TR>
<TR><TD><Center><Input type=Button name="s1" value="Button1"></Input><Input type=Button name="s1" value="Button1"></Input></Center></TD><TD> Demo </TD></TR>
<TR><TD>Two Buttons in the same table cell</TD><TD> Demo </TD></TR>
</table>
</body>
</html>
 
The above table contains two columns with three rows.

QTP Code to click on WebButtons
' To click on the first button
Set objButton1 = Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",0)
objButton1.highlight
objButton1.click

' To click on the second button
Set objButton2 = Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",1)
objButton2.highlight
objButton2.click


Alternatively we can use the below code
' To click on the first button
Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",0).Click
' To click on the second button
Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",1).Click


The same concept will apply for WebLink or Images etc but the Micclass will change in the ChildItem method

If you are looking to handle WebLinks then
' To click on the first link
Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"Link",0).click
' To click on the second link
Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"Link",1).click

If you are looking to handle Images then
' To click on the first image
Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"Image",0).click
' To click on the second image
Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"Image",1).click

Also Note that Index value in the childItem method will vary depending on the number of similar objects present in the cell.