Rational Functional Tester 支持使用 RootTestObject 表示待测软件的全局视图。要执行全局搜索,可以对 RootTestObject 调用查找方法。 调用 TestObject 查找方法将仅搜索该 TestObject 的子代。
查找方法中的第一个参数为搜索属性的子项。第二个可选参数为标志,用于指示是否应仅搜索可能包含在测试对象图中的子代。属性子项的有效值为:
存在适用于 RootTestObject.find 的特殊属性,包括:
TestObject[] foundTOs ; RootTestObject root = RootTestObject.getRootTestObject() ; // Find all toplevel windows in the Windows domain with caption "My // Document" CaptionText caption = new CaptionText("My Document") ; foundTOs = root.find(atChild(".domain", "Win", ".caption", caption)) ; // Find any dialogs, then return their children // "OK" buttons. RegularExpression dialogRE = new RegularExpression("*dialog", false) ; RegularExpression buttonRE = new RegularExpression("*button", false) ; foundTOs = root.find(atList(atDescendant(".class", dialogRE), atChild(".class", buttonRE,".value", "OK"))) ; // Start Notepad, dynamically enable that process, // find its top-level window that matches the process id // and get its descendant text window. ProcessTestObject p1 = StartApp("Notepad") ; Integer pid = new Integer((int)p1.getProcessId()) ; foundTOs = root.find(atList(atProperty(".processId", pid), atDescendant(".class", ".text"))) ; // This enables a Windows app with the provided window handle and returns a // TestObject representing the window. Long hWnd = getAppsHwnd(); foundTOs = root.find(atChild(".hwnd", hWnd, ".domain", "Win")); // This enables a .NET app with the provided window handle and returns a // TestObject representing the window. Long handle = getAppsHwnd(); foundTOs = root.find(atChild("Handle", handle, ".domain", "Net"));
Windows 和 .NET 应用程序通过 Rational Functional Tester 来动态启用,并且用于启用这些应用程序的属性为 .processName。要在 Windows 或 .NET 应用程序上查找所需的测试对象,请在查询中使用 .processName。
Property[] props = new Property[4]; // find toplevel window of calculator app props[0] = new Property(".processName", "calc.exe"); props[1] = new Property(".class","SciCalc"); props[2] = new Property(".name", "Calculator"); props[3] = new Property(".text", "Calculator"); TestObject[] tos = find(atChild(props)); if(tos.length > 0) { // find button with text 9 props = new Property[3]; props[0] = new Property(".class","Button"); props[1] = new Property(".name", "9"); props[2] = new Property(".text", "9"); TestObject[] tos9 = tos[0].find(atChild(props)); if(tos9.length > 0) { // Click button 9 ((GuiTestObject)tos9[0]).click(); } }