Functional Tester は、テスト対象のソフトウェアのグローバル・ビューを表す RootTestObject クラスをサポートしています。SAP アプリケーションをテスト用に使用可能にするには、RootTestObject クラスの enableForTesting メソッドを呼び出します。グローバルに検索するには、RootTestObject クラスの検索メソッドを呼び出します。検索メソッドの最初の引数になる副項目の有効な値には、atProperty、atChild、atDescendant、および atList があります。.processName、.processID、.domain プロパティーなど、RootTestObject.find に適用される特殊なプロパティーがあります。これらの副項目およびプロパティーから任意のものを使用することができます。例えば、SAP ドメインを検索するには、.domain プロパティーを SAP に設定した atChild 副項目を使用できます。
トップレベルの SAP Test Object が見つかって戻された後は、そのオブジェクトを使用して、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();
}
}
}