def on_call(*args, **kwargs): _cls_name = args[0].__class__.__name__ _met_name = func.__name__ _element_name = args[0].name try: result = func(*args, **kwargs) if result is not None: logger.debug( '[Call]: {0} >> {1} >> {2} [Return]: {3}'.format( _cls_name, _met_name, _element_name, result)) else: logger.debug('[Call]: {0} >> {1} >> {2}'.format( _cls_name, _met_name, _element_name)) return result except NoSuchElementException: logger.error( '[NoSuchElementException]: Fail to locate element {0}'. format(_element_name)) except WebDriverException as e: exc_type, _, _ = sys.exc_info() logger.error('[{0}]: {1}'.format(exc_type.__name__, e).rstrip()) raise except Exception: logger.exception('[UnwantedException]:') raise
def send_specific_keys(self, *args): keys_set = set() redundant_keys = [ 'BACK_SPACE', 'LEFT_SHIFT', 'LEFT_CONTROL', 'LEFT_ALT', 'ARROW_LEFT', 'ARROW_UP', 'ARROW_RIGHT', 'ARROW_DOWN' ] try: keys_mapping = dict( filter(lambda d: d[0] not in redundant_keys, Keys.__dict__.items())) for arg in args: pattern = re.compile(arg, re.IGNORECASE) for attr in keys_mapping: result = re.search(pattern, attr) if result: keys_set.add(attr) if keys_set: self.driver.send_keys(*keys_set) logger.debug( '[Call]: KeyActions >> send_specific_keys >> {0}'.format( ' + '.join(keys_set))) else: self.driver.send_keys('') logger.warning( '[Call]: KeyActions >> send_specific_keys >> empty content' ) except WebDriverException as e: exc_type, _, _ = sys.exc_info() logger.error('[{0}]: {1}'.format(exc_type.__name__, e).rstrip()) raise except Exception: logger.exception('[UnwantedException]:') raise
def wrapper(*args, **kwargs): try: logger.debug('[Assert]: {0} >> {1}'.format(func.__name__, format(args[1:]))) return func(*args, **kwargs) except AssertionError as e: args[0].Exc_Stack.append(e)
def wrapper(*args, **kwargs): try: result = func(*args, **kwargs) logger.debug('Parse "{0}", get config value "{1}"'.format(func.__name__, result)) return result except Exception as e: logger.error('Fail to parse "{0}": {1}'.format(func.__name__, e)) raise e
def on_call(*args, **kwargs): _cls_name = args[0].__class__.__name__ _met_name = func.__name__ try: result = func(*args, **kwargs) _result = True if result else False logger.debug('[Call]: {0} >> {1} [Return]: {2}'.format( _cls_name, _met_name, _result)) return result except TimeoutException as e: logger.warning('[TimeoutException]: {0}'.format(e).rstrip()) except WebDriverException as e: exc_type, _, _ = sys.exc_info() logger.error('[{0}]: {1}'.format(exc_type.__name__, e).rstrip()) raise except Exception: logger.exception('[UnwantedException]:') raise
def __getattr__(self, attr): logger.debug('Call: {0} >> {1}'.format(cls.__name__, attr)) method = getattr(self.wrapped, attr) return method