""" GUI Automated Testing This module contains base class of all forms. """ __author__ = "Lukas Cenovsky (cenovsky@bakalari.cz)" __version__ = "0.3" __date__ = "August 2008" __copyright__ = "Copyright (c) 2008 Lukas Cenovsky" from BaseComponent import BaseComponent from Button import Button from TextBox import TextBox from ListBox import ListBox RecognizableComponents = { 'Button': Button, 'Label': BaseComponent, 'TextBox': TextBox, 'ListBox': ListBox, } class Form(BaseComponent): """ base class holding common properties and methods for all forms """ # the following methods are considered private def __init__(self, aControl, aGUIAT): """ Form constructor @aControl - .NET component object @aGUIAT - GUIAT main object """ BaseComponent.__init__(self, aControl, aGUIAT) self._AnalyzeStructure() def _AnalyzeStructure(self, aControl=None, aResult=None, aLevel=' '): """ analyze the structure of the form; fill self._guiatComponents dictionary the initial call is without parameters - that means we want to analyze the self object (the form) - see GUIAT.Run method the recursive calls are with all parameters: @aControl - the object we are going to inspect @aResult - dictionary where the found components are stored @aLevel - for of objects hierarchy pretty printing the result is dictionary of objects: {component_name: component} the component can contains the same structured dictionary of its components (self._guiatComponents[0]._guiatComponents[0]._guiatComponents and so on) """ if aControl == None: aControl = self._control if aResult == None: print'"%s" (%s)' % (aControl.Name, aControl.GetType().Name) self._guiatComponents = {} aResult = self._guiatComponents for c in aControl.Controls: # create the appropriate GUIAT object for known components # create BaseComponent for the others if c.GetType().Name in RecognizableComponents: # we know the component, let's inspect it print'%s"%s" (%s)' % (aLevel, c.Name, c.GetType().Name) # creates GUIAT object # RecognizableComponents[c.GetType().Name] is GUIAT class that can control # the .NET component instance; calling it creates the GUIAT object aResult[c.Name] = RecognizableComponents[c.GetType().Name](c, self.guiat) # analyze the structure of the found component self._AnalyzeStructure(c, aResult[c.Name]._guiatComponents, aLevel+' ') else: # we have do not know the component - create BaseComponent try: print'%s"%s" (%s) - UNKNOWN' % (aLevel, c.Name, c.GetType().Name) except Exception, e: print '\n\n%s%s\n%s\n' % (aLevel, c, e) aResult[c.Name] = BaseComponent(c, self.guiat) self._AnalyzeStructure(c, aResult[c.Name]._guiatComponents, aLevel+' ')