def _select_custom_tree_control_item(self, win): try: pos = int(self.arg(1)) text = self.arg(2) win.select_custom_tree_control_item(pos, text) except NotFoundException: Logger.add_error("Custom tree control #%d item %s not found" % (pos, text))
def click_mouse(self, position): try: self._send_lbutton_click_to_window(position) Logger.add_result("Mouse clicked at (%d, %d)" % (position[0], position[1])) except NotFoundException: Logger.add_error("Mouse click failed")
def _enter_text(self, win): pos = int(self.arg(1)) text = self.arg(2) try: win.enter_text(pos, text) except NotFoundException: Logger.add_error("Text control #%d not found" % pos)
def MessageBox(*args, **kw): Logger.add_result("MessageBox '%s' opened" % args[1]) wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, _explore_and_register) rv = wxMessageBox(*args, **kw) Logger.add_result("MessageBox '%s' closed" % args[1]) return rv
def _enter_text(self, win): pos = int(self.arg(1)) text = self.arg(2) try: win.enter_text(pos, text) except NotFoundException: Logger.add_error("Text control #%d not found" % pos)
def _click_button(self, win): name = self.arg(1) try: win.click_button(name) except NotFoundException: Logger.add_error("Button(%s) not found. hwnd=%d" % (name, win.hwnd))
def start_app(mymanuscript, path): global manuscript manuscript = mymanuscript wrap_wx_classes() Logger.header("Starting application %s" % os.path.basename(path)) run_python_file([ path, ])
def describe(self,frame): try: menu_bar = frame.GetMenuBar() if menu_bar is not None: self.describe_menu_bar(menu_bar) Logger.add(" ") except AttributeError: pass
def _select_custom_tree_control_item(self, win): try: pos = int(self.arg(1)) text = self.arg(2) win.select_custom_tree_control_item(pos, text) except NotFoundException: Logger.add_error("Custom tree control #%d item %s not found" % (pos, text))
def describe(self, frame): try: menu_bar = frame.GetMenuBar() if menu_bar is not None: self.describe_menu_bar(menu_bar) Logger.add(" ") except AttributeError: pass
def _select_combobox_item(self, win): try: pos = int(self.arg(1)) text = self.arg(2) win.select_combobox_item(pos, text) except NotFoundException: Logger.add_error("ComboBox control #%d item %s not found" % (pos, text))
def register_dialog(self, win=None): if win is None: return self.windows.append(win) if not self.execution_started: Logger.add_instruction("Execution of instructions start") self.execution_started = True wx.CallLater(TIME_TO_WAIT_BEFORE_CONTINUING_IN_MILLISECONDS, self.execute_next_instruction)
def describe_wxdialog_windows(self, win, level=0): try: for child in win.Children: child_id = child.GetId() margin = "%*.*s" % (level*3, level*3, "") Logger.add(" %s%4d %-24.24s %-16.16s '%s'" % (margin, child_id, child.GetClassName(), child.GetLabel(), child.GetName())) self.describe_wxdialog_windows(child, level+1) except AttributeError: Logger.add(" No children exiets")
def execute_next_instruction(self): try: instruction = self._next_instruction() self._display_instruction_in_popup_window(instruction) if instruction.comment: delay = 0 else: # TODO: We have some timing problem so we can't set # waiting time to 0. 40 seems to be ok, delay = max(40, self.args.timedelay() * 1000) wx.CallLater(delay, self._execute_instruction, instruction) except NoMoreInstructionsException: Logger.add("INSTRUCTION: None")
def describe_menu(self, menu, name): Logger.add(" ") Logger.add(" Menu: '%s' Item count: %d" % (name, menu.MenuItemCount)) Logger.add(" Id Label Text") Logger.add(" ---- ------------------------ ---------------------") for item in menu.MenuItems: self.describe_menu_item(item) if item.SubMenu is not None and item.SubMenu.MenuItemCount > 0: self.describe_submenu(item.SubMenu)
def describe_menu(self, menu, name): Logger.add(" ") Logger.add(" Menu: '%s' Item count: %d" % (name, menu.MenuItemCount)) Logger.add(" Id Label Text") Logger.add( " ---- ------------------------ ---------------------") for item in menu.MenuItems: self.describe_menu_item(item) if item.SubMenu is not None and item.SubMenu.MenuItemCount > 0: self.describe_submenu(item.SubMenu)
def describe_wxdialog(self, win, level=0): if win is None: return try: if len(win.Children) == 0: return except AttributeError: return Logger.newline() Logger.header2("wx Description") Logger.add(" Id Classname Label Name") Logger.add(" ---- ------------------------ ---------------- ----------------") self.describe_wxdialog_windows(win)
def start_test(args, manuscript): if len(manuscript.filepaths) > 0: Logger.set_path(get_logpath(manuscript.filepaths[0])) Logger.set_log_dialog_descriptions(args.descriptions()) Logger.add_section("Manuscript", str(manuscript)) start_app(manuscript, args.program()) else: print "The start script can't be found"
def execute(self, manuscript, win): # Everything ends here so we don't bother to call Instruction.execute manuscript.get_application_frame().Destroy() Logger.add_result("Application destroyed")
def _close_frame(self, win): win, name = self.find_win(win, "wxFrame", self.arg(1)) try: win.Destroy() except NotFoundException: Logger.add_error("Frame(%s) not found" % name)
def Destroy(self, *args, **kw): self._shown = False Logger.add_close(self) wxFileDialog.Destroy(self, *args, **kw)
def Destroy(self, *args, **kw): self.shown = False Logger.add_result("Dialog '%s' closed" % self.GetLabel()) wxColourDialog.Destroy(self, *args, **kw)
def Show(self, *args, **kw): self._shown = True Logger.add_open(self) self.call_when_win_shows(self._explore_and_register) super(PreviewFrame, self).Show(*args, **kw)
def Print(self, *args, **kw): self._shown = True Logger.add_open(self) self.call_when_win_shows(self._explore_and_register) super(Printer, self).Print(*args, **kw) self._shown = False
def _clik_mouse(self, win): pos = self._position(win) try: win.click_mouse(pos) except NotFoundException: Logger.add_error("Mouse click at (%d, %d) failed" % (pos[0], pos[1]))
def ShowModal(self): Logger.add_result("MessageDialog opened") wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, self._explore, MessageDialog.listener) super(MessageDialog, self).ShowModal()
def start_app(mymanuscript, path): global manuscript manuscript = mymanuscript wrap_wx_classes() Logger.header("Starting application %s" % os.path.basename(path)) run_python_file([path,])
def _hide_frame(self, win): try: win, name = self.find_win(win, "wxFrame", self.arg(1)) win.Hide() except NotFoundException: Logger.add_error("Frame(%s) not found" % name)
def _close_frame(self, win): win, name = self.find_win(win, "wxFrame", self.arg(1)) try: win.Destroy() except NotFoundException: Logger.add_error("Frame(%s) not found" % name)
def __init__(self, *args, **kw): Logger.add_result("AboutBox opened") wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, self._register_and_explore) wxAboutBox(*args, **kw)
def ShowModal(self): Logger.add_result("MessageDialog opened") wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, self._explore, MessageDialog.listener) super(MessageDialog, self).ShowModal()
def click_mouse(self, position): try: self._send_lbutton_click_to_window(position) Logger.add_result("Mouse clicked at (%d, %d)" % (position[0], position[1])) except NotFoundException: Logger.add_error("Mouse click failed")
def _select_menu(self, win): try: item_id = self._find_menu_item_id(win) win.click_menu_item(item_id) except NotFoundException: Logger.add_error("Menu not found")
def MessageBox(*args, **kw): Logger.add_result("MessageBox '%s' opened" % args[1]) wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, _explore_and_register) rv = wxMessageBox(*args, **kw) Logger.add_result("MessageBox '%s' closed" % args[1]) return rv
def _hide_frame(self, win): try: win, name = self.find_win(win, "wxFrame", self.arg(1)) win.Hide() except NotFoundException: Logger.add_error("Frame(%s) not found" % name)
def describe_children(self, hwnd): Logger.add(" hwnd Classname Label") Logger.add(" ------- ------------------------ ------------------") children = win.get_children(hwnd) for hwnd, class_name, text in children: Logger.add(" %8d %-24.24s '%s'" % (hwnd, class_name, text))
def describe_window(self, hwnd): if hwnd == None: hwnd = win.get_active_window() Logger.header(" Window Description hwnd: %d Classname: '%s' Label: '%s'" % (hwnd, win.get_classname(hwnd), win.get_window_text)) Logger.header2("Native Description") self.describe_children(hwnd)
def ShowModal(self): self._shown = True Logger.add_open(self) self.call_when_win_shows(self._explore_and_register) super(FileDialog, self).ShowModal()
def Destroy(self, *args, **kw): self.shown = False Logger.add_close(self) wxPageSetupDialog.Destroy(self, *args, **kw)
def ShowModal(self, *args, **kw): self.shown = True Logger.add_result("Dialog opened") wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, self._register_and_explore) super(ColourDialog, self).ShowModal(*args, **kw)
def Destroy(self, *args, **kw): self._shown = False Logger.add_close(self) wxFileDialog.Destroy(self, *args, **kw)
def describe_menu_item(self, item): Logger.add(" %4d %-24.24s '%s' " % (item.Id, item.Label, item.Text) )
def setUp(self): Logger.set_path(os.path.join(os.path.dirname(__file__), "test.log")) self.instruction = create_instruction(EXIT_INSTRUCTION) self.win = WinMock() self.manuscript = Mock(Manuscript) self.manuscript.get_application_frame.return_value = self.win
def describe_submenu(self, submenu): Logger.add(" ") Logger.add(" Submenu Item count: %d" % (submenu.MenuItemCount)) Logger.add(" Id Label Text") Logger.add(" ---- ------------------------ ---------------------") for item in submenu.MenuItems: Logger.add(" %4d %-24.24s '%s' " % (item.Id, item.Label, item.Text) ) Logger.add(" ")
def Destroy(self, *args, **kw): self._shown = False Logger.add_close(self) wxPreviewFrame.Destroy(self, *args, **kw)
def _close_dialog(self, win): win, name = self.find_win(win, "wxDialog", self.arg(1)) try: win.EndModal(wx.ID_CANCEL) except: Logger.add_error("Dialog(%s) not found" % name)
def ShowModal(self): self._shown = True Logger.add_open(self) self.call_when_win_shows(self._explore_and_register) super(FileDialog, self).ShowModal()
def ShowModal(self, *args, **kw): self.shown = True Logger.add_result("Dialog opened") wx.CallLater(TIME_TO_WAIT_FOR_DIALOG_TO_SHOW_IN_MILLISECONDS, self._register_and_explore) super(ColourDialog, self).ShowModal(*args, **kw)
def _close_dialog(self, win): win, name = self.find_win(win, "wxDialog", self.arg(1)) try: win.EndModal(wx.ID_CANCEL) except: Logger.add_error("Dialog(%s) not found" % name)
def Destroy(self, *args, **kw): self.shown = False Logger.add_result("Dialog '%s' closed" % self.GetLabel()) wxColourDialog.Destroy(self, *args, **kw)
def describe_menu_bar(self, menu_bar): Logger.newline() Logger.header2("Menu Bar: count = %d" % menu_bar.MenuCount) for menu, name in menu_bar.Menus: self.describe_menu(menu, name)
def Hide(self): self._shown = False Logger.add_close(self) super(Frame, self).Hide()