Functional Tester supporta un elemento RootTestObject per rappresentare una vista globale del software in fase di test. Per abilitare l'applicazione SAP per il test, richiamare il metodo enableForTesting in RootTestObject. Per eseguire una ricerca globale, è necessario richiamare il metodo find in RootTestObject. I valori validi per l'elemento secondario, ovvero il primo argomento del metodo di ricerca, includono atProperty, atChild, atDescendant e atList. Esistono proprietà particolari che si applicano a RootTestObject.find, che includono .processName, .processID, .domain e così via. E' possibile utilizzare uno di questi elementi secondari e proprietà. Ad esempio, è possibile utilizzare l'elemento secondario atChild con la proprietà .domain impostata su SAP, per ricercare il dominio SAP.
Una volta trovato e restituito l'oggetto di test SAP di livello superiore, è possibile utilizzare tale oggetto per trovare vari oggetti della gerarchia di runtime della GUI di SAP. Ad esempio:
Una volta ottenuto l'oggetto finestra attivo, è possibile utilizzare il metodo GetChildren nell'oggetto di test finestra principale per trovare e interagire con i vari oggetti in GuiMainWindow.
Di seguito è riportato un esempio del modo in cui gestire le interazioni utente con gli oggetti nell'applicazione SAP. Questo codice di esempio consente di effettuare le seguenti operazioni:
Esempio:
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 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 on 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"); } } }
Se l'applicazione SAP è già abilitata, non è necessario abilitarla esplicitamente per il test. Invece, è possibile utilizzare il seguente codice per trovare l'applicazione SAP abilitata.
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 } }