Functional Tester 支援以 RootTestObject 來表示測試中軟體的廣域視圖。如果要啟用 SAP 應用程式來進行測試,請在 RootTestObject 上呼叫 enableForTesting 方法。若要執行廣域搜尋,請在 RootTestObject 上呼叫 find 方法。子項目(find 方法的第一個引數)的有效值包括 atProperty、atChild、atDescendant 和 atList。有一些特定內容適用於 RootTestObject.find,其中包括 .processName、.processID、.domain 等。您可以使用任何這些子項目和內容。例如,您可以利用 .domain 內容設為 SAP 的 atChild 子項目來搜尋 SAP 網域。
在找到和傳回最上層「SAP 測試物件」之後,您可以利用這個物件來尋找 SAP GUI 執行時期階層的各種物件。例如:
有了作用中視窗物件之後,您可以利用主視窗測試物件的 GetChildren 方法,找到 GuiMainWindow 的各種物件以及與這些物件互動。
以下列出如何與 SAP 應用程式中的物件進行使用者互動的範例。這個範例程式碼會執行下列動作:
範例:
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) { // 利用 Scripting 來搜尋 SAP 測試物件 // 這使得 SAP 能夠接受 Functional Tester 的測試, // 且會傳回 SAP 網域中的所有最上層測試物件 getRootTestObject().enableForTesting("sapLogon"); TestObject[] sapApps = getRootTestObject().find(atChild(".domain", "SAP")); // 從最上層 SAP 物件取得 SAP 應用程式的控點 if(sapApps.length > 0){ SAPGuiApplicationTestObject theAPP = ((SAPTopLevelTestObject)sapApps[0]).getApplication(); logInfo("Application Number:" + theAPP.getProperty("Id")); // 從 SAP 應用程式測試物件取得 SAP 連線的控點 TestObject[] cons = (TestObject[])theAPP.getProperty("Connections"); SAPGuiConnectionTestObject con = (SAPGuiConnectionTestObject)cons[0]; logInfo("Connection Number:" + con.getProperty("Id")); // 從 SAP 連線測試物件取得 SAP 階段作業的控點 TestObject[] sessions = (TestObject[])con.getProperty("Sessions"); SAPGuiSessionTestObject sess = (SAPGuiSessionTestObject)sessions[0]; logInfo("Session Number:" + sess.getProperty("Id")); // 從 SAP 階段作業測試物件取得 SAP 主視窗的控點, // 以及反覆處理它的子項,直到找到所需要的物件 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) { // 在工具列 ("tbar[1]") 上,按一下「建立角色」按鈕 ("btn[48]") button.press(); logInfo("Clicked on the Create Role button"); break; } } } } } }else{ logInfo("SAP Application not found"); } } }
如果已啟用 SAP 應用程式,您便不需要明確啟用 SAP 應用程式來進行測試。相反地,您可以利用下列程式碼來尋找已啟用的 SAP 應用程式。
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) { // 傳回 SAP 網域中所有最上層的測試物件 TestObject[] sapApps = domains[i].getTopObjects(); // 執行與 SAP 物件的使用者互動 } }