Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Principle of object recognition by TestComplete

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

The ability to identify test objects has become the most basic function of a GUI testing tool. This article describes how TestComplete recognizes processes, forms, and controls.

Naming concept:

In order to record identified test objects in a script, TC needs to use the properties of those objects. Each object has many properties, such as "class name", "text", "enabled" and so on. You can see valid object properties in the Object Browser window, or use the Object Properties window to view them.

Some object properties change while the application is running (such as the text property of the edit box object), while others (such as the handle of the form) remain the same but will be different when two different application instances run. Some properties, such as the form class name of some applications, do not change because the application runs different instances.

In order for the test script to distinguish different objects according to their properties, the properties of the object must be uniquely different from other similar objects and remain unchanged.

In general, there are no attributes that meet all these requirements, so TC uses a combination of attributes to identify objects. For example, the process's executable file name and process's index are used by default to locate the process; to locate the form, use the form's class name, caption, index. In other words, a typical object name consists of several parts:

The names of some objects (for example, the caption of a window or the index of a process) change as the application runs, so you need to use a different name to locate the same process or form when the script runs. Using Name Mapping technology, you can redefine the combination of properties that TC uses by default to locate objects.

The addressing and positioning of objects is carried out according to a certain hierarchical relationship. For example, if you need to operate on a form, you first need to get the corresponding process object; in order to operate on a control, you first need to get the form object that contains the control. You can use the object tree of Object Browser to observe the hierarchical relationship of objects.

Once the object is identified and located, TC can further access all the programming objects it owns through the object's name attribute, and perform various operations on it through these object interfaces.

1. Process

TC interacts with processes through process programming objects. Use the Sys.Process or Sys.WaitProcess method to get the process object. These methods use parameters that uniquely identify operating system processes:

1 >, executable file name corresponding to the process

2 >, Index of the process instance. It is possible that an application with the same name will have multiple process instances running at the same time, in which 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 gets the second process instance of notepad:

Var p: OleVariant

Begin

/ / Obtains the object that provides scraping interface

/ / to the second instance of Notepad

P: = Sys.Process ('Notepad', 2)

End

Note, however, that the index of the process may change during the run of the script: if the process with the low sequence number index terminates, the index of the process with the high sequence number index decreases accordingly, so the process name is changed.

If you omit the index parameter when using process, TC defaults to a process with an Index of 1. For example, Process ("Notepad") and Process ("NotePad", 1) refer to the same process object.

2. Form object

The principles used by TC to identify forms depend on whether the application under test is Open Application (open application, white-box) or non-Open Application (plain, black-box).

1 >, Open Applications

If the application under test is compiled into Open Applications (an open application), you can use the special method provided by TC to access the object: WinFormsObject,VBObject,VCLObject. SwingObject et al.

2 >, Black-Box Applications

By default, TC uses the following relatively stable form properties to locate black box-type applications:

L Window class name

L Window caption

L Window index

Use the Process.Window,Process.WaitWindow,Window.Window and Window.WaitWindow methods to get the form object, for example:

Var p, w: OleVariant

Begin

P: = Sys.Process ('winword')

W: = p.Window ('OpusApp',' Microsoft Word-*', 1)

End

3. Control

Because each control of the operating system is a form, the identification method of the control is basically the same as that of the form.

4. Web object

When testing Web pages, TC uses DOM or Tag object model to locate page elements, DOM organizes the hierarchical relationship of page objects through the Document object model, and Tag organizes the hierarchical relationship through the Tag tag of HTML.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report