Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
light example
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
[b]Hi I have written the below shown code in seprate function library file so that I can remove the use of Object repository.

'##################################
'#Dialog
'##################################
Code:
Public Sub DPDialog(strlnDialogName,strnProp)
    objDialog =  strlnDialogName
    Set obj_Dialog = Description.Create  
    obj_Dialog ("Class Name").value = "Dialog"
    obj_Dialog ("regexpwndtitle").value= strlnDialogName    

    If strnProp = "Click"  Then ' Click Property
        Dialog(strlnDialogName).Click
    End If
    
End Sub


'####################################
'# WinEdit
'####################################

Code:
Public sub DBWinEdit(strenWinEdit,strlnValue,strnProp)
        Set obj_WinEdit = Description.Create  
        obj_WinEdit ("Class Name").value = "WinEdit"
        obj_WinEdit ("attached text").value= strenWinEdit        

      If  strnProp = "Set" Then ' Set Property
           Dialog(obj_Dialog).WinEdit(obj_WinEdit).Set strlnValue
      End If
          
End Sub

'######################################
'# WinButton
'######################################
Code:
Public Sub DPWinButton(strWInButton,strnProp)
        Set obj_WinButton= Description.Create  
        obj_WinButton ("Class Name").value = "WinButton"
        obj_WinButton ("regexpwndtitle").value= strWInButton        

        If strnProp ="Click" Then ' Click Property
            Dialog(obj_Dialog).WinEdit(obj_WinButton).Click
       End If
    
End Sub

'##############################################
Now I have written the below code to use the above functions and taking the object's name and its property from Excel sheet.



Code:
Call OpenExcel(sFileName, vSheet) 'Open Data File
              object = ReadExcelDataSingle(sFileName, Row, "Object", vSheet)
    Call CloseExcel(sFileName) 'Close Data File
    
   If  object = "Dialog" Then
       Call OpenExcel(sFileName, vSheet) 'Open Data File
       winName =  ReadExcelDataSingle(sFileName, Row, "ObjectName", vSheet)
       objProperty = ReadExcelDataSingle(sFileName, Row, "Property", vSheet)
       Call CloseExcel(sFileName) 'Close Data File
       Call  DPDialog(winName,objProperty)
   End If
    
    If  object = "WinEdit" Then
        Call OpenExcel(sFileName, vSheet) 'Open Data File
        objName = ReadExcelDataSingle(sFileName, Row, "ObjectName", vSheet)
        objProperty = ReadExcelDataSingle(sFileName, Row, "Property", vSheet)
        objVal = ReadExcelDataSingle(sFileName, Row, "Value", vSheet)
       Call CloseExcel(sFileName) 'Close Data File
       Call DBWinEdit(objName,objVal,objProperty)
    End If

   If  object = "WinButton" Then
         Call OpenExcel(sFileName, vSheet) 'Open Data File
         objName = ReadExcelDataSingle(sFileName, Row, "ObjectName", vSheet)
         objProperty = ReadExcelDataSingle(sFileName, Row, "Property", vSheet)
         Call CloseExcel(sFileName) 'Close Data File
         Call DPWinButton(objName,objProperty)
  End If

##############################################

When I remove Object Repository refrence the code doesnot work.
Can Anyone tell what is wrong in above code.
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi,
Have you associated this function library with the test where you are call these functions ?

Regards
Sridhar
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
You are using one object reference in your script and using that object reference to point to the object under test.

It should be like this:

Code:
Public Sub DPDialog(strlnDialogName,strnProp)

    Set obj_Dialog = Description.Create
    obj_Dialog ("micclass").value = "Dialog"
    obj_Dialog ("regexpwndtitle").value= strlnDialogName
    If strnProp = "Click" Then ' Click Property
        Dialog(obj_Dialog).Click
    End If

End Sub

For WinEdit and WinButton: You have not defined what 'obj_Dialog' is. The description for Dialog is pointing to an illegal description. Remember that you are not transferring the description of the Dialog Box to these two Subs. This is one way it can be done:

Code:
Public sub DPWinEdit(strenWinEdit,strlnDialogName,strlnValue,strnProp)

    Set obj_WinEdit = Description.Create
    obj_WinEdit ("Class Name").value = "WinEdit"
    obj_WinEdit ("attached text").value= strenWinEdit

    Set obj_Dialog = Description.Create
    obj_Dialog ("Class Name").value = "Dialog"
    obj_Dialog ("regexpwndtitle").value= strlnDialogName

    If strnProp = "Set" Then ' Set Property
    Dialog(obj_Dialog).WinEdit(obj_WinEdit).Set strlnValue
    End If

End Sub
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
Yes I have associated this function library with the test. The second piece of code is in my test.

Scenerio is like this:
I have an Excel sheet in which I provide following columns
TestPurpose Object ObjectName Property Value
Login Dialog Login Click WinEdit Agent Name: Set ABCD
WinEdit Password: Set mercury
WinButton OK Click
Verification Window Flight Reservation Exist


Now I have made a Function Library in which I have written the code as DPWindow,DPDialog,DPWinEdit,DPWinButton.

And in my test after retrieving values from excel sheet row by row I am calling the above functions. Code for these two conditions I have pasted earlier.

I want to make my function library generic so that My excel sheet format remains same as above for each test case and Object Repository is not needed in it.
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
Amit,

I think you have the correct concept, but you would need to correct your DP subroutines for them to be able to utilize the values retrieved from Excel. Please see my previous post for the same.

I would also suggest you read more about Descriptive Programming. Dani of AdvancedQTP.com has written a book (Scripting QTP) which you can download for free and is a very good source of understanding different ways of working with QTP Scripting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)