def appendtext(self, window_name, object_name, data): """ Append string sequence. @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param data: data to type. @type data: string @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name) self._grab_focus(obj) if obj.getRole() == pyatspi.ROLE_COMBO_BOX: obj = self._get_child_object_type(obj, pyatspi.ROLE_TEXT) if not obj: raise LdtpServerException('Unable to get combo box children') try: texti = obj.queryEditableText() except NotImplementedError: raise LdtpServerException('Text cannot be entered into object.') texti.setTextContents('%s%s' % (texti.getText(0, texti.characterCount), data.encode('utf-8'))) return 1
def selecttabindex(self, window_name, object_name, tab_index): """ Select tab based on index. @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param tab_index: tab to select @type data: integer @return: 1 on success. @rtype: integer """ children = self._get_tab_children(window_name, object_name) length = len(children) if tab_index < 0 or tab_index > length: raise LdtpServerException(u"Invalid tab index %s" % tab_index) tab_handle = children[tab_index] if not tab_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) tab_handle.Press() return 1
def gettabname(self, window_name, object_name, tab_index): """ Get tab name @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param tab_index: Index of tab (zero based index) @type object_name: int @return: text on success. @rtype: string """ obj = self._get_object(window_name, object_name) self._grab_focus(obj) if tab_index < 0 or tab_index > obj.childCount: raise LdtpServerException('Unable to get page tab name,' \ ' invalid index') name = None try: child = obj.getChildAtIndex(int(tab_index)) name = child.name except NotImplementedError: raise LdtpServerException('Not selectable object.') return name
def oneleft(self, window_name, object_name, iterations): """ Press scrollbar left with number of iterations @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param interations: iterations to perform on slider increase @type iterations: integer @return: 1 on success. @rtype: integer """ if not self.verifyscrollbarhorizontal(window_name, object_name): raise LdtpServerException('Object not horizontal scrollbar') object_handle = self._get_object_handle(window_name, object_name) i = 0 minValue = 1.0 / 8 flag = False while i < iterations: if object_handle.AXValue <= 0: raise LdtpServerException('Minimum limit reached') object_handle.AXValue -= minValue time.sleep(1.0 / 100) flag = True i += 1 if flag: return 1 else: raise LdtpServerException('Unable to decrease scrollbar')
def enterstring(self, window_name, object_name='', data=''): """ Type string sequence. @param window_name: Window name to focus on, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to focus on, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param data: data to type. @type data: string @return: 1 on success. @rtype: integer """ if not object_name and not data: raise LdtpServerException("Not implemented") else: object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) self._grabfocus(object_handle) object_handle.sendKeys(data)
def _internal_menu_handler(self, menu_handle, menu_list, perform_action=False): if not menu_handle or not menu_list: raise LdtpServerException("Unable to find menu %s" % [0]) for menu in menu_list: # Get AXMenu if not menu_handle.AXChildren: try: # Noticed this issue, on clicking Skype # menu in notification area menu_handle.Press() except atomac._a11y.ErrorCannotComplete: pass children = menu_handle.AXChildren[0] if not children: raise LdtpServerException("Unable to find menu %s" % menu) menu_handle = self._get_sub_menu_handle(children, menu) # Don't perform action on last item if perform_action and menu_list[-1] != menu: if not menu_handle.AXEnabled: # click back on combo box menu_handle.Cancel() raise LdtpServerException("Object %s state disabled" % \ menu) # Click current menuitem, required for combo box menu_handle.Press() # Required for menuitem to appear in accessibility list self.wait(1) if not menu_handle: raise LdtpServerException("Unable to find menu %s" % menu) return menu_handle
def gettabname(self, window_name, object_name, tab_index): """ Get tab name @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param tab_index: Index of tab (zero based index) @type object_name: int @return: text on success. @rtype: string """ children = self._get_tab_children(window_name, object_name) length = len(children) if tab_index < 0 or tab_index > length: raise LdtpServerException(u"Invalid tab index %s" % tab_index) tab_handle = children[tab_index] if not tab_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) return tab_handle.AXTitle
def selecttabindex(self, window_name, object_name, tab_index): """ Select tab based on index. @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param tab_index: tab to select @type data: integer @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name) self._grab_focus(obj) if tab_index < 0 or tab_index > obj.childCount: raise LdtpServerException('Unable to get page tab name,' \ ' invalid index') try: selectioni = obj.querySelection() selectioni.selectChild(tab_index) return 1 except NotImplementedError: raise LdtpServerException('Unable to select page tab object.') raise LdtpServerException('Page tab index does not exist')
def _get_menu_hierarchy(self, window_name, object_name, strict_hierarchy = False, wait = True): _menu_hierarchy = re.split(';', object_name) if strict_hierarchy and len(_menu_hierarchy) <= 1: # If strict_hierarchy is set and _menu_hierarchy doesn't have # hierarchy menu's with ; seperated, then raise exception # Fixes bug #590111 - It would be nice if doesmenuexist could # search for strict hierarchies raise LdtpServerException("Invalid menu hierarchy input") if not re.search('^mnu', _menu_hierarchy[0], re.M | re.U): # Add mnu to the first object, if it doesn't exist _menu_hierarchy[0] = 'mnu%s' % _menu_hierarchy[0] obj = self._get_object(window_name, _menu_hierarchy[0], wait) for _menu in _menu_hierarchy[1:]: _flag = False for _child in self._list_objects(obj): if obj == _child: # if the given object and child object matches, as # the _list_objects return object as one of the _child continue if self._match_name_to_acc(_menu, _child): _flag = True obj = _child break if not _flag: raise LdtpServerException( 'Menu item "%s" doesn\'t exist in hierarchy' % _menu) return obj
def selectrowindex(self, window_name, object_name, row_index): """ Select row index @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to select @type row_index: integer @return: 1 on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) count = len(object_handle.AXRows) if row_index < 0 or row_index > count: raise LdtpServerException('Row index out of range: %d' % row_index) cell = object_handle.AXRows[row_index] if not cell.AXSelected: object_handle.activate() cell.AXSelected = True else: # Selected pass return 1
def settextvalue(self, window_name, object_name, data): """ Type string sequence. @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param data: data to type. @type data: string @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name, obj_type=[ 'combo_box', 'text', 'entry', 'paragraph', 'password_text', 'editbar' ]) self._grab_focus(obj) if obj.getRole() == pyatspi.ROLE_COMBO_BOX: obj = self._get_child_object_type(obj, pyatspi.ROLE_TEXT) if not obj: raise LdtpServerException('Unable to get combo box children') try: texti = obj.queryEditableText() except NotImplementedError: raise LdtpServerException('Text cannot be entered into object.') return int(texti.setTextContents(data.encode('utf-8')))
def gettextvalue(self, window_name, object_name, startPosition=None, endPosition=None): """ Get text value @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param startPosition: Starting position of text to fetch @type: startPosition: int @param endPosition: Ending position of text to fetch @type: endPosition: int @return: text on success. @rtype: string """ obj = self._get_object(window_name, object_name, obj_type=[ 'combo_box', 'text', 'entry', 'label', 'paragraph', 'password_text', 'editbar', 'terminal' ]) if obj.getRole() == pyatspi.ROLE_COMBO_BOX: child_obj = self._get_combo_child_object_type(obj) if child_obj.getRole() == pyatspi.ROLE_LIST: obj = self._get_child_object_type(obj, pyatspi.ROLE_TEXT) if not obj: raise LdtpServerException('Unable to get text object') elif child_obj.getRole() == pyatspi.ROLE_MENU: return obj.name else: raise LdtpServerException( 'Unable to get combo box child object') try: texti = obj.queryText() except NotImplementedError: raise LdtpServerException( 'Text cannot be retrieved from object %s.' % obj) if startPosition and startPosition > 0: start = startPosition else: start = 0 if endPosition and endPosition > start: end = endPosition else: end = texti.characterCount text = texti.getText(start, end) try: return unicode(text) except UnicodeDecodeError: return text
def getcellsize(self, window_name, object_name, row_index, column=0): """ Get cell size @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to get @type row_index: integer @param column: Column index to get, default value 0 @type column: integer @return: cell coordinates on success. @rtype: list """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) count = len(object_handle.AXRows) if row_index < 0 or row_index > count: raise LdtpServerException('Row index out of range: %d' % row_index) cell = object_handle.AXRows[row_index] count = len(cell.AXChildren) if column < 0 or column > count: raise LdtpServerException('Column index out of range: %d' % column) obj = cell.AXChildren[column] if not re.search("AXColumn", obj.AXRole): obj = cell.AXChildren[column] return self._getobjectsize(obj)
def gettablerowindex(self, window_name, object_name, row_text): """ Get table row index matching given text @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_text: Row text to select @type row_text: string @return: row index matching the text on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) index = 0 for cell in object_handle.AXRows: if re.match(row_text, cell.AXChildren[0].AXValue): return index index += 1 raise LdtpServerException(u"Unable to find row: %s" % row_text)
def selectrow(self, window_name, object_name, row_text, partial_match=False): """ Select row @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_text: Row text to select @type row_text: string @return: 1 on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) for cell in object_handle.AXRows: if re.match(row_text, cell.AXChildren[0].AXValue): if not cell.AXSelected: object_handle.activate() cell.AXSelected = True else: # Selected pass return 1 raise LdtpServerException(u"Unable to select row: %s" % row_text)
def doubleclickrow(self, window_name, object_name, row_text): """ Double click row matching given text @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_text: Row text to select @type row_text: string @return: row index matching the text on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) object_handle.activate() self.wait(1) for cell in object_handle.AXRows: cell = self._getfirstmatchingchild(cell, "(AXTextField|AXStaticText)") if not cell: continue if re.match(row_text, cell.AXValue): x, y, width, height = self._getobjectsize(cell) # Mouse double click on the object cell.doubleClickMouse((x + width / 2, y + height / 2)) return 1 raise LdtpServerException('Unable to get row text: %s' % row_text)
def doubleclickrowindex(self, window_name, object_name, row_index, col_index=0): """ Double click row matching given text @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to click @type row_index: integer @param col_index: Column index to click @type col_index: integer @return: row index matching the text on success. @rtype: integer """ obj = self._get_object(window_name, object_name) try: tablei = obj.queryTable() except NotImplementedError: raise LdtpServerException('Object not table type.') try: cell = tablei.getAccessibleAt(row_index, col_index) self._grab_focus(cell) size = self._get_size(cell) self._mouse_event(size.x + size.width / 2, size.y + size.height / 2, 'b1d') return row_index finally: raise LdtpServerException('Unable to access row index: %d column: %d' % row_index, col_index)
def selectrowindex(self, window_name, object_name, row_index): """ Select row index @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to select @type row_index: integer @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name) try: tablei = obj.queryTable() except NotImplementedError: raise LdtpServerException('Object not table type.') if row_index < 0 or row_index > tablei.nRows: raise LdtpServerException('Row index out of range: %d' % row_index) cell = tablei.getAccessibleAt(row_index, 0) self._grab_focus(cell) return 1
def rightclick(self, window_name, object_name, row_text): """ Right click on table cell @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to get @type row_index: index @param column: Column index to get, default value 0 @type column: index @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name) try: tablei = obj.queryTable() except NotImplementedError: raise LdtpServerException('Object not table type.') for i in range(0, tablei.nRows): for j in range(0, tablei.nColumns): cell = tablei.getAccessibleAt(i, j) if not cell: continue if cell.childCount > 0: flag = False try: if self._handle_table_cell: # Was externally set, let us not # touch this value flag = True else: self._handle_table_cell = True children = self._list_objects(cell) for child in children: if self._match_name_to_acc(row_text, child): self._grab_focus(child) size = self._get_size(child) self._mouse_event(size.x + size.width / 2, size.y + size.height / 2, 'b3c') return 1 finally: if not flag: self._handle_table_cell = False elif self._match_name_to_acc(row_text, cell): self._grab_focus(cell) size = self._get_size(cell) self._mouse_event(size.x + size.width / 2, size.y + size.height / 2, 'b3c') return 1 raise LdtpServerException('Unable to right click row: %s' % row_text)
def multiselect(self, window_name, object_name, row_text_list, partial_match=False): """ Select multiple row @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_text_list: Row list with matching text to select @type row_text: string @return: 1 on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) object_handle.activate() selected = False try: window = self._get_front_most_window() except (IndexError, ): window = self._get_any_window() for row_text in row_text_list: selected = False for cell in object_handle.AXRows: parent_cell = cell cell = self._getfirstmatchingchild( cell, "(AXTextField|AXStaticText)") if not cell: continue if re.match(row_text, cell.AXValue): selected = True if not parent_cell.AXSelected: x, y, width, height = self._getobjectsize(parent_cell) window.clickMouseButtonLeftWithMods( (x + width / 2, y + height / 2), ['<command_l>']) # Following selection doesn't work # parent_cell.AXSelected=True self.wait(0.5) else: # Selected pass break if not selected: raise LdtpServerException(u"Unable to select row: %s" % row_text) if not selected: raise LdtpServerException(u"Unable to select any row") return 1
def _get_object_map(self, window_name, obj_name, obj_type=None, wait_for_object=True, force_remap=False): if not window_name: raise LdtpServerException("Unable to find window %s" % window_name) window_handle, ldtp_window_name, app=self._get_window_handle(window_name, wait_for_object) if not window_handle: raise LdtpServerException("Unable to find window %s" % window_name) strip=r"( |:|\.|_|\n)" if not isinstance(obj_name, unicode): # Convert to unicode string obj_name=u"%s" % obj_name stripped_obj_name=re.sub(strip, u"", obj_name) obj_name=fnmatch.translate(obj_name) stripped_obj_name=fnmatch.translate(stripped_obj_name) object_list=self._get_appmap(window_handle, ldtp_window_name, force_remap) def _internal_get_object_handle(object_list): # To handle retry this function has been introduced for obj in object_list: if obj_type and object_list[obj]["class"] != obj_type: # If object type is provided and doesn't match # don't proceed further, just continue searching # next element, even though the label matches continue label=object_list[obj]["label"] strip=r"( |:|\.|_|\n)" if not isinstance(label, unicode): # Convert to unicode string label=u"%s" % label stripped_label=re.sub(strip, u"", label) # FIXME: Find object name in LDTP format if re.match(obj_name, obj) or re.match(obj_name, label) or \ re.match(obj_name, stripped_label) or \ re.match(stripped_obj_name, obj) or \ re.match(stripped_obj_name, label) or \ re.match(stripped_obj_name, stripped_label): # Return object map return object_list[obj] if wait_for_object: obj_timeout=self._obj_timeout else: # don't wait for the object obj_timeout=1 for retry in range(0, obj_timeout): obj=_internal_get_object_handle(object_list) if obj: # If object found, return immediately return obj if obj_timeout <= 1: # Don't wait for the object break time.sleep(1) # Force remap object_list=self._get_appmap(window_handle, ldtp_window_name, True) # print(object_list) raise LdtpServerException("Unable to find object %s" % obj_name)
def uncheckrow(self, window_name, object_name, row_index, column = 0): """ Check row @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to get @type row_index: integer @param column: Column index to get, default value 0 @type column: integer @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name) cell = self._get_accessible_at_row_column(obj, row_index, column) flag = None if cell.childCount > 0: flag = False try: if self._handle_table_cell: # Was externally set, let us not # touch this value flag = True else: self._handle_table_cell = True children = self._list_objects(cell) for child in children: try: actioni = child.queryAction() flag = True if self._check_state(child, pyatspi.STATE_CHECKED): self._click_object(child, 'toggle') except NotImplementedError: continue self._grab_focus(cell) break finally: if not flag: self._handle_table_cell = False else: try: actioni = cell.queryAction() flag = True if self._check_state(cell, pyatspi.STATE_CHECKED): self._click_object(cell, 'toggle') except NotImplementedError: raise LdtpServerException('Unable to check row') self._grab_focus(cell) if not flag: raise LdtpServerException('Unable to check row') return 1
def selectrow(self, window_name, object_name, row_text, partial_match=False): """ Select row @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_text: Row text to select @type row_text: string @return: 1 on success. @rtype: integer """ if partial_match: return self.selectrowpartialmatch(window_name, object_name, row_text) obj = self._get_object(window_name, object_name) try: tablei = obj.queryTable() except NotImplementedError: raise LdtpServerException('Object not table type.') for i in range(0, tablei.nRows): for j in range(0, tablei.nColumns): cell = tablei.getAccessibleAt(i, j) if not cell: continue if cell.childCount > 0: flag = False try: if self._handle_table_cell: # Was externally set, let us not # touch this value flag = True else: self._handle_table_cell = True children = self._list_objects(cell) for child in children: if self._match_name_to_acc(row_text, child): self._grab_focus(child) return 1 finally: if not flag: self._handle_table_cell = False elif self._match_name_to_acc(row_text, cell): self._grab_focus(cell) return 1 raise LdtpServerException('Unable to select row: %s' % row_text)
def _get_window_handle(self, window_name, wait_for_window=True): if not window_name: raise LdtpServerException("Invalid argument passed to window_name") # Will be used to raise the exception with user passed window name orig_window_name = window_name window_obj = (None, None, None) strip = r"( |\n)" if not isinstance(window_name, unicode): # Convert to unicode string window_name = u"%s" % window_name stripped_window_name = re.sub(strip, u"", window_name) window_name = fnmatch.translate(window_name) stripped_window_name = fnmatch.translate(stripped_window_name) windows = self._get_windows() def _internal_get_window_handle(windows): # To handle retry this function has been introduced for window in windows: label = windows[window]["label"] strip = r"( |\n)" if not isinstance(label, unicode): # Convert to unicode string label = u"%s" % label stripped_label = re.sub(strip, u"", label) # FIXME: Find window name in LDTP format if re.match(window_name, window) or \ re.match(window_name, label) or \ re.match(window_name, stripped_label) or \ re.match(stripped_window_name, window) or \ re.match(stripped_window_name, label) or \ re.match(stripped_window_name, stripped_label): # Return window handle and window name return (windows[window]["obj"], window, windows[window]["app"]) return (None, None, None) if wait_for_window: window_timeout = self._obj_timeout else: # don't wait for the window window_timeout = 1 for retry in range(0, window_timeout): window_obj = _internal_get_window_handle(windows) if window_obj[0]: # If window object found, return immediately return window_obj if window_timeout <= 1: # Don't wait for the window break time.sleep(1) windows = self._get_windows(True) if not window_obj[0]: raise LdtpServerException('Unable to find window "%s"' % \ orig_window_name) return window_obj
def selectitem(self, window_name, object_name, item_name): """ Select combo box / layered pane item @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param item_name: Item name to select @type object_name: string @return: 1 on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) self._grabfocus(object_handle.AXWindow) try: object_handle.Press() except AttributeError: # AXPress doesn't work with Instruments # So did the following work around x, y, width, height = self._getobjectsize(object_handle) # Mouse left click on the object # Note: x + width/2, y + height / 2 doesn't work self.generatemouseevent(x + 5, y + 5, "b1c") self.wait(5) handle = self._get_sub_menu_handle(object_handle, item_name) x, y, width, height = self._getobjectsize(handle) # on OSX 10.7 default "b1c" doesn't work # so using "b1d", verified with Fusion test, this works self.generatemouseevent(x + 5, y + 5, "b1d") return 1 # Required for menuitem to appear in accessibility list self.wait(1) menu_list = re.split(";", item_name) try: menu_handle = self._internal_menu_handler(object_handle, menu_list, True) # Required for menuitem to appear in accessibility list self.wait(1) if not menu_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % \ menu_list[-1]) menu_handle.Press() except LdtpServerException: object_handle.activate() object_handle.sendKey(AXKeyCodeConstants.ESCAPE) raise return 1
def _internal_menu_handler(self, menu_handle, menu_list, perform_action=False): if not menu_handle or not menu_list: raise LdtpServerException("Unable to find menu %s" % [0]) for menu in menu_list: # Get AXMenu if not menu_handle.AXChildren: try: # Noticed this issue, on clicking Skype # menu in notification area menu_handle.Press() except atomac._a11y.ErrorCannotComplete: if self._ldtp_debug: print(traceback.format_exc()) if self._ldtp_debug_file: with open(self._ldtp_debug_file, "a") as fp: fp.write(traceback.format_exc()) # For some reason, on accessing the lenght first # doesn't crash, else """ Traceback (most recent call last): File "build/bdist.macosx-10.8-intel/egg/atomac/ldtpd/utils.py", line 178, in _dispatch return getattr(self, method)(*args) File "build/bdist.macosx-10.8-intel/egg/atomac/ldtpd/menu.py", line 63, in selectmenuitem menu_handle=self._get_menu_handle(window_name, object_name) File "build/bdist.macosx-10.8-intel/egg/atomac/ldtpd/menu.py", line 47, in _get_menu_handle return self._internal_menu_handler(menu_handle, menu_list[1:]) File "build/bdist.macosx-10.8-intel/egg/atomac/ldtpd/utils.py", line 703, in _internal_menu_handler children=menu_handle.AXChildren[0] IndexError: list index out of range """ len(menu_handle.AXChildren) # Now with above line, everything works fine # on doing selectmenuitem('appSystemUIServer', 'mnu0;Open Display*') children = menu_handle.AXChildren[0] if not children: raise LdtpServerException("Unable to find menu %s" % menu) menu_handle = self._get_sub_menu_handle(children, menu) # Don't perform action on last item if perform_action and menu_list[-1] != menu: if not menu_handle.AXEnabled: # click back on combo box menu_handle.Cancel() raise LdtpServerException("Object %s state disabled" % \ menu) # Click current menuitem, required for combo box menu_handle.Press() # Required for menuitem to appear in accessibility list self.wait(1) if not menu_handle: raise LdtpServerException("Unable to find menu %s" % menu) return menu_handle
def _click_object(self, obj, action = '(click|press|activate)'): try: iaction = obj.queryAction() except NotImplementedError: raise LdtpServerException( 'Object does not have an Action interface') else: for i in xrange(iaction.nActions): if self._ldtp_debug: print(iaction.getName(i)) if re.match(action, iaction.getName(i), re.I): iaction.doAction(i) return raise LdtpServerException('Object does not have a "%s" action' % action)
def setvalue(self, window_name, object_name, data): """ Type string sequence. @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param data: data to type. @type data: double @return: 1 on success. @rtype: integer """ obj = self._get_object(window_name, object_name) try: valuei = obj.queryValue() except NotImplementedError: raise LdtpServerException('Value cannot be entered into object.') valuei.currentValue = float(data) return 1
def doubleclick(self, window_name, object_name): """ Double click on the object @param window_name: Window name to look for, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to look for, either full name, LDTP's name convention, or a Unix glob. Or menu heirarchy @type object_name: string @return: 1 on success. @rtype: integer """ object_handle = self._get_object_handle(window_name, object_name) if not object_handle.AXEnabled: raise LdtpServerException(u"Object %s state disabled" % object_name) self._grabfocus(object_handle) x, y, width, height = self._getobjectsize(object_handle) window = self._get_front_most_window() # Mouse double click on the object #object_handle.doubleClick() window.doubleClickMouse((x + width / 2, y + height / 2)) return 1
def setcellvalue(self, window_name, object_name, row_index, column=0, data=None): """ Set cell value @param window_name: Window name to type in, either full name, LDTP's name convention, or a Unix glob. @type window_name: string @param object_name: Object name to type in, either full name, LDTP's name convention, or a Unix glob. @type object_name: string @param row_index: Row index to get @type row_index: integer @param column: Column index to get, default value 0 @type column: integer @param data: data, default value None None, used for toggle button @type data: string @return: 1 on success. @rtype: integer """ raise LdtpServerException("Not implemented")