def __getattr__(self, name): from arjuna import log_trace if type(name) is str and not name.startswith("__"): try: val = self[name] log_trace("Space: Got value {} for {}.".format(val, name)) return val except Exception as e: log_trace("Space: No value for {} in any scope.".format(name)) raise AttributeError(str(e))
def __getitem__(self, name): scopes = _LOOKUP_ORDER[self._request.scope] from arjuna import log_trace for scope in scopes: log_trace("Space: Getting value for {} from {} scope".format(name, scope)) try: container = getattr(self._request, _SCOPE_MAP[scope]) return getattr(container, name) except Exception as e: log_trace("Space: No value for {} in {} scope".format(name, scope)) continue raise Exception("Attribute with name >>{}<< does not exist in request scope for {}".format(name, scopes))
def find(self, dispatcher_call, wmd, context="ELEMENT"): from arjuna import log_trace, log_debug log_trace("Finding with wmd: {}".format(str(wmd))) from arjuna import Arjuna found = False js_call_name = context == "ELEMENT" and "_find_element_with_js" or "_find_multielement_with_js" js_call = getattr(self.container, js_call_name) locators = wmd.locators if context != "ELEMENT": if "POINT" in {l.ltype.name for l in locators}: raise ConditionException( "With.POINT can be used only with GuiElement.") # Prepare Relations dict we = None for locator in locators: try: if locator.ltype.name == "POINT": # Assumption here is that this container is automator. size, dispatcher = js_call(locator.lvalue) elif locator.ltype.name == "JS": size, dispatcher = js_call(locator.lvalue) else: lvalue = locator.lvalue if locator.ltype.name == "XPATH": if not lvalue.startswith("."): lvalue = "." + lvalue log_debug("Trying out locator {} with value {}".format( locator.ltype.name, lvalue)) size, dispatcher = dispatcher_call( locator.ltype.name, lvalue, relations=wmd.meta.relations, filters=wmd.meta.filters) return locator.ltype.name, locator.lvalue, size, dispatcher except WaitableError as e: log_debug("Waitable exception raised.") we = e except Exception as f: log_debug("Non-Waitable exception raised: {}: {}".format( f.__class__.__name__, str(f))) raise f else: we = None if not found: raise GuiWidgetNotFoundError(*wmd.locators, relations=wmd.meta.relations, filters=wmd.meta.filters, container=self.__container)
def __setattr__(self, name, value): container = self._get_container_for_scope() from arjuna import log_trace log_trace("Space: Setting {}={} in {} scope".format( name, value, self._request.scope)) #, contexts="request") setattr(container, name, value)