The previous article (Testing Microsoft Access Applications With TestComplete – Part 1) states that to test Microsoft Access applications, you have to use both the MSAA engine and COM interfaces to access the application’s forms and controls. The article explains how you can use the MSAA functionality to simulate user actions over forms and controls.
This article explains how to work with forms via COM. Like in Part 1, I’m going use the Northwind database shipped with Microsoft Access 2003.
When exploring your Access application in the Object Browser, you may notice that even though the MSAA Open Applications plug-in provides access to form elements, it does not expose the element’s properties and methods that you can edit in the Microsoft Access’s Properties window. To get these properties in TestComplete, you can create a script that will work with Microsoft Access via COM.
Microsoft Access is a COM server and its internals can be accessed from a COM client application. To explore the internal object structure, you can use TestComplete’s Object Browser:
- Open the desired database in Microsoft Access.
- Switch to the Object Browser panel in TestComplete.
- Select the Sys node in the objects tree and switch to the Properties tabbed page.
- Press the Params button of the OleObject property. This will call a window where you can specify the COM server to be explored.
- Type Access.Application in the OleObject edit box and press OK.
TestComplete will connect to Microsoft Access via OLE and it will display (IDispatch) for the OleObject property in the Object Browser. Thus, you get the access point to the Microsoft Access application.
- Press the ellipsis button of the OleObject property. TestComplete will update the Object Browser and display methods and properties of the Access’s Application object. By using methods and properties of this object, you can get access to form elements and their properties and methods. For instance, to explore properties of the Products button that resides on the Main Switchboard form, you should go through the following sequence of properties:
OleObject (IDispatch) -> Forms -> Item(“Main Switchboard”) -> Products
For complete information on Microsoft Access objects, properties and methods, see Microsoft Access documentation.
The following code snippet demonstrates how to modify the caption of the Products button that resides on the Main Switchboard form of the Northwind database. Note that before working with a form via OLE, make sure the form is visible on screen.
The following code demonstrates how to change the value of the Bill To box that resides on the Orders form of the Northwind database.
As you can see, accessing Microsoft Access forms and their elements does not differ much from accessing the forms and form elements from Microsoft Access script modules. To create complex scripts, you need to know the object model and the object methods and properties described in Microsoft Access documentation.