The foundation of our test framework are IronPython classes that control Windows components. Simply said, everything in Windows is a component. So we create IronPython layer that allows controlling each Windows component easily. Then we create classes that will control forms with many components. And finally, we build test scripts and test suites for the whole application.
We start with just three simple classes. The first class, GUIAT, is the core class taking care of running, activating (focusing), and inspecting the tested application. The second class, BaseComponent, is ancestor of all component classes. The last one, Form, descendant of BaseComponent, is ancestor of all forms.
The BaseComponent class provides access to common properties of all components. There is just one in the first version:
- location - size and position of the component on the screen (not within the parent form)
- _name - name of the component, not all components have this field filled
- _control - reference to the .NET component instance
- _guiat - reference to the main GUIAT object (see below)
- _guiatComponents - dictionary with all child GUIAT components
- _GetComponentByName - method that searches for component with given name
The Form class extends the BaseComponent class. Its purpose is to find and store all components on itself. It has one private method that does it:
- _AnalyzeStructure - method that searches and stores components on a form. It is recursively called for each member of the Controls collection. It prints out the name, type, and depth level of the found components. Then it creates BaseComponent instance and stores it into the _guiatComponents dictionary of the parent component.
- mainForm - GUIAT representation of the main form of the tested application (Form instance)
- Run - method that runs the tested application in separate thread and creates the Form instance of the main form
- Activate - method that activates (focuses) the tested application
>>> import GUIATThe above code runs the tested application, lists name and type of all components, then prints location of the text box, and finally activates the tested application.
>>> g = GUIAT.GUIAT()
>>> g.Run()
Starting GUIAT...
"frmGUIAT" (frmGUIAT)
"btnAddItem" (Button)
"lblNewItem" (Label)
"txtNewItem" (TextBox)
"lbxItems" (ListBox)
"btnQuit" (Button)
Starting GUIAT done.
>>> print g.mainForm._GetComponentByName('txtNewItem').location
(212, 177, 96, 16)
>>> g.Activate()
True
To sum up the process again:
- Create instance of the GUIAT class - let's call it g
- g.Run() runs the tested application
- g.Run() creates instance of IronPython Form class for the main form of the tested application
- The Form instance searches during its initialization all components on the main form, prints information about them, and creates BaseComponent instance for each of them
- To find location of "txtNewItem" component, execute:
g.mainForm._GetComponentByName("txtNewItem").location - To activate tested application, execute:
g.Activate()