Thursday, November 27, 2008

GUI Automation: Building the Framework (3)

After a hiatus, the GUI Automation blog continues the series on the automated testing of Windows GUI applications. This entry uses the Win32 API to interact with a list box. As usual source code is provided for download:
In the entry Lukas makes an important point about any testing framework:

We do not test the list box component. We test the application.

When testing an application you don't need to test the functionality provided by the operating system or the frameworks you're using; you test your application logic.

Example code for selecting an item in a list box from the application under test (is SUT for "System Under Test" a commonly used acronym?):

def Select(self, aItem):
""" select an item from list box
@aItem - string with item to select
"""
if aItem not in self.items:
raise Exception("Item '%s' not in list box" % aItem)
self.guiat.Activate()
self._CheckVisibility()
pos = self.location
# click on the first item to focus the list box
Win32API.MouseClick(pos[0] + (pos[2]/2), pos[1] + 3)
# send Home to be sure we are on the first item
# (we could be scrolled down a little)
Win32API.SendKey(Win32API.VK_HOME)
# simulate pressing down arrow until we find the item
# we should find it because it is among self.items
while self.value != aItem:
Win32API.SendKey(Win32API.VK_DOWN)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.