def inject_waiter(self): Log.debug( "Injecting JavaScrip HTTP requests waiter into '%s' element" % self.element_name) with open(js_waiter_file, 'r') as content: js_waiter = content.read() self.execute(js_waiter)
def get_rows_by_attribute_value(self, column_name: str, attribute_name: str, attribute_value: str, wait_time: int = element_load_time) -> T: Log.debug( f"Getting rows by column {column_name} by attribute {attribute_name} and value {attribute_value} " f"from the table: {self.name}") out = list() end_time = time.time() + wait_time while True: content = self.get_content() for row in content: column = getattr(row, column_name) if column.exists(): act_attr_value = getattr( row, column_name).get_attribute(attribute_name) if act_attr_value == attribute_value: out.append(row) if self.next_page(): return self.get_rows_by_attribute_value( column_name, attribute_name, attribute_value, wait_time) elif out or time.time() > end_time: break return out
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
def exists(self, wait_time: int = 0): Log.debug( f"Window '{self.name}' existence verification. Wait time = {str(wait_time)}" ) if self.get_driver(): try: self.wait_for.visibility_of_element_located(self.load_time) return True except (NoSuchElementException, TimeoutException): Log.debug("Window '%s' was not found" % self.name) return False
def get_row_by_attribute_value(self, column_name: str, attribute_name: str, attribute_value: str, wait_time: int = element_load_time) -> T: Log.debug( "Getting row by column %s attribute %s and value %s from the table: %s" % (column_name, attribute_name, attribute_value, self.name)) end_time = time.time() + wait_time while True: content = self.get_content() for row in content: column = getattr(row, column_name) if column.exists(): act_attr_value = getattr( row, column_name).get_attribute(attribute_name) if act_attr_value == attribute_value: return row if self.next_page(): return self.get_rows_by_attribute_value( column_name, attribute_name, attribute_value, wait_time) elif time.time() > end_time: break return None
def get_driver(self, wait_time: int = 0): if not self.session: Log.debug(f"Creating an instance of a {appium_platform} driver." ) # TODO: Move driver name to a config self.session = AppiumDriver.get_remote_session() return self.session