def scroll_editor_till_line_number(self, number, direction, editor=None): if editor is None: editor = self.get_editor_element() start_time = round(time.time()) while True: self.set_focus(editor) line_numbers_elements = self.get_line_numbers_elements() elapsed_time = round(time.time()) if elapsed_time - start_time > self.DEFAULT_HUGE_TIMEOUT: raise CustomTimeoutException( self.get_driver(), call_from=self.scroll_editor_till_line_number.__name__) try: line_number_element = self.get_line_number_element( number, line_numbers_elements) if line_number_element is not None: highlight(line_number_element, effect_time=1) return line_number_element except NoLineNumberOnScreenException: if direction == "Down": self.page_down(editor) elif direction == "Up": self.page_up(editor) except Exception: raise GeneralException( self.get_driver(), call_from=self.scroll_editor_till_line_number.__name__)
def get_text_element_in_line(self, line_element, text): text_elements = self.find_them(UI.get_spans_locator(), parent=line_element) for text_element in text_elements: highlight(text_element) if text_element.text.strip() == text: return text_element
def show_tooltip(self, tooltip_type, line_number, editor=None): if editor is None: editor = self.get_editor_element() if tooltip_type == "error": divs_locator = UI.get_editor_errors_locator() elif tooltip_type == "info": divs_locator = UI.get_editor_infos_locator() else: raise Exception("Unsupported tooltip type") error_divs = self.get_error_divs(divs_locator, editor) error_div = None for error_div in error_divs: parent = self.get_parent_node(error_div) top = self.get_element_top(parent) line_num = self.get_line_number_from_top(top, editor) if line_num == line_number: break if error_div is None: raise ElementNotFoundException(self.get_driver()) highlight(error_div, effect_time=1) actions = ActionChains(self.get_driver()) actions.move_to_element(error_div).perform() time.sleep(1) hover = self.find_active_hover_element(editor=editor) hover_row = self.find_it(UI.get_hover_row_locator(), parent=hover) highlight(hover_row, effect_time=1) content = self.find_it(UI.get_hover_content_locator(), parent=hover_row) return content.text
def close_zone_widget_if_exists(self, editor=None): if editor is None: editor = self.get_editor_element() try: widget_zone = self.find_it(UI.get_monako_zone_widget_locator(), parent=editor) highlight(widget_zone) actions = self.find_them(UI.get_action_items_locator(), parent=widget_zone) for action in actions: highlight(action) action_label = self.find_it(UI.get_action_label_locator()) if action_label.get_attribute( constants.ELEMENT_TITLE) == constants.Close: self.click_me(action, element_human_name=constants.Close) self.wait_for_widget_zone_disappear(editor) break except WebDriverException: print("No widget zone. That's fine here.") except Exception: raise GeneralException( self.get_driver(), call_from=self.close_zone_widget_if_exists.__name__)
def find_it(self, locator, parent=None): if parent is None: parent = self._driver element = parent.find_element(*locator) highlight(element) return element
def click_on_node(self, node): try: highlight(node) self.click_me(node) except Exception: dump(self.get_driver(), reason=self.click_on_node.__name__)
def confirm_input(self, input_element): print("Press Enter on element") highlight(input_element) self.click_me(input_element) actions = ActionChains(self.get_driver()) actions.send_keys(Keys.ENTER) actions.perform() sleep(2)
def right_click_it(element, effect_time=None, color=None, border=None): highlight(element, effect_time, color, border) driver = element.parent actions = ActionChains(driver) actions.move_to_element(element) actions.context_click(element) actions.perform()
def find_them(self, locator, parent=None, show=True): if parent is None: parent = self._driver elements = parent.find_elements(*locator) if show: for element in elements: highlight(element) return elements
def status_bar_should_have_text(self, text): theia_status_bar = self.find_it(UI.get_theia_statusbar_locator()) elements_with_commands = self.find_them(UI.get_status_elements(), parent=theia_status_bar) for elements_with_command in elements_with_commands: if elements_with_command.text == text: highlight(elements_with_command, effect_time=1) return raise NoSuchElementException
def get_input_element(self): input_frame = self.find_it(UI.get_monako_quick_input_locator()) input_element = self.find_it(UI.get_monako_input_locator(), parent=input_frame) visible = str2bool(input_element.get_attribute(constants.ARIA_HAS_POPUP)) if not visible: raise WebDriverException highlight(input_element) self.click_me(input_element) return input_element
def get_editor_element(self): # <div> id like "^code-editor-opener:.*$" main_content = self.find_it(UI.get_theia_main_content_panel_locator()) eds = self.find_them(UI.get_theia_dock_panel_widgets_locator(), parent=main_content) for ed in eds: classes = ed.get_attribute(constants.TYPE_CLASS) if constants.THEIA_HIDDEN not in classes: highlight(ed, effect_time=1) return ed
def scroll_till_element_is_found(self, direction, content, element_name, upper_node): self.node_should_exist(upper_node) if constants.THEIA_VIEW_CONTAINER_TITLE_NODE in upper_node.get_attribute(constants.TYPE_CLASS) \ or constants.THEIA_SIDE_PANEL_TOOLBAR in upper_node.get_attribute(constants.TYPE_CLASS): node_top = "0px" node_padding = "0px" else: parent_upper_node = self.get_parent_node(upper_node) node_top = self.get_element_top(parent_upper_node) node_padding = self.get_element_padding_left(upper_node) found_node = None start_time = round(time.time()) while True: elapsed_time = round(time.time()) if elapsed_time - start_time > self.DEFAULT_HUGE_TIMEOUT: raise CustomTimeoutException( self.get_driver(), call_from=self.scroll_file_explorer_till_element_is_found.__name__ ) try: found_node = self.find_child_node(content, element_name, node_top, node_padding) except StaleElementReferenceException: print("Got StaleElementReferenceException exception, wait 1 sec") time.sleep(1) continue except Exception: raise GeneralException(self.get_driver(), call_from=self.scroll_till_element_is_found.__name__) if found_node is not None: highlight(found_node) break if direction == "Down": self.page_down_tree(content) elif direction == "Up": self.page_up_tree(content) else: raise Exception("Unsupported scroll direction: '{0}'".format(direction)) if found_node is None: raise ElementNotFoundException(self.get_driver()) return found_node
def click_node_to_expand(self, node): parent_node = self.get_parent_node(node) child_node_content = self.find_it(UI.get_tree_node_content_locator(), parent=node) node_id = child_node_content.get_attribute(constants.TYPE_ID) if constants.THEIA_TREE_EXPANDABLE_NODES in node.get_attribute(constants.TYPE_CLASS): arrow = self.find_it(UI.get_theia_expand_arrow_locator(), parent=parent_node) is_expanded = self.is_element_expanded(arrow) if not is_expanded: highlight(node) self.click_me(node) return node_id
def expect_notification_message_gone(self, msg_text): print("Expecting notification message '{0}' to disappear ...".format(msg_text)) notification_container = self.find_it(UI.get_theia_notification_container_locator()) highlight(notification_container) notifications = self.find_them(UI.get_theia_notifications_locator(), parent=notification_container) for notification in notifications: text_el = self.find_it(UI.get_theia_notification_message_locator(), parent=notification) if text_el.text == msg_text: raise WebDriverException print("Expecting notification message '{0}' to disappear ... Ok".format(msg_text)) return
def find_host(self, content, connection_name, expandable=True, padding_left="0px"): tree_nodes = self.wait_for_nodes(content, expandable) for tree_node in tree_nodes: highlight(tree_node) node_padding_left = self.get_element_padding_left(tree_node) if node_padding_left != padding_left: continue node_content = self.find_it(UI.get_tree_node_content_locator(), parent=tree_node) if node_content.text == connection_name: return tree_node return None
def get_references_num(self, editor=None): if editor is None: editor = self.get_editor_element() WebDriverWait(self.get_driver(), self.DEFAULT_TIMEOUT).until( expected_conditions.presence_of_element_located( UI.get_monako_zone_widget_locator())) widget_zone = self.find_it(UI.get_monako_zone_widget_locator(), parent=editor) highlight(widget_zone) list_rows = self.find_them(UI.get_monako_list_row_locator(), parent=widget_zone) return len(list_rows)
def confirm_delete_member(self, dataset, member): notification_container = self.find_it(UI.get_theia_notification_container_locator()) highlight(notification_container) notifications = self.find_them(UI.get_theia_notifications_locator(), parent=notification_container) for notification in notifications: text_el = self.find_it(UI.get_theia_notification_message_locator(), parent=notification) if text_el.text == self.create_delete_member_expected_text(dataset, member): buttons = self.find_them(UI.get_buttons_locator(), parent=notification) for button in buttons: if button.text == constants.OK: self.click_me(button, element_human_name=constants.OK) return raise WebDriverException
def get_current_line_num_inside_widget_zone(self, content, editor=None): if editor is None: editor = self.get_editor_element() WebDriverWait(self.get_driver(), self.DEFAULT_TIMEOUT).until( expected_conditions.presence_of_element_located( UI.get_monako_zone_widget_locator())) widget_zone = self.find_it(UI.get_monako_zone_widget_locator(), parent=editor) highlight(widget_zone) current_line_num = self.get_current_line_num(content=content, parent=widget_zone) return current_line_num
def find_them(self, locator, parent=None, show=True): if parent is None: parent = self._driver elements = parent.find_elements(*locator) if show: for element in elements: try: highlight(element) except StaleElementReferenceException: pass except Exception: raise GeneralException(self.get_driver(), call_from=self.find_them.__name__) return elements
def navigate_with_references(self, editor=None): if editor is None: editor = self.get_editor_element() WebDriverWait(self.get_driver(), self.DEFAULT_TIMEOUT).until( expected_conditions.presence_of_element_located( UI.get_monako_zone_widget_locator())) widget_zone = self.find_it(UI.get_monako_zone_widget_locator(), parent=editor) highlight(widget_zone) tree_rows = self.find_them(UI.get_monako_tree_row_locator(), parent=widget_zone) for row in tree_rows: highlight(row, effect_time=1) self.click_me(row) current_line_num = self.get_current_line_num(parent=widget_zone)
def invoke_context_menu_item(self, item): menu = self.get_context_menu() menu_item = None menu_elements = self.find_them(UI.get_theia_submenu_items_locator(), parent=menu) for menu_element in menu_elements: highlight(menu_element) label = self.find_it(UI.get_theia_submenu_item_label_locator(), parent=menu_element) if label.text == item: menu_item = menu_element break if menu_item is None: raise ElementNotFoundException(self.get_driver()) actions = ActionChains(self._driver) actions.move_to_element(menu_item) actions.click(menu_item) actions.perform()
def mark_lines_with_numbers(self, line_numbers, editor=None): if editor is None: editor = self.get_editor_element() lines_to_mark = list() line_elements = self.get_lines_elements(editor) line_numbers_elements = self.get_line_numbers_elements() for line_number in line_numbers: line = self.get_line_element_with_number( line_number, editor=editor, line_elements=line_elements, line_numbers_elements=line_numbers_elements) lines_to_mark.append(line) highlight(lines_to_mark, effect_time=1)
def get_line_num_for_reference(self, ref_num, content=None, editor=None): if editor is None: editor = self.get_editor_element() ref_num = int(ref_num) WebDriverWait(self.get_driver(), self.DEFAULT_TIMEOUT).until( expected_conditions.presence_of_element_located( UI.get_monako_zone_widget_locator())) widget_zone = self.find_it(UI.get_monako_zone_widget_locator(), parent=editor) highlight(widget_zone) list_rows = self.find_them(UI.get_monako_list_row_locator(), parent=widget_zone) self.click_me(list_rows[ref_num]) current_line_num = self.get_current_line_num(content=content, parent=widget_zone) return current_line_num
def confirm_delete(self, host_name): notification_container = self.find_it(UI.get_theia_notification_container_locator()) highlight(notification_container) notifications = self.find_them(UI.get_theia_notifications_locator(), parent=notification_container) if len(notifications) == 0: notifications = self.get_notifications_from_control_center() for notification in notifications: highlight(notification) text_el = self.find_it(UI.get_theia_notification_message_locator(), parent=notification) if text_el.text == self.create_delete_host_expected_text(host_name): buttons = self.find_them(UI.get_buttons_locator(), parent=notification) for button in buttons: if button.text == constants.OK: self.click_me(button, element_human_name=constants.OK) return raise WebDriverException
def get_line_number_element(self, number, line_numbers_elements=None, editor=None): print("Find line element with number: '{0}'".format(number)) if line_numbers_elements is None: line_numbers_elements = self.get_line_numbers_elements(editor) for line_numbers_element in line_numbers_elements: print("Checking line. It's number: '{0}'".format( line_numbers_element.text)) if str(line_numbers_element.text) == str(number): highlight(line_numbers_element) parent_element = self.get_parent_node(line_numbers_element) return parent_element raise NoLineNumberOnScreenException( self.get_driver(), call_from=self.get_line_number_element.__name__, msg="No line with number '{0}' found".format(number))
def wait_for_timeout_waiting_notification(self, msg_text): print("Notification message '{0}' should not appear...".format(msg_text)) notification_container = self.find_it(UI.get_theia_notification_container_locator()) highlight(notification_container) notifications = self.find_them(UI.get_theia_notifications_locator(), parent=notification_container) if len(notifications) == 0: notifications = self.get_notifications_from_control_center() if len(notifications) == 0: raise WebDriverException for notification in notifications: highlight(notification) text_el = self.find_it(UI.get_theia_notification_message_locator(), parent=notification) if text_el.text == msg_text: print("Expecting notification message '{0}' ... Ok".format(msg_text)) raise UnexpectedNotificationMessage( self.get_driver(), call_from=self.wait_for_timeout_waiting_notification.__name__ )
def wait_for_data_sets_is_expanded(self, node_id, content): print("Wait for node is expanded...") node_top = self.get_tree_element_top_by_id(node_id) node_padding = self.get_tree_element_padding_by_id(node_id) child_nodes = self.find_them(UI.get_tree_nodes_locator(), parent=content) for child_node in child_nodes: highlight(child_node) child_parent = self.get_parent_node(child_node) child_top = self.get_element_top(child_parent) if lt_pixels(child_top, node_top): continue child_padding = self.get_element_padding_left(child_node) if lt_pixels(node_padding, child_padding): print("Wait for node is expanded...Ok", node_padding, child_padding) return print("Wait for node is expanded...Waiting") node = self.find_it((By.ID, node_id)) highlight(node) arrow = self.find_it(UI.get_theia_expand_arrow_locator(), parent=node) highlight(arrow) is_expanded = self.is_element_expanded(arrow) if is_expanded: self.page_down_tree(content) raise WebDriverException
def expect_notification_message(self, msg_text, like=False): print("Expecting notification message '{0}' ...".format(msg_text)) notification_container = self.find_it(UI.get_theia_notification_container_locator()) highlight(notification_container) notifications = self.find_them(UI.get_theia_notifications_locator(), parent=notification_container) if len(notifications) == 0: notifications = self.get_notifications_from_control_center() for notification in notifications: highlight(notification) text_el = self.find_it(UI.get_theia_notification_message_locator(), parent=notification) if like: if msg_text in text_el.text: print("Expecting notification message '{0}' ... Ok".format(msg_text)) return notification else: if text_el.text == msg_text: print("Expecting notification message '{0}' ... Ok".format(msg_text)) return notification raise WebDriverException
def find_panel_with_title(self, title): title = title.upper() panels = self.find_them(UI.get_theia_side_panel_title_locator()) for panel in panels: highlight(panel) panel_title = panel.text.upper() if string_is_regexp(title): if re.search(title, panel_title): highlight(panel) return panel else: if panel_title == title: highlight(panel) return panel raise ElementNotFoundException(self.get_driver())