Testing PowerBuilder Applications With TestComplete 4

  May 02, 2006

Currently, PowerBuilder applications are “closed” to TestComplete. In other words, TestComplete does not have access to internal objects, methods and properties of these applications. You can test these applications by simulating mouse clicks, keystrokes, using low-level procedures, manual tests as well as other means provided by TestComplete for testing black-box applications.

However, since PowerBuilder supports Microsoft Active Accessibility, you can work with application objects using TestComplete’s MSAA engine. It provides access to application internals exposed through Microsoft Active Accessibility. So, the MSAA engine makes PowerBuilder applications more “open” in comparison to traditional black-box apps.

Testing PowerBuilder Applications With TestComplete 4

TestComplete currently treats applications created with PowerBuilder as “closed” applications because it can not access the applications internal objects, methods and properties. To test these applications you would have to test them as black-box applications by simulating mouse clicks and keystrokes using low-level procedures, manual tests and various other features provided by TestComplete.

However, not all PowerBuilder application objects are “closed” to TestComplete since PowerBuilder supports Microsoft Active Accessibility. TestComplete’s MSAA engine provides access to application internals exposed through Microsoft Active Accessibility. The MSAA engine makes PowerBuilder applications “open” in comparison to traditional black-box applications. Since PowerBuilder application windows and controls support Microsoft Active Accessibility, you can access and use the application’s internal objects, methods and properties that are exposed by the IAccessible interface. These methods and properties are displayed in TestComplete’s Object Browser just like any “open” application and can be used in your scripts.

In this blog entry, I will demonstrate how to retrieve data from the DataWindow non-visual component of an application created with PowerBuilder 10 or later.

Installing the MSAA Plug-In

TestComplete includes a special MSAA Open Applications plug-in that provides access to objects, methods and properties exposed by Microsoft Active Accessibility. To test PowerBuilder applications, you need to install this plug-in into TestComplete in order to view an application’s internal objects, methods and properties. You can install the plug-in during TestComplete's installation or at any later time. To check whether the plug-in is installed, launch TestComplete and select File | Install Extensions from the main menu. In the subsequent Extensions dialog, make sure that the MSAA Open Applications plug-in is selected:

Extensions Dialog

If the plug-in is not listed in the dialog, run the TestComplete installation program in Modify mode and install the plug-in.

Creating a Sample PowerBuilder Application

To create a sample PowerBuilder application:

  • Launch PowerBuilder 10 and create a new project. Name the sample project msaaconnection.
  • Add a new window to the project and name it window_main.
  • Add a DataWindow component to the application and name it datawindow.
  • Connect the DataWindow component to a database.
  • Add a ProjectApplication node to the PowerBuilder project. Open the Properties window for the node and specify msaaconnection.exe in the Executable File Name edit box. Leave all other properties unchanged:


    Click to display image
    PowerBuilder Project Properties

    The project contents should now look as follows:

    Click to display image
    Project Contents

Now that your project's contents are set, open the window_main window in the Window Painter and place a DataWindow Control to window_main:

Click to display image
Layout View

In the Properties window you can specify PowerBuilder controls’ accessibility property values: AccessibleName, AccessibleDescription and AccessibleRole. These properties are used to address the control in TestComplete. Setting specific values for these properties will help you find the controls in the Object Browser easier. Although, you can leave the default values since TestComplete will still be able to address the objects.

Click to display image
Accessibility Properties Highlighted

Save the changes and compile your PowerBuilder application. Now your application is ready for testing and you can configure the TestComplete project.

Configure a TestComplete Project

To start testing with TestComplete first you have to configure a project:

  • Launch TestComplete and create a new test project that only contains the Script project item.
  • Right-click the project node in the Project Explorer panel and select Edit | Properties from the context menu. This will open the project editor in the Workspace panel and display the Properties page.
  • Select the MSAA Open Applications group on the left of the page. TestComplete will display the list of MSAA Open Applications properties on the right. This list contains windows class names and their properties will be accessed via TestComplete's MSAA engine.
  • Select the check box for the asterisk (*) class name. This allows TestComplete to use MSAA to expose methods and properties of any existing window:


    Click to display image
    MSAA Open Applications

    Select File | Save All from TestComplete’s main menu to save all project changes.

Testing the PowerBuilder Application

You are now ready to perform a test with your PowerBuilder Application. To start the test:

  • Launch your PowerBuilder application.
  • Switch to TestComplete’s Object Browser.
  • Expand the node corresponding to the PowerBuilder application (Process("msaaconnection")) to make sure that the test engine has access to the application’s internal objects, methods and properties. These elements are accessed through MSAA. In the image below, the Object Browser displays the object tree of the PowerBuilder 10 application. The selected tree node corresponds to the DataWindow Control. Child elements of this control are displayed as child nodes. The name of each node contains a prefix (mb, sb, text and others) that specifies the element’s role. The prefix is followed by an underscore and the accessible name. If an element does not have an accessible name, TestComplete forms the name itself:


    Click to display image
    Object Browser

The following JScript code demonstrates how you can access PowerBuilder application elements from your script. The GetObjectByName function is used to obtain an element by its name and index. The Main function iterates through all application elements and posts DataWindow element values to the test log.

This script, executed for my sample application, produced the following log. Your log will look different since we are using different databases.

Click to display image
TestComplete Log

As you can see, the script can retrieve values from DataWindow controls. Using TestComplete’s MSAA engine you can retrieve property values of other PowerBuilder application controls.