搜索 SAP TestObject

Functional Tester 支持用于查找一个或多个与指定搜索条件匹配的 SAP TestObject 的方法,即使未使用对象图也如此。

Functional Tester 支持使用 RootTestObject 表示待测试软件的全局视图。要为测试启用 SAP 应用程序,可以对 RootTestObject 调用 enableForTesting 方法。 要执行全局搜索,可以对 RootTestObject 调用查找方法。 子项(即查找方法的第一个参数)的有效值包括 atPropertyatChildatDescendantatList。存在适用于 RootTestObject.find 的特殊属性,包括 .processName.processID.domain 等。可以使用其中任一子项和属性。例如,可以使用 .domain 属性设置为 SAPatChild 子项来搜索 SAP 域。

注: 请参阅“SAP GUI 脚本框架”文档,以获取有关 SAP 的 GUI 运行时层次结构的更多信息。

一旦找到并返回了顶级 SAP 测试对象,即可使用该对象来查找 SAP 的 GUI 运行时层次结构的各种对象。例如:

一旦拥有活动窗口对象,即可对主窗口测试对象使用 GetChildren 方法来查找 GuiMainWindow 上的各种对象并与其交互。

以下是有关如何执行与 SAP 应用程序中对象的用户交互的示例。此样本代码:

  1. 为测试启用 SAP 应用程序
  2. 返回表示窗口的 SAP 测试对象
  3. 使用此对象查找 SAP 工具栏上的按钮名称属性设置为 btn[48]创建角色按钮。
  4. 单击创建角色按钮

示例:

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
		}
	}

反馈