Searching for test objects
Rational Functional Tester supports a means for locating one or more TestObjects matching specified search criteria. The search is based on name/value pairs representing properties of the TestObject or TestObjects you are looking for. The search can either be global, or limited to children of a parent TestObject.
Rational Functional Tester supports a RootTestObject to represent a global view of the software under test. To perform a global search, you invoke the find method on the RootTestObject. Invoking a TestObject find method will only search the children of that TestObject.
The first argument in the find method is a subitem for the search properties. The second optional argument is a flag indicating whether only children that might be included in the test object map should be searched. Valid values for the property subitems are:
- atProperty -- A name/value pair representing a TestObject property
- atChild -- One or more properties that must be matched against the direct child of the starting TestObject
- atDescendant -- One or more properties that can be matched against any child of the starting TestObject
- atList -- A sequential list of properties to match against. Valid subitems for atList are:
- atChild
- atDescendant
- atProperty
- The first list item is matched against to get a list of candidates, and out of those candidates their descendants are matched against for the next list item, and so on.
There are special properties that apply to RootTestObject.find, including:
- .processName -- A top-level property that has two functions:
- Dynamically enable the processes with that processName
- Constrain the find to only look in processes with that name
- .processId -- A top-level property that has two functions:
- Dynamically enable the processes with that process id (pid)
- Constrain the find to only look in processes with that process id (pid)
The .processId is valid for dynamically enabled domains like .NET and Windows. It cannot be used for enabled domains, such as HTML and Java.
- .domain -- A flag specifying only search in top-level domains matching the domain property
- .hWnd -- Along with the hWnd property being used for the search, if the .domain "Win" is also specified, the matching window will be enabled for testing with the Windows domain.
- Handle -- Along with the window handle property being used for the search, if the .domain "Net" is also specified, the matching window will be enabled for testing with the .NET domain.
Examples:
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"));The Windows and .NET applications are dynamically enabled by Rational Functional Tester and the property used to enable these applications is .processName. To find the required test object on a Windows or .NET application, use the .processName in the query.
Example: The following example code is to find the button 9 in a calculator and then click on it.
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(); //unregister tos9[0].unregister(); } }
Related concepts
Get started with Rational Functional Tester
Related tasks
Calling a script from a functional test script
Related reference