Saturday, 12 October 2013

#12. Arrays v/s Collections in QTP

Arrays v/s Collections in QTP:-
1. Arrays are of fixed size.
   Dim arr(3)
   arr = Array(3,1,5)
1. Collections are growable in size.
   Set col = Browser("").Page("").WebEdit("").GetToProperties()
2. For memory usage, Collections are recommended to use instead of Arrays. Because a Collection object uses less memory than an array.
3. Performance wise, arrays are preferred over collections.
4. Arrays can hold basic data types. Whereas, collections can hold only objects.

Properties of a collection:-
   col.Count
   col(i).Name
   col(i).Value
   col(i).RegularExpression
Methods of an array:-
   UBound(arr); LBound(arr)

Sunday, 19 May 2013

#11. hoverMouse

Function hoverMouse(objName)
   Set obj = findObject(objName)   'findObject is a function to return a given object.
   Set dRep = CreateObject("Mercury.DeviceReplay")
   x = obj.GetROProperty("abs_x")
   y = obj.GetROProperty("abs_y")
   dRep.MouseMove x,y
   Set dRep = Nothing
End Function

abs_x - absolute value of x coordinate
x - coordinate x relative to the parent object.

#10. How to check hidden objects.

QTP shows that an object exists but it is not visible on the screen. Then how to prove whether object exists or not.

Function  isHiddenObject(objName)
   Set obj = findObject(objName)
   w = obj.getROProperty("width")
   h = obj.getROProperty("height")
   x = obj.getROProperty("x")
   y = obj.getROProperty("y")
   If w = 0 and h = 0 and x = 0 and y = 0 Then
      isHiddenObject = True
   End If
End Function

#7. Few Interview Questions on QTP

1. Your experience in QTP, that is, projects worked on.
2. Framework used.
3. Functions in string handling.
4. Order in which QTP uses different methods to recognize an object. - DVSO, that is, Descriptive Properties -> Visual Relational Identifier -> Smart Identification -> Ordinal Identifier.
5. If QTP is unable to recognize object thru DVSO then how will the object be recognized. - thru descriptive prog., virtual objects etc.
6. Explain SetTOProperty, GetTOProperty.
7. Distinguish between Output Value and Checkpoints.
8. How to use virtual objects.
9. Steps to open a given browser at a particular url.
10. How to write a SQL connection thru QTP.
11. DNL and DNL less connection.
12. Difference between Absolute Path and Relative Path.
13. If an object is not visible on web page but QTP says it exists then how to make sure that it exists.
- should be familiar with Data Driven, Keyword and Hybrid Frameworks.
Manual Testing
1. 6 phases in Bug Life Cycle.
2. Difference between - Smoke Testing, end-to-end testing, and Sanity Testing.
3. What is a deferred defect.
4. What is RTM. - Requirements Traceability Matrix.


> “Output Values” are used to retrieve values for later use and so it will retrieve the property values you select and place them in the datatable for you.
> Checkpoints are primarily used to see if the property values of an object have changed from an anticipated value, or state in the application.  Like: has my button moved, is the edit field enabled or disabled, what is the current default value in the edit field, etc.  In addition, checkpoints have the ability to use parameters in order to handle dynamic situations so you don’t have to hardcode a value in the checkpoint.

Saturday, 18 May 2013

#6. Function can return an array and an object too.

Function returning an array:-
Function arr()
   a = Array(3,1,5)
   arr = a
End Function
b = arr()
msgbox b(1)
'prints 1.

Function returning an object:-
Function getPage()
   Set getPage = Browser("creationTime:="&getBrowserIndex()).Page("title:=.*")
End Function
'getBrowserIndex is function that returns current index of browser.

Friday, 10 May 2013

#4. RegisterUserFunc - How to Register a function?

#4. RegisterUserFunc - To add or change the behaviour of an existing test object method during a run session.
FUNCTION BrowserActivate(OBJECT)
   DIM hWnd
   hWnd = OBJECT.GetROProperty("hwnd") 'hwnd is a Windows Handle
   ON ERROR RESUME NEXT
   Window("hwnd:=" & hWnd).Activate
   IF ERR.NUMBER <> 0 THEN
     Window("hwnd:=" & Browser("hwnd:=" & hWnd).OBJECT.hWnd).Activate
     ERR.CLEAR
   END IF
   ON ERROR GOTO 0
END FUNCTION
RegisterUserFunc "Browser", "Activate", "BrowserActivate"
Browser("micClass:=Browser","index:=0").Activate
- BrowserActivate Function would be used to create Activate method for the Browser class.

Tuesday, 7 May 2013

#3. To compare two given files through QTP

'#3. To compare two given files through QTP
'Return True if files are identical. Return False if files are different.
'COMMANDS INVOLVED-
'Set fso = CreateObject("Scripting.fileSystemObject")
'Set file1 = fso.GetFile(filePath1)
'file1.Size
'Set file1Txt = file1.OpenAsTextStream
'DO WHILE file1Txt.ATENDOFSTREAM = FALSE
'str1 = file1Txt.READ(1000)
filePath1 = "U:\Automation\QTP Notes\Screen1.png"
filePath2 = "U:\Automation\QTP Notes\Screen2.png"
filePath3 = "U:\Automation\QTP Notes\Tasks.txt"
msgbox compareFiles(filePath1, filePath3)
Function compareFiles(filePath1, filePath2)
 Set fso = CreateObject("Scripting.fileSystemObject")
 Set file1 = fso.GetFile(filePath1)
 Set file2 = fso.GetFile(filePath2)
 If file1.Size <>  file2.Size   then
    msgbox "Files are different."
 else
  Set file1Txt = file1.OpenAsTextStream
  Set file2Txt = file2.OpenAsTextStream
  compareFiles = True
        DO WHILE file1Txt.ATENDOFSTREAM = FALSE
   str1 = file1Txt.READ(1000)
   str2 = file2Txt.READ(1000)
   compareFiles = STRCOMP(Str1, Str2, 0)
   If compareFiles <> 0 Then
    compareFiles = False
    EXIT DO
   else
    compareFiles = True
   END IF
  LOOP
 End If
End Function

Monday, 6 May 2013

#2. To run a QTP Test from a .vbs file

'#2. To run a QTP Test from a .vbs file
set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible =True
qtApp.Open <Test Path>
Set qtTest = qtApp.Test
qtTest.Run
qtTest.Save
qtTest.Close
qtApp.Quit
Set qtApp = Nothing
Set qtTest = Nothing

#1. To close all opened browsers

'#1. To close all opened browsers
Set desc = Description.Create
desc("micClass").Value = "Browser"
Set objBrowser = Desktop.ChildObjects(desc)
for i = 0 to objBrowser.Count-1
   objBrowser(i).Close
next