Functional Tester 支持使用 RootTestObject 类表示被测软件的全局视图。要启用 SAP 应用程序以进行测试,可在 RootTestObject 类上调用 enableForTesting 方法。 要执行全局搜索,可在 RootTestObject 类上调用 find 方法。 子项(即查找方法的第一个参数)的有效值包括 atProperty、atChild、atDescendant 和 atList。存在适用于 RootTestObject.find 的特殊属性,包括 .processName、.processID 和 .domain 属性。 您可以使用任意一个这些 subitem 值和属性。例如,要搜索 SAP 域,您可以使用 atChild 子项,并将 .domain 属性设置为 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)
{
// 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");
}
}
}
如果已经启用了 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)
{
// Returns all top-level test objects in the SAP domain
TestObject[] sapApps = domains[i].getTopObjects();
// Perform user interactions with the SAP objects
}
}
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 IBM Rational
*/
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 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();
}
}
}