Rft cannot identify Windows dialog box Handling Methods

Source: Internet
Author: User

I. Overview

Rft provides the find method, which is a powerful tool that allows us to run the test script without the test object, in this way, our scripts have good robustness and portability (in last year's automated test project, qtp often fails to run the scripts due to the property of the test object ). However, today, when I used the test object Checker to obtain the Windows dialog box properties, I encountered an extreme problem. The object checker could not recognize the Windows dialog box. The last few twists and turns finally solved this problem.

Ii. Problems

The script operation process is like this. First, click the export button on the interface. A confirmation box is displayed, indicating whether to save the script. Then, click "yes ", then, the system opens a new file save Dialog Box Based on this dialog box. At this time, I found that the test object examiner could not obtain any attributes of the object at all, and no objects were found when I used the find method. The attribute used is ". Name" and the attribute value is "Save"

Iii. Analysis

The root cause of this problem is rft's object recognition mechanism. By reading materials and APIs, I think rft can process Object Relationships in two ways: a collection of parent-child relationships, another object set, which is temporarily called the top layer-lower layer link. For example, a confirmation prompt box with the "OK" and "cancel" buttons is the parent-child relationship object, and a confirmation prompt box is the parent object, the OK button and cancel button are the sub-objects of the button. Parent-Child objects can be easily found by the object checker or the find method. Objects in the top-layer relationship are like the example above: A dialog box is displayed on the basis of the existing Windows dialog box. The two dialogs are not a parent-child relationship, but a nested relationship. Obviously, a dialog box is a top-level window, that is, the owner of the focus. It is also called a modal window during development. Top-level -- lower-level objects cannot be recognized by the object Examiner. Of course, these are my current understanding of rft, and I have not seen a similar explanation on IBM's website. With guitestobject, we can easily process parent-child relationships. However, for objects in the top-level-lower-level relationships, the guitestobject object is powerless (at least here I am here)

Iv. Solution

To solve this problem, rft provides an interface to access the Windows platform control, that is, iwindow. Since we cannot get the properties of the Save dialog box through the testobject class, we treat the Save dialog box as a Windows Object and use iwindow to identify it. We need to solve the following problems:

1. First, let the script get the object in the File Save dialog box. The object type is iwindow. The object can get the attributes returned by gettext. In the File Save dialog box, gettext returns "Save ".

2. Call inputchars of iwindow to enter the directory saved in the file.

3. Let the script get the "save" button of the sub-object of the Save dialog box object and click it.

To implement the above functions, we need two methods: gettopwindow and getlevelwindow. There is a related article on the IBM website. For the link, see section 5. The code is directly posted here:

/*** Return the objects of the top-level window in the window system. For example, gettopwindow ("Save as") will return a Windows Save As dialog box. Unlike getlevelwindow, The topwindow object can execute the inputchars method, levelwindow does not work. * @ Param objname: gettext attribute of Windows Forms, dialog boxes, and elements * @ return iwindow Windows Control (object), which is a top-level window */Public iwindow gettopwindow (string objname) {iwindow [] wins = rationaltestscript. gettopwindows (); int length = wins. length; For (INT I = 0; I <length; I ++) {If (wins [I]. gettext (). matches (objname) {return wins [I] ;}} return NULL ;}
/*** For some second-level pop-up windows, this method can be used to identify and operate. This method returns the object with the specified name, such as getwinobject ("Save as", "Save (& S) "), this method returns to the" save "button in the Windows save dialog box. ** @ Param topwinname * gettext attribute of the top-level window object * @ Param levelwinname * gettext attribute of the sub-object under the top-level object * @ return iwindow object. This object can be clicked or double-clicked. */Public iwindow getlevelwindow (string topwinname, string levelwinname) {iwindow winobjects = NULL; iwindow [] wins = rationaltestscript. gettopwindows (); // returns the Windows Object array for (INT I = 0; I <wins. length; I ++) {// search for all objects that meet the topwinname attribute in the array if (wins [I]. gettext (). equals (topwinname) {winobjects = wins [I] ;}} iwindow [] winobj = winobjects. getchildren (); For (INT I = 0; I <winobj. length; I ++) {If (winobj [I]. gettext (). equals (levelwinname) {// In the top-level object, find the object that meets the levelname attribute return winobj [I] ;}} return NULL ;}
Finally, the Code for identifying the file storage box and saving the file is as follows:
Test. getlevelwindow ("Save as", "File Name (& N ):"). click (); // click the save text box to get the focus. test. gettopwindow ("Save "). inputchars ("C: // result.xls"); // enter the dialog box for saving the file

V. Summary

After the code is complete, I found that this problem is not complicated. All classes and Methods rft have been provided, just because I was not familiar with the iwindow usage before, so I took a lot of detours until I saw an article on the IBM website. In fact, it is not just to save the dialog box. We can use iwindow to find and locate any windows platform control.

6. References http://www.ibm.com/developerworks/cn/rational/r-cn-extendsrftobj/index.html of extended rational functional tester Object Recognition Technology

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.