Understanding how TestComplete interacts with tested applications

In this recipe we will deal with TestComplete workings with various windows and control elements.

Getting ready

Launch the Calculator Plus application (C:Program FilesMicrosoft Calculator PlusCalcPlus.exe) and make sure it is in Standard mode (the View | Standard menu item is checked).

How to do it...

In order to learn how TestComplete works with tested applications we need to perform the following steps:

  1. Let's make a simple test and run it.
    function Test2()  
    {  
      var pCalc = Sys.Process("CalcPlus");  
      var wCalc = pCalc.Window("SciCalc", "Calculator Plus", 1);
      wCalc.Activate();  
      wCalc.Window("Button", "2").Click();  
      wCalc.Window("Button", "+").Click();  
      wCalc.Window("Button", "2").Click();  
      wCalc.Window("Button", "=").Click();  
      var result = wCalc.Window("Edit", "").wText;  
      Log.Message(result);  
    }  
  2. In the result of the calculus, the log will have several messages on the buttons that have been clicked and the result of the add-up equation 2+2 from the text field.

How it works...

In the first line, we initialize the pCalc variable and assign it with the object that is returnable by the Process method. The Process method takes two parameters: the name of the process and its index. By default, the index is equal to 1 and can be omitted.

In the next line, we initialize a new variable wCalc, while using the previously created variable pCalc this time around.

The wCalc variable will have a value assigned that is returned by the Window method. This method takes in three parameters:

  • WndClass: This parameter specifies the window class. The value of this property is viewable in Object Browser (the WndClass property).
  • WndCaption: This parameter specifies a heading of the window, as seen by the user. The value of this property is also viewable in Object Browser.
  • GroupIndex: This parameter specifies the current state of the window among the other windows of the same class (the so called, Z ordering). The GroupIndex parameter can also be omitted in case of unique control.

In the four lines to follow, we are working with the control elements of the type Button, while using the same Window method.

In the last line but one, we are working with a new control element Edit, by respectively signifying such a class for it. Since this element has no heading at all, the second parameter is an empty string.

In this same string, we go about creating a new variable result and assigning it with a value of the wText property of the text field—in order to have this value outputted to the log.

Tip

Please note that access to any control element, regardless of its class and level of hierarchy, is carried out with the help of the Window method! This is true only for Win32 applications.

If you do not know which class or heading of the necessary control element is to be taken up, make use of the Object Spy utility and look up the corresponding properties of the control element of choice.

There's more...

In our examples we are handling an ordinary Win32 application.

Apart from this, there is a good deal of other types of applications (.NET, Java, Delphi, and so on), and for each type there are proprietary methods of access and control. For example, for .NET applications it is the WinFormsObject method, for Delphi applications it is the VCLObject method, and so on.

Hence, if you have, say, a control element, that is identifiable by TestComplete as

Sys.Process("myapp").WinFormsObject("DotNetWinClass", "App Caption")

you will not be able to address it with the help of the Window method:

Sys.Process("myapp").Window("DotNetWinClass", "App Caption") // <= WRONG!

This is incorrect and will not work! For each type of application, correct methods should be used (they can be looked up in Object Browser).

See also

  • Usage of the Log.Message method is considered in greater detail in Chapter 6, Logging Capabilities, that is dedicated to working with the log
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.159.223