From http://softtest.chinaitlab.com/qita/746669.html
The basic principle of the GUI testing tool is to identify the tested object, record the operation of the object, add the edit of the test logic, and play back the script.
The recognition capability of the test object becomes the most basic function of a GUI testing tool. This article describes how TC identifies processes, forms, and controls.
Naming concepts
To record the identified test objects in the script, TC needs to use the attributes of these objects. Each object has many attributes, such as "Class Name", "text", and "enabled. You can view valid object properties in the Object Browser window or use the object Properties window.
Some object attributes will be changed during application running (for example, the text attribute of the edit box object), and some (for example, the handle of the form) it remains unchanged but will be different when two different application instances are running. Some attributes (such as the Form class name of some applications) will not change because the application program running instance is different.
In order for the test script to distinguish different objects based on object attributes, the object attributes must be unique and unchanged from other similar objects.
Generally, no property meets all these requirements, so TC uses a combination of properties to identify objects. For example, the executable file name of the process and the index of the process are used by default to locate the process. To locate the form, the class name, caption, and index of the form are used. In other words, typical object names include:
Some object names (for example, window caption or process index) change as the application runs, therefore, you need to use different names to locate the same process or form during script running. By using the name mapping technology, you can redefine the property combination that TC uses by default to locate objects.
The addressing and positioning of an object is based on a certain level of relationship. For example, to operate a form, you must first obtain the corresponding process object. to operate a control, you must first obtain the form object containing the control. You can use the object tree of Object Browser to observe the object hierarchy.
After identifying and locating an object, TC can further access all its programming objects through the object name attributes and perform various operations on it through these object interfaces.
Process
TC interacts with processes through process programming objects. Use the SYS. process or SYS. waitprocess method to obtain the process object. These methods use parameters that uniquely identify operating system processes:
1. executable file name corresponding to the Process
2. The index of the Process instance. Applications with the same name may run with multiple process instances. In this case, the process index can be distinguished. The index of the first started process is 1, the second is 2, and so on.
For example, the following script obtains the second process instance of notepad:
VaR
P: olevariant;
Begin
// Obtains the object that provides SCR implements pting Interface
// To the second instance of notepad
P: = SYS. Process ('notepad ', 2 );
End;
However, note that the index of the process may change during the script running process: if the process with the low serial number index is terminated, the index of the process with the high serial number index will be reduced accordingly, therefore, the process name is changed.
If you omit the index parameter when using process, TC uses the process with index 1 by default, for example, process ("Notepad") and process ("Notepad", 1) indicates the same process object.
Form object
The TC principle for identifying forms depends on whether the tested application is open application (open application, white box) or non-open application (normal, black box ).
1. Open Applications
If the tested application is compiled into open applications (Open Applications), you can use the special methods provided by TC to access the objects winformsobject, vbobject, and vclobject. Swingobject.
2. black-box applications
By default, TC uses the following relatively stable form attributes to locate black box applications:
L window class name
L window caption
L window Index
Use the process. Window, process. waitwindow, window. window, and window. waitwindow methods to obtain the form object. For example:
VaR
P, W: olevariant;
Begin
P: = SYS. Process ('winword ');
W: = P. Window ('opusapp', 'Microsoft word-* ', 1)
End;
Widget
Because every control in the operating system is a form, the control recognition method is basically the same as the form recognition method.
Web object
When testing a Web page, TC uses the Dom or tag object model to locate page elements. The Dom model is used to organize the hierarchical relationship of page objects through the Document Object Model, the tag method uses HTML Tag tags to organize hierarchies.
Flex object
When testing the flex page, TC is located using the element name, instead of based on the relative position. However, make sure that the element is displayed in the window during the test.