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 is_file_explorer_visible(self): panel_state = explorer_state = constants.STATE_HIDDEN theia_left_panel = self.find_it(UI.get_theia_left_panel_locator()) if constants.THEIA_ELEMENT_COLLAPSED not in theia_left_panel.get_attribute( constants.TYPE_CLASS): panel_state = constants.STATE_VISIBLE try: file_explorer_id_element = self.find_it( UI.get_files_explorer_locator()) explorer_classes = file_explorer_id_element.get_attribute( constants.TYPE_CLASS) if constants.THEIA_ELEMENT_COLLAPSED not in explorer_classes and \ constants.THEIA_HIDDEN not in explorer_classes: explorer_state = constants.STATE_VISIBLE except NoSuchElementException: pass except Exception: raise GeneralException( self.get_driver(), call_from=self.is_file_explorer_visible.__name__) return constants.STATE_HIDDEN not in [panel_state, explorer_state]
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 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 error_should_present(self, editor=None, error_type=None): if editor is None: editor = self.get_editor_element() if error_type is None: error_type = "error" overlays = self.find_it(UI.get_monako_overlays_locator(), parent=editor) if error_type == "error": error_divs = self.find_them(UI.get_editor_errors_locator(), parent=overlays) elif error_type == "info": error_divs = self.find_them(UI.get_editor_infos_locator(), parent=overlays) else: raise Exception("Unsupported error_type: '{0}'".format(error_type)) if not len(error_divs): raise WebDriverException return error_divs
def find_child_node(self, content, child_name, top, padding): child_nodes = self.find_them(UI.get_tree_nodes_locator(), parent=content) for child_node in child_nodes: child_parent = self.get_parent_node(child_node) child_parent_top = self.get_element_top(child_parent) if lt_pixels(child_parent_top, top): continue child_padding = self.get_element_padding_left(child_node) if lt_pixels(child_padding, padding): continue child_node_content = self.find_it(UI.get_tree_node_content_locator(), parent=child_node) if child_node_content.text != child_name: continue if child_node_content.text == child_name: return child_node child_node_padding_left = self.get_element_padding_left(child_node) # we reached another Connection name, but looking not for a connection if child_node_padding_left == "0px" and padding != "0px": print("Next connection reached!") print("child_node_padding_left: '{0}'".format(child_node_padding_left)) print("padding: '{0}'".format(padding)) break return None
def wait_for_input_with_title_disappear(self, title): 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 visible and input_element.get_attribute(constants.ELEMENT_TITLE) == title: raise WebDriverException
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_lines_elements(self, editor=None): if editor is None: editor = self.get_editor_element() lines = self.find_it(UI.get_monako_lines_content_locator(), parent=editor) lines_list = self.find_them(UI.get_monako_editor_lines_locator(), parent=lines) return lines_list
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 wait_for_tab_exist(self, tab_text): main_content = self.find_it(UI.get_theia_main_content_panel_locator()) tab_container = self.find_it(UI.get_tab_content_locator(), parent=main_content) tabs = self.find_them(UI.get_tabs_locator(), parent=tab_container) for tab in tabs: if tab.text == tab_text: return tab raise WebDriverException
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 get_active_tab_element(self): # <li> id like "^shell-tab-code-editor-opener:.*$" main_content = self.find_it(UI.get_theia_main_content_panel_locator()) tab_container = self.find_it(UI.get_tab_content_locator(), parent=main_content) tabs = self.find_them(UI.get_tabs_locator(), parent=tab_container) for tab in tabs: if constants.THEIA_CURRENT_TAB in tab.get_attribute( constants.TYPE_CLASS): return tab return None
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 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_line_numbers_elements(self, editor=None): if editor is None: editor = self.get_editor_element() line_numbers = self.find_them( UI.get_monako_line_numbers_content_locator(), parent=editor) return line_numbers
def find_file_explorer_content(self): locator = UI.get_files_explorer_content_locator() WebDriverWait(self._driver, self.DEFAULT_TIMEOUT).until( expected_conditions.presence_of_element_located(locator) ) file_explorer = self.find_it(locator) return file_explorer
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 wait_for_input_disappear(self): input_widget = self.find_it(UI.get_monako_input_widget_locator()) hidden = str2bool(input_widget.get_attribute(constants.ARIA_HIDDEN)) if not hidden: print("Press Enter again") self.confirm_input(input_widget) 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 get_notifications_from_control_center(self): status_bar = self.find_it(UI.get_theia_statusbar_locator()) highlight(status_bar) area_right = self.find_it(UI.get_right_status_bar_area(), parent=status_bar) highlight(area_right) status_elements = self.find_them(UI.get_status_elements(), parent=area_right) show_button = None for status_element in status_elements: highlight(status_element) try: int_text = int(status_element.text) show_button = status_element break except ValueError: continue except Exception: raise GeneralException(self.get_driver(), call_from=self.get_notifications_from_control_center.__name__) notifications = list() if show_button is not None: highlight(show_button) notification_center = self.find_it(UI.get_theia_notification_center_locator()) highlight(notification_center) if constants.THEIA_CLOSED in notification_center.get_attribute(constants.TYPE_CLASS): self.click_me(show_button) sleep(1) while True: if constants.THEIA_CLOSED in notification_center.get_attribute(constants.TYPE_CLASS): sleep(1) continue break highlight(notification_center) notifications = self.find_them(UI.get_theia_notifications_locator(), parent=notification_center) return notifications
def show_file_explorer(self): if not self.is_file_explorer_visible(): file_explorer_id_element = self.find_it( UI.get_files_explorer_tab_locator()) self.click_me(file_explorer_id_element) else: print("visible?")
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 collapse_tree_node(self, node): try: parent_node = self.get_parent_node(node) arrow = self.find_it(UI.get_theia_expand_arrow_locator(), parent=parent_node) is_expanded = self.is_element_expanded(arrow) if is_expanded: self.click_me(node) except Exception: dump(self.get_driver(), reason=self.collapse_tree_node.__name__)
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 wait_for_widget_zone_disappear(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) raise WebDriverException finally: return