Part 1: Understanding testobject. Find
I. Functions of the testobject. Find Method
1. dynamically finding test objects (controls, labels, etc.) during the test process, so that our test cases do not depend on the object map that comes with rft ).
2. Without the dependency on the object map, you no longer need to repeatedly modify the object map process for UI and other changes.
Ii. Instructions for using the find Method
1. The find method is a method that inherits roottestobject from the testobject class and overwrites multiple implementation methods.
In the following example, the Code usesatDescendant
To locate the button. However, you can usefind
:
-
atChild
Search for all direct sub-objects of testobject.
atDescendant
Search for all the sub-objects of testobject.
atList
You can specify a list of atchild, atdescendant, and atproperty objects to reduce the search range.
Part 2: Use the find method (test the Java software that comes with rft)
1. Open an automatic Java Applet:
Find "configuration" -- "configure the application for testing..." -- ", and enter the interface: click" run"
2. view the control properties to prepare for the find operation.
Open the application to be tested, and view the attributes of each element on the interface through the "dedicated test object graph" -- "capture function on the left of the main interface of rft. Query all the required control attributes.
3. Create a new class and abstract the entire dialog and Its Controls (here only the cancel button is added)
1 package Baidu; 2 Import resources. baidu. testforplaceanorderhelper; 3 Import COM. rational. test. ft. *; 4 Import COM. rational. test. ft. object. interfaces. *; 5 import COM. rational. test. ft. object. interfaces. SAP. *; 6 Import COM. rational. test. ft. object. interfaces. WPF. *; 7 Import COM. rational. test. ft. object. interfaces. dojo. *; 8 Import COM. rational. test. ft. object. interfaces. siebel. *; 9 Import COM. rational. test. ft. object. interfaces. flex. *; 10 Import COM. rational. test. ft. object. interfaces. generichtmlsubdomain. *; 11 import COM. rational. test. ft. script. *; 12 Import COM. rational. test. ft. value. *; 13 Import COM. rational. test. ft. VP. *; 14 Import COM. IBM. rational. test. ft. object. interfaces. sapwebportal. *; 15/** 16 * Description: functional test script17 * @ author lenovo18 */19 public class testforplaceanorder extends testforplaceanorderhelper20 {21/** 22 * Script Name: <B> testforplaceanorder </B> 23 * generated: <B> 11:41:34 </B> 24 * Description: functional test script25 * original host: winNT version 6.1 build 7601 (s) 26*27 * @ since 2014/10/1828 * @ author lenovo29 */30 public void testmain (object [] ARGs) 31 {32 // todo insert Code 33} 34 35 // create a class (DIALOG ), abstract The place an order dialog box and its internal control 36 // static class, which can be used to conveniently call 37 public static class placeanorder38 {39 // to obtain the root node, the entire dialog40 public static guitestobject getdialog () 41 {42 roottestobject root = getroottestobject (); 43 testobject [] to = root. find (atdescendant ("class", "javax. swing. jframe "," title "," place an order "); 44 return New guitestobject (to [0]); 45} 46 // get the cancel button 47 Public static guitestobject getbtncancel () 48 {49 testobject to = getdialog (); 50 // here we use the forced type conversion method 51 testobject [] btncancel =. find (atdescendant ("class", "javax. swing. jbutton "," text "," cancel "); 52 return New guitestobject (btncancel [0]); 53} 54 55} 56 57 58}
Create another test case: (Action: cancel the order)
1 package Baidu; 2 Import resources. baidu. testjavaclassahelper; 3 Import Baidu. testforplaceanorder. placeanorder; 4 5 import COM. rational. test. ft. *; 6 Import COM. rational. test. ft. object. interfaces. *; 7 Import COM. rational. test. ft. object. interfaces. SAP. *; 8 Import COM. rational. test. ft. object. interfaces. WPF. *; 9 Import COM. rational. test. ft. object. interfaces. dojo. *; 10 Import COM. rational. test. ft. object. interfaces. siebel. *; 11 import COM. rational. test. ft. object. interfaces. flex. *; 12 Import COM. rational. test. ft. object. interfaces. generichtmlsubdomain. *; 13 Import COM. rational. test. ft. script. *; 14 Import COM. rational. test. ft. value. *; 15 Import COM. rational. test. ft. VP. *; 16 Import COM. IBM. rational. test. ft. object. interfaces. sapwebportal. *; 17/** 18 * Description: functional test script19 * @ author lenovo20 */21 public class testjavaclassa extends testjavaclassahelper22 {23/** 24 * Script Name: <B> testjavaclassa </B> 25 * generated: <B> 8:55:31 </B> 26 * Description: functional test script27 * original host: winNT version 6.1 build 7601 (s) 28*29 * @ since 2014/10/1830 * @ author lenovo31 */32 public void testmain (object [] ARGs) 33 {34 testobject to = placeanorder. getdialog (); 35 36 guitestobject btncancel = placeanorder. getbtncancel (); 37 38 btncancel. click (); 39} 40 41}
Learning rft: understanding and using testobject. Find