Testing Microsoft Access Applications With TestComplete - Part 1

  October 26, 2006

A Microsoft Access database or project typically contains tables, queries and forms that are used to view, input and modify data, macros, different reports and other objects. You can test your Microsoft Access databases (projects) in the same way you would test any other Windows application: by simulating mouse clicks and keystrokes. Also, you can use low-level procedures, manual tests and other features provided by TestComplete to test black-box applications.

To obtain access to elements of a Microsoft Access form and to an element's properties and methods, you should use the MSAA Open Applications plug-in or work with Microsoft Access via COM. Most likely, you will use these technologies together, since MSAA does not provide access to internal properties and methods while the COM-based approach does not let you simulate user actions. In this article, I'll explain how you can work with elements of Access forms via MSAA.

This article uses the Northwind database project that is shipped with Microsoft Access 2003.

Before you start simulating user actions, you have to obtain access to the desired UI forms and elements. If you explore a Microsoft Access database or project in the Object Browser, you will see that by default, TestComplete can access application forms, but it does not have access to form elements:

You need a way to make the form elements visible to TestComplete in order to simulate actions over them.

To access form elements, use TestComplete's MSAA Open Applications plug-in. Since Microsoft Access supports Microsoft Active Accessibility, you can use the MSAA engine to access form elements. Open the File | Install Extensions dialog and check if the plug-in is installed in TestComplete.

After you make sure the plug-in is installed, you need to change project settings in order for TestComplete to be able to apply the MSAA engine to Microsoft Access windows. To do this:

  • Right-click your project in the Project Explorer panel and choose Edit | Properties from the context menu. TestComplete will open the Project Properties edit page in the Workspace panel.
  • On the edit page, select MSAA Open Applications from the list on the left. This will open the project's MSAA options for editing.
  • Select the check box corresponding to the asterisk (*) class name. TestComplete will then use the MSAA engine to expose methods and properties of any existing window.
  • Save all the changes, for example, by pressing Ctrl+S or by selecting File | Save All from TestComplete's main menu.

TestComplete now has access to the form elements. These elements are accessible via the MSAA engine and are marked with the icon. The name of each MSAA node consists of a prefix that specifies the element's accessible role followed by an underscore and the element's accessible name. For instance, in the figure below, the MSAAObject("btn_Products") object corresponds to the Products button of the Main Switchboard form of the Northwind database:

Click to display image

If the element does not have an accessible name, TestComplete generates and assigns a name to it.

The MSAAObject("btn_Products") object contains methods and properties exposed by the MSAA Open Applications plug-in as well as methods, properties and actions provided by TestComplete for onscreen objects. The actions provided by TestComplete include the Click, ClickR, DblClick and other “click” actions that you can use to simulate user actions over a button. The following code demonstrates how you can simulate a mouse click over the Products button of the Main Switchboard form:

To simulate user input into the Bill To box and into the Products and Quantity columns in the Orders form of the Northwind database, you can use the code below. To execute this code, the Main Switchboard form of the Northwind database must be visible on screen.

Simulating user actions over Microsoft Access forms does not differ much from simulating user actions over ordinary Win32 controls. The key point is to specify the MSAA engine's settings so that TestComplete can access form elements.