Searching for SAP TestObjects

Functional Tester supports a means for locating one or more SAP TestObjects matching a specified criteria, even without using the Object Map, through scripting manually.

Rational® Functional Tester supports a RootTestObject to represent a global view of the software under test. To enable the SAP application for testing, you invoke the enableForTesting method on the RootTestObject. To perform a global search, you invoke the find method on the RootTestObject. Valid values for the subitem, which is the first argument of the find method, include atProperty, atChild, atDescendant, and atList. There are special properties that apply to the RootTestObject.find, including the .processName, .processID, .domainetc. You can use any one of these subitems and properties. For example, you can use the atChild subitem with the .domain property set to SAP, to search for the SAP domain.

Note: See the SAP GUI Script Framework documentation for more information on SAP's GUI Runtime Hierarchy.

Once the top level SAP Test Object is found and returned, you can use that object to find various objects of SAP's GUI runtime hierarchy. For example:

  • You can obtain the SAPGuiApplicationTestObject by invoking the GetApplication method on the SAPTopLevelTestObject.
  • You can obtain the SAPGuiConnectionTestObject by invoking the GetProperty("Connections") method on the SAPGuiApplicationTestObject.
  • You can obtain the SAPGuiSessionTestObject by invoking the GetProperty("Sessions") method on the SAPGuiConnectionTestObject.
  • You can obtain the SAP's active window by invoking the GetProperty("ActiveWindow") method on the SAPGuiSessionTestObject.

Once you have the active window object, you can use the GetChildren method on the main window test object to find and interact with various objects on GuiMainWindow.

Listed below is an example on how you can perform user interactions with objects in the SAP application. This sample code:

  1. Enables the SAP application for testing
  2. Returns the SAP test object representing the window
  3. Uses this object to find the Create Role button whose button name property is set to btn[48] on the SAP toolbar.
  4. Clicks on the Create Role button

Example:

#Region " Script Header "
' Functional Test Script
' author Administrator
Imports Microsoft.VisualBasic
Imports Rational.Test.Ft
Imports Rational.Test.Ft.Object.Interfaces
Imports Rational.Test.Ft.Object.Interfaces.SAP
Imports Rational.Test.Ft.Object.Interfaces.Siebel
Imports Rational.Test.Ft.Script
Imports Rational.Test.Ft.Value
Imports Rational.Test.Ft.Vp
#End Region

Public Class HandCodingWithEnablement 
    Inherits HandCodingWithEnablementHelper

    'Script Name   : HandCodingWithEnablement
    'Generated     : Sep 5, 2006 10:53:54 AM
    'Description   : Functional Test Script
    'Original Host : Windows XP x86 5.1 build 2600 Service Pack 2 

    'since  2006/09/05
    'author Administrator

    Public Function TestMain(ByVal args() As Object) As Object
        Dim sapApps() As TestObject
        Dim app As SAPTopLevelTestObject
        Dim theAPP As SAPGuiApplicationTestObject
        Dim cons() As TestObject
        Dim sessions() As TestObject
        Dim con As SAPGuiConnectionTestObject
        Dim sess As SAPGuiSessionTestObject
        Dim mainWnd As SAPTopLevelTestObject
        Dim wndChild() As TestObject
        Dim btns() As TestObject
        Dim btn As SAPGuiToggleTestObject
        Dim i, j As Integer
        Dim Len1, Len2 As Integer

        ' Searching for SAP Test Objects through Scripting 

        ' This enables SAP to be tested by Rational® Functional Tester and 
        ' returns all top-level test objects in the SAP domain
        GetRootTestObject().EnableForTesting("sapLogon")
        sapApps = GetRootTestObject().Find(AtChild(".domain", "SAP"))

        ' Get a handle to the SAP Application from the top-level SAP object
        If (sapApps.GetLength(0)> 0) Then
            app = sapApps(0)
            theAPP = app.GetApplication
            LogInfo("Application Number:" + theAPP.GetProperty("Id"))

            ' Get a handle to the SAP Connection from the SAP Application Test object
            cons = theAPP.GetProperty("Connections")
            con = cons(0)
            LogInfo("Connection Number:" + con.GetProperty("Id"))

            ' Get a handle to the SAP Session from the SAP Connection Test Object
            sessions = con.GetProperty("Sessions")
            sess = sessions(0)
            LogInfo("Session Number:" + sess.GetProperty("Id"))

            ' Get a handle to the SAP Main Window from the SAP Session Test Object
            ' and iterate over its children till the desired object is found
            mainWnd = sess.GetProperty("ActiveWindow")
            wndChild = mainWnd.GetChildren()

            Len1 = wndChild.GetLength(0) - 1
            For i = 0 To Len1
                Dim name As String = wndChild(i).GetProperty("Name")
                If (name.CompareTo("tbar[1]") = 0) Then
                    btns = wndChild(i).GetChildren
                    Len2 = btns.GetLength(0) - 1
                    For j = 0 To Len2
                        Dim btnType As String = btns(j).GetProperty("Type")
                        If (btnType.CompareTo("GuiButton") = 0) Then
                            btn = CType(btns(j), SAPGuiToggleTestObject)
                            Dim btnName As String = btn.GetProperty("Name")
                            If (btnName.CompareTo("btn[48]") = 0) Then
                                ' Click on the "Create Role" button ("btn[48]") placed on the toolbar("tbar[1]")
                                btn.Press()
                                LogInfo("Clicked on the Create Role button")
                                Return Nothing
                            End If
                        End If
                    Next j
                End If
            Next i
        Else
            LogInfo("SAP Application not found")
        End If
        
    Return Nothing
    End Function
End Class

If the SAP application is already enabled, then you need not enable the SAP application explicitly for testing. Instead you can use the following code to find the enabled SAP application.

Dim domains As DomainTestObject()
      Dim domain As DomainTestObject
      Dim sapApps() As TestObject
      Dim name As String
      Dim domainsCount As Integer
      Dim i As Integer

	domains = GetDomains()
      domainsCount = domains.GetLength(0) - 1
      For i = 0 To domainsCount
          domain = domains(i)
          name = domain.GetName()
          If (name.CompareTo("SAP") = 0) Then                
              ' Returns all top-level test objects in the SAP domain
              sapApps = domain.GetTopObjects

		' Perform user interactions with the SAP objects				                
          End If
      Next i