Ejemplo n.º 1
0
 def execute_action(self,
                    action,
                    element_condition:
                    expected_conditions = presence_of_element_located,
                    *args):
     try:
         obj = getattr(self.get_element(element_condition), action)
         if isinstance(obj, str):
             self.__retry_count = 0
             return obj
         else:
             if self.action_element:
                 self.inject_js_waiter()
             if args:
                 value = obj(*args)
             else:
                 value = obj()
             if self.action_element:
                 self.wait_until_http_requests_are_finished()
             return value
     except (StaleElementReferenceException, WebDriverException,
             InvalidElementStateException) as e:
         if self.__retry_count <= 2:
             self.__retry_count += 1
             Log.error('Error on performing \'%s\' action. Retrying...' %
                       action)
             Log.error(e.msg)
             time.sleep(retry_delay)
             if 'is not clickable at point' in e.msg:
                 self.scroll_to_element()
             return self.execute_action(action, element_condition, *args)
         else:
             raise e
Ejemplo n.º 2
0
 def quit(self):
     if self.get_driver():
         Log.debug("Closing the Appium driver session")
         try:
             self.get_driver().quit()
         except Exception as e:
             Log.error("Can't quit Appium driver")
             Log.error(e)
         finally:
             self.session = None
Ejemplo n.º 3
0
 def wait_until_http_requests_are_finished(
         self, wait_time: int = http_request_wait_time):
     try:
         end_time = time.time() + wait_time
         while True:
             if not self.execute(
                     "return window.openHTTPs") or time.time() > end_time:
                 break
     except TimeoutException:
         Log.error('HTTP request execution time is more than %s seconds' %
                   wait_time)
         self.execute("window.openHTTPs=0")