""" GUI Automated Testing This module contains interface to the TextBox component. """ __author__ = "Lukas Cenovsky (lukas.cenovsky@bakalari.cz)" __version__ = "0.2" __date__ = "August 2008" __copyright__ = "Copyright (c) 2008 Lukas Cenovsky" from time import sleep from Win32API import Win32API from BaseComponent import BaseComponent class TextBox(BaseComponent): """interface to the TextBox component""" def FocusEditor(self): """ set cursor to the text edit we cannot test if it contains the focus because the method self._control.Focused does not work""" self.guiat.Activate() self._CheckVisibility() pos = self.location Win32API.MouseClick(pos[0] + (pos[2]/2), pos[1] + (pos[3]/2)) sleep(0.2) def Clear(self): """ clear the text from text edit simulate pressing Home key and multiple Delete keys until the text edit is empty""" self.FocusEditor() Win32API.SendKey(Win32API.VK_HOME) # sending just len(TextBox.Text) Delete keys might not be enough for i in range(2000): if self.value == '': break else: Win32API.SendKey(Win32API.VK_DELETE) if self.value != '': raise Exception("Text not cleared: '%s'" % self.value) def Write(self, aString): """ write text to the control""" self.Clear() Win32API.SendString(aString) sleep(0.2) if self.value != aString: raise Exception("Text '%s' not written correctly: '%s'" % \ (aString, self.value)) # property providing easy access to the text box component value value = property(lambda self: self._control.Text, Write)