Searching for SAP TestObjects

With Rational® Functional Tester, you can locate one or more SAP TestObjects matching a specified search criteria, even without using the Object Map.

Rational® Functional Tester supports a RootTestObject class 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 class. To search globally, you invoke the find method on the RootTestObject class. 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, and .domain properties. You can use any one of these subitems and properties. For example, to search for the SAP domain, you can use the atChild subitem with the .domain property set to SAP.

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

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

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

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 method.

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

  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 the Create Role button

Example:

import resources.HandCodingWithEnablementHelper;

import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;

/**
 * Description   : Functional Test Script
 * @author Administrator
 */
public class HandCodingWithEnablement extends HandCodingWithEnablementHelper
{
	/**
	 * Script Name   : HandCodingWithEnablement
	 * Generated     : Sep 5, 2006 10:03:51 AM
	 * Description   : Functional Test Script
	 * Original Host : WinNT Version 5.1  Build 2600 (S)
	 * 
	 * @since  2006/09/05
	 * @author Administrator
	 */
	public void testMain(Object[] args) 
	{
		// 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");
		TestObject[] sapApps = getRootTestObject().find(atChild(".domain", "SAP"));
		
		// Get a handle to the SAP Application from the top-level SAP object
		if(sapApps.length > 0){
			SAPGuiApplicationTestObject theAPP = ((SAPTopLevelTestObject)sapApps[0]).getApplication();
			logInfo("Application Number:" + theAPP.getProperty("Id"));
			
			// Get a handle to the SAP Connection from the SAP Application Test object
			TestObject[] cons = (TestObject[])theAPP.getProperty("Connections");

			SAPGuiConnectionTestObject con = (SAPGuiConnectionTestObject)cons[0];
			logInfo("Connection Number:" + con.getProperty("Id"));
			
			// Get a handle to the SAP Session from the SAP Connection Test Object
			TestObject[] sessions = (TestObject[])con.getProperty("Sessions");
			SAPGuiSessionTestObject sess = (SAPGuiSessionTestObject)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
			SAPTopLevelTestObject mainWnd = (SAPTopLevelTestObject)sess.getProperty("ActiveWindow");			
						
			TestObject[] wndChild = mainWnd.getChildren();
			for (int i=0; i<wndChild.length; i++)
			{
				String name = (String)wndChild[i].getProperty("Name");
				if (name.compareTo("tbar[1]")== 0)
				{
					TestObject[] btn = (TestObject[])wndChild[i].getChildren();
					for (int j = 0; j< btn.length; j++)
					{
						System.out.println("ToolBar Buttons");
						String btnType = (String)btn[j].getProperty("Type");
						if (btnType.compareTo("GuiButton")==0)
						{
							SAPGuiToggleTestObject button = (SAPGuiToggleTestObject)btn[j];
							String btnName = (String)button.getProperty("Name");
							if (btnName.compareTo("btn[48]")== 0)
							{
								// Click the "Create Role" button ("btn[48]") placed on the toolbar("tbar[1]")
								button.press();
								logInfo("Clicked on the Create Role button");
								break;
							}
						}
					}
				}
			}
		}else{
			logInfo("SAP Application not found");
		}
	}
}

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

DomainTestObject domains[] = getDomains();
	for  (int i =0; i < domains.length; i ++)
	{
		DomainTestObject domain = domains[i];
		String name = (String)domain.getName();
		if (name.compareTo("SAP") == 0)
		{
			// Returns all top-level test objects in the SAP domain
			TestObject[] sapApps = domains[i].getTopObjects();
				
			// Perform user interactions with the SAP objects
		}
	}
You can also adapt the dynamicfind() API to find SAP text objects in a functional test script and perform setText in an SAP text field.
public class SAPEditControl extends SAPEditControlHelper {
	/**
	 * Script Name : <b>SAPEditControl</b> Generated : <b>Aug 3, 2011 2:29:57
	 * PM</b> Description : Functional Test Script Original Host : WinNT Version
	 * 5.1 Build 2600 (S)
	 * 
	 * @since 2011/08/03
	 * @author Functional Test User
	 */
	public void testMain(Object[] args) {
		// Define a set of properties for a control (test object) to be searched
		Property Props[] = new Property[4];
		// property and value
		Props[0] = new Property(".class", "Html.TABLE");
		Props[1] = new Property(".customclass", "SAPEditControl");
		Props[2] = new Property(".id", "WD019E-r");
		Props[3] = new Property(".classIndex", "10");

		try {

			// Find and store test objects into array
			TestObject Obj[] = getRootTestObject().find(atDescendant(Props));

			// Perform a click action on the very first object.
			((TextGuiSubitemTestObject) Obj[0]).click();

			// Set a text into SAP Edit Control
			((TextGuiSubitemTestObject) Obj[0]).setText("ClaimedAmount");

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			//call unregisterAll to clear reference.
			unregisterAll();
		}
	}

}