def ctl_get(c_type, parent=None, src_li=None, timeout=Delay('0s'), number=None, negative=False, single=False, none=False, _assert=False, index=None, attributes={}, attr_dict=None): ct = CONTROL_TYPES.get(c_type) if ct: criteria = SearchCriteria.ByControlType(CONTROL_TYPES.get(c_type)) else: criteria = SearchCriteria.All attr_filters = attributes.get('wait', []) for _ in waiting_iterator(timeout): if parent: #logging.warning(repr(parent) + repr(dir(parent))) if isinstance(parent, list): raise IronbotException("Ctl Get: 'parent' should contain a single window, not a list (check if there is a 'single' or 'index' parameter when searching for that window).") mult = parent.GetMultiple(criteria) li = [elem for elem in mult] elif src_li: li = list(src_li) for attr, params in attr_filters: li = [item for item in li if attr_dict.action(item, attr, 'wait', params)] if negative: li = filter(lambda v: v not in li, src_li) ok, res, msg = result_modifier(li, src_list=src_li, single=single, none=none, number=number, index=index) if ok: return res if _assert: logging.error('Ctl Get failed: %s' % msg) raise IronbotException('Ctl Get failed: %s' % msg) logging.warning('Ctl Get failed: %s' % msg) return res
def _attr(controls, attributes, attr_dict, timeout=Delay('0s'), _assert=False): single = False ctls = controls if not isinstance(ctls, list): ctls = [ctls] single = True gets = _dict_pop(attributes, 'get', []) sets = _dict_pop(attributes, 'set', []) waits = _dict_pop(attributes, 'wait', []) #dos = _dict_pop(attributes, 'do', []) others = {} for k in list(attributes.keys()): others[k] = _dict_pop(attributes, k, []) success = True for _ in waiting_iterator(timeout): #logging.warning("CHECKING %s" % repr(timeout.value)) success = True for c in ctls: for a, p in waits: if not attr_dict.action(c, a, 'wait', p): success = False if success: break if not success: if _assert: raise IronbotTimeoutException('Error: Attribute timeout') logging.warning('Error: Attribute timeout') res = [] for c in ctls: ctl_gets = [] for a, p in gets: ctl_gets.append(attr_dict.action(c, a, 'get', p)) if len(ctl_gets) == 1: ctl_gets = ctl_gets[0] res.append(ctl_gets) #res = [(lambda li: li[0] if len(gets) == 1 else li) # ([attr_dict.action(c, a, 'get', p) for a, p in gets]) for c in ctls] for k, v in others.iteritems(): for a, p in v: for c in ctls: attr_dict.action(c, a, k, p) for a, p in sets: for c in ctls: attr_dict.action(c, a, 'set', p) if single: return res[0] return res
def dream(delay): """ Dream | <delay> Waits for a given period of tima, and checks for events from error handlers when waiting. :param delay: :return: None """ for _ in waiting_iterator(delay): pass
def ctl_get(c_type, parent=None, src_li=None, timeout=Delay('0s'), number=None, negative=False, single=False, none=False, _assert=False, index=None, attributes={}, attr_dict=None): """ Ctl Get | <c_type> [| <parent>/<src_li> ] | attributes & paramsa :param c_type: control type name (all, button, edit, menu, list, listitem, radio, radiobutton, checkbox, tab, tree, treenode, toolbar) :param parent: an optional named parameter, parent window. Incompatible with src_li :param src_li: an optional named parameter, a list of controls to filter. :param negative: inverts filtering :return: """ ct = CONTROL_TYPES.get(c_type) if ct: criteria = SearchCriteria.ByControlType(CONTROL_TYPES.get(c_type)) else: criteria = SearchCriteria.All attr_filters = attributes.get('wait', []) for _ in waiting_iterator(timeout): if parent: #logging.warning(repr(parent) + repr(dir(parent))) if isinstance(parent, list): raise IronbotException("Ctl Get: 'parent' should contain a single window, not a list (check if there is a 'single' or 'index' parameter when searching for that window).") mult = parent.GetMultiple(criteria) li = [elem for elem in mult] elif src_li: li = list(src_li) for attr, params in attr_filters: li = [item for item in li if attr_dict.action(item, attr, 'wait', params)] if negative: li = filter(lambda v: v not in li, src_li) ok, res, msg = result_modifier(li, src_list=src_li, single=single, none=none, number=number, index=index) if ok: return res if _assert: logging.error('Ctl Get failed: %s' % msg) raise IronbotException('Ctl Get failed: %s' % msg) logging.warning('Ctl Get failed: %s' % msg) return res
def app_state(app, running=True, timeout=Delay('0s'), any=False, all=False, single=False, none=False, _assert=False, number=None): """ App State | <app> | params :param app: required, positional -- an application object; :param running: an optional flag -- the result is True if the app is running; :param not_running: an optional flag -- the result is True if the app is not running; :param kill: an optional flag -- same as not_running plus kills the app after waiting; :param assert: an optional flag -- fail keyword on failure; :param timeout: optional, followed by a delay value, e.g. *10s -- wait for the desired state. :return: True if the app state at the end of waiting is as desired, otherwise False """ src_app = app if not isinstance(src_app, list): app = [app] kill = running is None running = bool(running) prefer_bool = all or any or single or none or not isinstance(src_app, list) for _ in waiting_iterator(timeout): res_list = [] for a in app: res_list.append(bool(a.HasExited) != bool(running)) ok, res, msg = result_modifier(res_list, src_list=src_app, any=any, all=all, single=single, none=none, number=number, prefer_bool=prefer_bool) if ok: break if kill: for a in app: if not a.HasExited: logging.warning('Killing an application') a.Dispose() if ok: return res if _assert: logging.error('App State failed: %s' % msg) raise IronbotTimeoutException('App State failed: %s' % msg) logging.warning('App State failed: %s' % msg) return res
def wnd_get(app=None, parent=None, attr_dict=None, **kw): """ Wnd Get | params and attrs Finds windows on desktop, in app, or by parent window (in case of a modal window). :param parent: (named) specifies a parent window. Incompatible with "app". :param app: (named) specifies an application object. If both parent and app are absent, the keyword looks for a window on desktop. :return: List of windows or a single window (if "single is given"). """ if app and parent: raise IronbotException("You may specify either 'app' or 'parent' parameter, not both") timeout = kw.get('timeout', None) if 'timeout' in kw: del kw['timeout'] for _ in waiting_iterator(timeout): exc, res = None, None try: try: if app: wnd_list = [w for w in app.GetWindows()] elif parent: wnd_list = [w for w in parent.ModalWindows()] else: wnd_list = [w for w in Desktop.Instance.Windows()] except: logging.error("Wnd Get: unable to obtain wnd_list: %s" % format_exc()) wnd_list = [] res = _wnd_filter(wnd_list, attr_dict=attr_dict, **kw) except Exception, e: exc = e if res: return res
def wnd_get(app=None, parent=None, attr_dict=None, **kw): if app and parent: raise IronbotException("You may specify either 'app' or 'parent' parameter, not both") timeout = kw.get('timeout', None) if 'timeout' in kw: del kw['timeout'] for _ in waiting_iterator(timeout): exc, res = None, None try: try: if app: wnd_list = [w for w in app.GetWindows()] elif parent: wnd_list = [w for w in parent.ModalWindows()] else: wnd_list = [w for w in Desktop.Instance.Windows()] except: logging.error("Wnd Get: unable to obtain wnd_list: %s" % format_exc()) wnd_list = [] res = _wnd_filter(wnd_list, attr_dict=attr_dict, **kw) except Exception, e: exc = e if res: return res
def _attr(controls, attributes, attr_dict, timeout=Delay('0s'), _assert=False): """ Kbd/Ctl/Proc/Wnd Attr | <objects> | parameters & attributes Operations on attributes of objects. First performs 'wait' operations, then the 'get' ones, then all the rest except 'set', and finally the 'set' ones. :param objects: An object or a list of objects to operate on. :return: A list of 'get' operations, or a list of lists, if there are many 'get' operations. """ single = False ctls = controls if not isinstance(ctls, list): ctls = [ctls] single = True gets = _dict_pop(attributes, 'get', []) sets = _dict_pop(attributes, 'set', []) waits = _dict_pop(attributes, 'wait', []) #dos = _dict_pop(attributes, 'do', []) others = {} for k in list(attributes.keys()): others[k] = _dict_pop(attributes, k, []) success = True for _ in waiting_iterator(timeout): #logging.warning("CHECKING %s" % repr(timeout.value)) success = True for c in ctls: for a, p in waits: if not attr_dict.action(c, a, 'wait', p): success = False if success: break if not success: if _assert: raise IronbotTimeoutException('Error: Attribute timeout') logging.warning('Error: Attribute timeout') res = [] for c in ctls: ctl_gets = [] for a, p in gets: ctl_gets.append(attr_dict.action(c, a, 'get', p)) if len(ctl_gets) == 1: ctl_gets = ctl_gets[0] res.append(ctl_gets) #res = [(lambda li: li[0] if len(gets) == 1 else li) # ([attr_dict.action(c, a, 'get', p) for a, p in gets]) for c in ctls] for k, v in others.iteritems(): for a, p in v: for c in ctls: attr_dict.action(c, a, k, p) for a, p in sets: for c in ctls: attr_dict.action(c, a, 'set', p) if single: return res[0] return res