def map_to_object(self): """Map object to object.""" selenium_utils.get_when_visible( self._driver, self.locator_cls.BUTTON_MAP_TO) selenium_utils.click_on_staleable_element( self._driver, self.locator_cls.BUTTON_MAP_TO) self.is_mapped = True
def select_by_titles(self, list_titles): """Select checkboxes according titles.""" selenium_utils.wait_for_js_to_load(self._driver) selenium_utils.get_when_visible(self._driver, self.locator_titles) checkboxes = self._driver.find_elements(*self.locator_checkboxes) title_els = self._driver.find_elements(*self.locator_titles) self._select_necessary(checkboxes, title_els, list_titles)
def _select_first_result(self): """Wait when dropdown elements appear and select first one.""" for _ in xrange(batch.TRY_COUNT): try: selenium_utils.get_when_visible(self._driver, self._locator_dropdown) dropdown_elements = self._driver.find_elements(*self._locator_dropdown) self.text = dropdown_elements[0].text dropdown_elements[0].click() break except exceptions.StaleElementReferenceException: pass
def hover_over_visible_member(self, member_title): """Hovers over visible member with (unique) title "member_title". Args: member_title (basestring): (unique) title of member """ try: el = self._get_visible_member_by_title(member_title) selenium_utils.hover_over_element(self._driver, el) selenium_utils.get_when_visible( self._driver, locator.LhnMenu.EXTENDED_INFO) return extended_info.ExtendedInfo(self._driver) except selenium_exception.StaleElementReferenceException: return self.hover_over_visible_member(member_title)
def set_visible_fields(self, fields): """Set visible fields to display objects on the tree view.""" locator_modal_fields = (By.CSS_SELECTOR, self._locators.MODAL.format(self.widget_name)) locator_fields_titles = ( By.CSS_SELECTOR, locator.ModalSetVisibleFields.FIELDS_TITLES.format(self.widget_name)) locator_fields_checkboxes = ( By.CSS_SELECTOR, (locator.ModalSetVisibleFields.FIELDS_CHECKBOXES. format(self.widget_name))) selenium_utils.get_when_visible(self._driver, locator_modal_fields) self.fields_elements = base.ListCheckboxes( self._driver, locator_fields_titles, locator_fields_checkboxes) self.fields_elements.select_by_titles(fields)
def _log_tab_validate(_driver, log_panel_element): """Validation of all log items on Log pane. Return: list of dicts. """ tab_elements = element.AsmtLogTab tab_locators = locator.AssessmentLogTab selenium_utils.wait_for_js_to_load(_driver) def check_log_item(log_element, label_value): """Check consistency of log item by passed log element. Person's label will be checked by comparing element 'class' and passed 'label_value' Return: dict of bool. """ all_cells_texts = [ elem.text for elem in log_element.find_elements(*tab_locators.CELLS_CSS) ] expected_headers = [ tab_elements.FIELD, tab_elements.ORIGINAL_VALUE, tab_elements.NEW_VALUE ] headers_is_valid = ([ all_cells_texts.pop(0) for _ in xrange(len(expected_headers)) ] == expected_headers) field_is_valid = all( cell != "" and cell != tab_elements.EMPTY_STATEMENT for cell in all_cells_texts[0::3]) orignal_value_is_valid = all(cell == tab_elements.EMPTY_STATEMENT for cell in all_cells_texts[1::3]) new_value_is_valid = all( cell != "" and cell != tab_elements.EMPTY_STATEMENT for cell in all_cells_texts[2::3]) person_label_is_valid = selenium_utils.is_value_in_attr( log_element.find_element(*tab_locators.PERSON_LABEL), "class", value=label_value) person_element = log_element.find_element( *tab_locators.COMMENT_PERSON_CSS) return { "headers_is_valid": headers_is_valid, "field_is_valid": field_is_valid, "orignal_value_is_valid": orignal_value_is_valid, "new_value_is_valid": new_value_is_valid, "person_is_valid": person_element.text == roles.DEFAULT_USER, "person_label_is_valid": person_label_is_valid } selenium_utils.get_when_invisible(_driver, tab_locators.LOG_TAB_SPINNER_CSS) log_list = base.ElementsList( _driver, selenium_utils.get_when_visible(log_panel_element, tab_locators.LOG_LIST_CSS)) return [ check_log_item(el.element, 'assessor' if i == 0 else 'none') for i, el in enumerate(log_list.get_items()) ]
def set_visible_fields(self, fields): """Set visible fields to display objects on the tree view.""" locator_modal_fields = (By.CSS_SELECTOR, self._locators.MODAL.format(self.widget_name)) locator_fields_titles = ( By.CSS_SELECTOR, locator.ModalSetVisibleFields.FIELDS_TITLES.format( self.widget_name)) locator_fields_checkboxes = (By.CSS_SELECTOR, ( locator.ModalSetVisibleFields.FIELDS_CHECKBOXES.format( self.widget_name))) selenium_utils.get_when_visible(self._driver, locator_modal_fields) self.fields_elements = base.ListCheckboxes(self._driver, locator_fields_titles, locator_fields_checkboxes) self.fields_elements.select_by_titles(fields)
def __init__(self, driver, item_text): super(CustomAttributesItemContent, self).__init__(driver) self.item_el = selenium_utils.get_when_visible( self._driver, self._locators.TREE_ITEM_EL_OPENED_CSS) self.add_btn = base.Button(self.item_el, self._locators.ADD_BTN_CSS) self.custom_attributes_list = [] self._item_name = item_text
def is_result_ready(): """Check if the results on mapper is ready.""" is_results_ready = False if not selenium_utils.is_element_enabled( selenium_utils.get_when_visible( self._driver, constants.locator.CommonModalUnifiedMapper.BUTTON_SEARCH) ): return is_results_ready if ( selenium_utils.is_element_exist( self._driver, self._locators.MAPPER_TREE_SPINNER_NO_RESULT) or selenium_utils.is_element_exist( self._driver, self._locators.MAPPER_TREE_SPINNER_ITEMS) ): return is_results_ready if ( selenium_utils.is_element_exist( self._driver, self.locator_no_results_message) or selenium_utils.get_when_all_visible( self._driver, (By.CSS_SELECTOR, self._locators.ITEMS)) ): is_results_ready = True return is_results_ready return is_results_ready
def is_result_ready(): """Check if the results on mapper is ready.""" is_results_ready = False if not selenium_utils.is_element_enabled( selenium_utils.get_when_visible( self._driver, constants.locator.CommonModalUnifiedMapper.BUTTON_SEARCH) ): return is_results_ready if ( selenium_utils.is_element_exist( self._driver, self._locators.MAPPER_TREE_SPINNER_NO_RESULT) or selenium_utils.is_element_exist( self._driver, self._locators.MAPPER_TREE_SPINNER_ITEMS) ): return is_results_ready if ( selenium_utils.is_element_exist( self._driver, self.locator_no_results_message) or selenium_utils.get_when_all_visible( self._driver, (By.CSS_SELECTOR, self._locators.ITEMS)) ): is_results_ready = True return is_results_ready return is_results_ready
def _set_members_listed(self): """Waits for the listed members to be loaded and adds them to a local container""" self._set_member_count() if self.member_count: # wait until the elements are loaded selenium_utils.get_when_invisible(self._driver, locator.ObjectWidget.LOADING) selenium_utils.get_when_visible( self._driver, locator.ObjectWidget.MEMBERS_TITLE_LIST) self.members_listed = self._driver.find_elements( *locator.ObjectWidget.MEMBERS_TITLE_LIST) else: self.members_listed = []
def __init__(self, driver, item_text): super(CustomAttributesItemContent, self).__init__(driver) self.item_el = selenium_utils.get_when_visible( self._driver, self._locators.TREE_ITEM_EL_OPENED_CSS) self.add_btn = base.Button(self.item_el, self._locators.ADD_BTN_CSS) self.custom_attributes_list = [] self._item_name = item_text
def __init__(self, driver): super(InfoWidget, self).__init__(driver) selenium_utils.wait_for_js_to_load(self._driver) self.child_cls_name = self.__class__.__name__.lower() self.list_all_headers_txt = [] self.list_all_values_txt = [] self.info_widget_locator = (self._locators.INFO_PAGE_ELEM if self.is_info_page else self._locators.INFO_PANEL_ELEM) self.info_widget_elem = selenium_utils.get_when_visible( self._driver, self.info_widget_locator) # common for all objects self.title_lbl_txt = self.get_title_lbl_txt() self.title = base.Element(self.info_widget_elem, self._locators.TITLE_ENTERED) self.state_lbl_txt = self._elements.STATE.upper() self.state_txt = self.get_state_txt() self._extend_list_all_scopes([self.title_lbl_txt, self.state_lbl_txt], [self.title.text, self.state_txt]) self.info_3bbs_btn = selenium_utils.get_when_visible( self.info_widget_elem, self._locators.BUTTON_3BBS) # for Info Page if self.is_info_page: self.info_page_footer = base.Label(self.info_widget_elem, self._locators.TXT_FOOTER_CSS) self.modified_by = selenium_utils.get_when_visible( self.info_widget_elem, self._locators.TXT_MODIFIED_BY_CSS) _created_at_txt, _updated_at_txt = ( self.info_page_footer.text.split(string_utils.WHITESPACE * 6)) self.created_at_txt = (re.sub("Created at", string_utils.BLANK, _created_at_txt)) self.updated_at_txt = (_updated_at_txt.splitlines()[1].replace( "on ", string_utils.BLANK)) self._extend_list_all_scopes([ self._elements.CREATED_AT.upper(), self._elements.MODIFIED_BY.upper(), self._elements.UPDATED_AT.upper() ], [ self.created_at_txt, self.modified_by.text, self.updated_at_txt ]) # for Info Panel else: self.panel = (SnapshotableInfoPanel( self._driver, self.info_widget_elem) if self.child_cls_name in objects.ALL_SNAPSHOTABLE_OBJS else InfoPanel( self._driver, self.info_widget_elem))
def select_visible_fields(self): """Select visible fields checkboxes on Select Visible Fields modal according to titles of fields to set.""" # pylint: disable=attribute-defined-outside-init _locator_modal_fields = (By.CSS_SELECTOR, self._locators.MODAL) _locator_fields_titles = ( By.CSS_SELECTOR, self._locators.FIELDS_TITLES) _locator_fields_checkboxes = ( By.CSS_SELECTOR, self._locators.FIELDS_CHECKBOXES) selenium_utils.get_when_visible(self._driver, _locator_modal_fields) self.visible_fields_elements = ListCheckboxes( self._driver, titles_locator=_locator_fields_titles, checkboxes_locator=_locator_fields_checkboxes) self.visible_fields_elements.select_by_titles(self.fields_to_set)
def __init__(self, driver): super(_Modal, self).__init__(driver) self.modal_window = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.attr_title_ui = base.TextInputField( self.modal_window, self._locators.ATTR_TITLE_UI_CSS) self.submit_btn = base.Button( self.modal_window, self._locators.SAVE_AND_CLOSE_BTN_CSS)
def _get_dropdown_element(self, el_or_loc): """Return DropdownMenu element if element not defined find it by locator""" element = (el_or_loc if isinstance( el_or_loc, webdriver.remote.webelement.WebElement) else selenium_utils.get_when_visible(self._driver, el_or_loc)) return (element if element.tag_name == self._locators.DROPDOWN_MAIN_CSS[1] else element.find_element(*self._locators.DROPDOWN_MAIN_CSS))
def __init__(self, driver): super(_Modal, self).__init__(driver) self.modal_window = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.attr_title_ui = base.TextInputField( self.modal_window, self._locators.ATTR_TITLE_UI_CSS) self.submit_btn = base.Button(self.modal_window, self._locators.SAVE_AND_CLOSE_BTN_CSS)
def select_visible_fields(self): """Select visible fields checkboxes on Select Visible Fields modal according to titles of fields to set.""" # pylint: disable=attribute-defined-outside-init _locator_modal_fields = (By.CSS_SELECTOR, self._locators.MODAL) _locator_fields_titles = ( By.CSS_SELECTOR, self._locators.FIELDS_TITLES) _locator_fields_checkboxes = ( By.CSS_SELECTOR, self._locators.FIELDS_CHECKBOXES) selenium_utils.get_when_visible(self._driver, _locator_modal_fields) self.visible_fields_elements = ListCheckboxes( self._driver, titles_locator=_locator_fields_titles, checkboxes_locator=_locator_fields_checkboxes) self.visible_fields_elements.select_by_titles(self.fields_to_set)
def _set_member_count(self): "Select member count." widget_title = selenium_utils.get_when_visible( self._driver, self.locator_or_element).text if "(" not in widget_title: self.member_count = int(widget_title) else: self.member_count = int( re.match(regex.WIDGET_TITLE_AND_COUNT, widget_title).group(2))
def _get_dropdown_element(self, el_or_loc): """Return DropdownMenu element if element not defined find it by locator""" element = (el_or_loc if isinstance( el_or_loc, webdriver.remote.webelement.WebElement) else selenium_utils.get_when_visible(self._driver, el_or_loc)) return (element if element.tag_name == self._locators.DROPDOWN_MAIN_CSS[1] else element.find_element(*self._locators.DROPDOWN_MAIN_CSS))
def _set_member_count(self): widget_title = selenium_utils.get_when_visible(self._driver, self._locator).text if "(" not in widget_title: self.member_count = int(widget_title) else: self.member_count = int( re.match(regex.WIDGET_TITLE_AND_COUNT, widget_title).group(2))
def __init__(self, driver): super(BaseModal, self).__init__(driver) self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.button_save_and_close = base.Button(self.modal_elem, self._locator_button_save) self.ui_title = base.TextInputField(self.modal_elem, self._locator_ui_title) self.ui_code = base.TextInputField(self.modal_elem, self._locator_ui_code)
def find_iframe_and_enter_data(self, text): """ Args: text (basestring): string want to enter """ iframe = selenium_utils.get_when_visible(self._driver, self._locator) self._driver.switch_to.frame(iframe) element = self._driver.find_element_by_tag_name("body") element.clear() element.send_keys(text) self._driver.switch_to.default_content() self.text = text
def find_iframe_and_enter_data(self, text): """ Args: text (basestring): string want to enter """ iframe = selenium_utils.get_when_visible(self._driver, self._locator) self._driver.switch_to.frame(iframe) element = self._driver.find_element_by_tag_name("body") element.clear() element.send_keys(text) self._driver.switch_to.default_content() self.text = text
def add_filter_attr(self, attr_name, value, operator=alias.AND_OP, compare=alias.EQUAL_OP): """Add filter attribute according to passed parameters. """ if not self._add_attr_btn: self._add_attr_btn = selenium_utils.get_when_visible( self._driver, self._locators.FILTER_ADD_ATTRIBUTE) self._add_attr_btn.click() last_filter_param = self._get_latest_filter_elements() last_filter_param['name'].select(attr_name) last_filter_param['value'].enter_text(value) last_filter_param['compare'].select(compare) last_filter_param['operator'].select(operator)
def _get_list_element(self, element_or_locactor): """Find element by locator or do nothing if passed var is 'WebElement'. Then check tag of element and if it is not 'ul' raise Error """ element = (element_or_locactor if isinstance( element_or_locactor, webdriver.remote.webelement.WebElement) else selenium_utils.get_when_visible(self._driver, element_or_locactor)) if element.tag_name != 'ul': raise ValueError("WebElement is {}. Pass 'ul' element".format( element.tag_name)) return element
def _get_visible_element(self): """Get element: if self object 'locator_or_element' is already Web element then try wait until it will be visible else try to find visible Web element using selenium utils method 'get_when_visible'. Return: selenium.webdriver.remote.webelement.WebElement """ if isinstance(self.locator_or_element, webelement.WebElement): selenium_utils.wait_until_condition( self._driver, lambda x: self.locator_or_element.is_displayed()) return self.locator_or_element return selenium_utils.get_when_visible( self._driver, self.locator_or_element)
def _set_member_count(self): """Parses widget name and number of items from widget tab title.""" widget_label = selenium_utils.get_when_visible( self._driver, self._locator_widget).text # The widget label has 2 forms: "widget_name_plural (number_of_items)" # and "number_of_items" and they change depending on how many widgets # are open. In order to handle both forms, we first try to parse the # first form and only then the second one. parsed_label = re.match(regex.WIDGET_TITLE_AND_COUNT, widget_label) item_count = ( widget_label if parsed_label is None else parsed_label.group(2)) self.member_count = int(item_count)
def _get_visible_element(self): """Get element: if self object 'locator_or_element' is already Web element then try wait until it will be visible else try to find visible Web element using selenium utils method 'get_when_visible'. Return: selenium.webdriver.remote.webelement.WebElement """ if isinstance(self.locator_or_element, webelement.WebElement): selenium_utils.wait_until_condition( self._driver, lambda x: self.locator_or_element.is_displayed()) return self.locator_or_element return selenium_utils.get_when_visible( self._driver, self.locator_or_element)
def _get_list_element(self, element_or_locactor): """Find element by locator or do nothing if passed var is 'WebElement'. Then check tag of element and if it is not 'ul' raise Error """ element = (element_or_locactor if isinstance( element_or_locactor, webdriver.remote.webelement.WebElement) else selenium_utils.get_when_visible(self._driver, element_or_locactor)) if element.tag_name != 'ul': raise ValueError("WebElement is {}. Pass 'ul' element".format( element.tag_name)) return element
def _set_member_count(self): """Parses widget name and number of items from widget tab title.""" widget_label = selenium_utils.get_when_visible( self._driver, self._locator_widget).text # The widget label has 2 forms: "widget_name_plural (number_of_items)" # and "number_of_items" and they change depending on how many widgets # are open. In order to handle both forms, we first try to parse the # first form and only then the second one. parsed_label = re.match(regex.WIDGET_TITLE_AND_COUNT, widget_label) item_count = (widget_label if parsed_label is None else parsed_label.group(2)) self.member_count = int(item_count)
def __init__(self, driver): super(CreateNewPersonModal, self).__init__(driver) self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.name_tf = base.TextInputField( self.modal_elem, self._locators.NAME) self.email_tf = base.TextInputField( self.modal_elem, self._locators.EMAIL) self.modal_type_lbl = base.Label( self.modal_elem, locator.ModalCommonConfirmAction.MODAL_TITLE) self.button_save_and_close = base.Button( self.modal_elem, self._locators.BUTTON_SAVE_AND_CLOSE) self.is_create_modal = "New Person" in self.modal_type_lbl.text
def add_filter_attr(self, attr_name, value, operator=None, compare_op=alias.EQUAL_OP): """Add filter attribute according to passed parameters. """ if not self._add_attr_btn: self._add_attr_btn = selenium_utils.get_when_visible( self._driver, self._locators.FILTER_ADD_ATTRIBUTE_BTN) self._add_attr_btn.click() last_filter_param = self._get_latest_filter_elements() last_filter_param['name'].select(attr_name) last_filter_param['value'].enter_text(value) last_filter_param["compare_op"].select(compare_op) if last_filter_param["operator"] and operator: last_filter_param["operator"].select(operator)
def add_filter_attr(self, attr_name, value, operator=None, compare_op=alias.EQUAL_OP): """Add filter attribute according to passed parameters. """ if not self._add_attr_btn: self._add_attr_btn = selenium_utils.get_when_visible( self.modal_elem, self._locators.FILTER_ADD_ATTRIBUTE_BTN) self._add_attr_btn.click() last_filter_param = self._get_latest_filter_elements() last_filter_param['name'].select(attr_name) last_filter_param['value'].enter_text(value) last_filter_param["compare_op"].select(compare_op) if last_filter_param["operator"] and operator: last_filter_param["operator"].select(operator)
def __init__(self, driver): super(BaseModal, self).__init__(driver) self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.ui_title = base.TextInputField(self.modal_elem, self._locator_ui_title) self.modal_type_lbl = base.Label( self.modal_elem, locator.ModalCommonConfirmAction.MODAL_TITLE) self.button_save_and_close = base.Button(self.modal_elem, self._locator_button_save) self.is_create_modal = "New " in self.modal_type_lbl.text self.code = (base.TextInputField(self.modal_elem, self._locator_code) if self.is_create_modal else base.Label( self.modal_elem, self._locator_code))
def __init__(self, driver): super(BaseModal, self).__init__(driver) self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.ui_title = base.TextInputField( self.modal_elem, self._locator_ui_title) self.modal_type_lbl = base.Label( self.modal_elem, locator.ModalCommonConfirmAction.MODAL_TITLE) self.button_save_and_close = base.Button( self.modal_elem, self._locator_button_save) self.is_create_modal = "New " in self.modal_type_lbl.text self.code = ( base.TextInputField(self.modal_elem, self._locator_code) if self.is_create_modal else base.Label(self.modal_elem, self._locator_code))
def __init__(self, driver, obj_name): super(CommonUnifiedMapperModal, self).__init__(driver) # labels self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.filter_toggle = base.Toggle( self.modal_elem, self._locators.FILTER_TOGGLE_CSS) self.filter_toggle.is_activated = True self.title_modal = base.Label(self.modal_elem, self._locators.MODAL_TITLE) if obj_name != objects.ASSESSMENT_TEMPLATES: self.obj_type = base.Label(self.modal_elem, self._locators.OBJ_TYPE) # user input elements self.tree_view = base.UnifiedMapperTreeView( self._driver, obj_name=obj_name) self._add_attr_btn = None self.search_result_toggle = base.Toggle( self.modal_elem, self._locators.RESULT_TOGGLE_CSS) self.close_btn = base.Button(self.modal_elem, self._locators.CLOSE_BTN_CSS)
def __init__(self, driver, obj_name): super(CommonUnifiedMapperModal, self).__init__(driver) # labels self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.filter_toggle = base.Toggle( self.modal_elem, self._locators.FILTER_TOGGLE_CSS) self.filter_toggle.is_activated = True self.title_modal = base.Label(self.modal_elem, self._locators.MODAL_TITLE) if obj_name != objects.ASSESSMENT_TEMPLATES: self.obj_type = base.Label(self.modal_elem, self._locators.OBJ_TYPE) # user input elements self.tree_view = base.UnifiedMapperTreeView( self._driver, obj_name=obj_name) self._add_attr_btn = None self.search_result_toggle = base.Toggle( self.modal_elem, self._locators.RESULT_TOGGLE_CSS) self.close_btn = base.Button(self.modal_elem, self._locators.CLOSE_BTN_CSS)
def __init__(self, driver, obj_name): super(CommonUnifiedMapperModal, self).__init__(driver) # labels self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.filter_toggle = base.Toggle( self.modal_elem, self._locators.FILTER_TOGGLE_CSS) self.filter_toggle.is_activated = True self.title_modal = base.Label(self.modal_elem, self._locators.MODAL_TITLE) if obj_name != objects.ASSESSMENT_TEMPLATES: self.obj_type = base.Label(self.modal_elem, self._locators.OBJ_TYPE) # user input elements self.tree_view = base.UnifiedMapperTreeView( self._driver, obj_name=obj_name) self._add_attr_btn = None self.search_result_toggle = base.Toggle( self.modal_elem, self._locators.RESULT_TOGGLE_CSS) self.open_in_new_frontend_btn = self._browser.link( class_name=["btn", "btn-small", "btn-white"], text="Open in new frontend")
def __init__(self, driver, obj_name): super(CommonUnifiedMapperModal, self).__init__(driver) # labels self.modal_elem = selenium_utils.get_when_visible( self._driver, self._locators.MODAL_CSS) self.filter_toggle = base.Toggle(self.modal_elem, self._locators.FILTER_TOGGLE_CSS) self.filter_toggle.is_activated = True self.title_modal = base.Label(self.modal_elem, self._locators.MODAL_TITLE) if obj_name != objects.ASSESSMENT_TEMPLATES: self.obj_type = base.Label(self.modal_elem, self._locators.OBJ_TYPE) # user input elements self.tree_view = base.UnifiedMapperTreeView(self._driver, obj_name=obj_name) self._add_attr_btn = None self.search_result_toggle = base.Toggle( self.modal_elem, self._locators.RESULT_TOGGLE_CSS) self.open_in_new_frontend_btn = self._browser.link( class_name=["btn", "btn-small", "btn-white"], text="Open in new frontend")
def __init__(self, driver, locator_element, locator_count): super(Toggle, self).__init__(driver, locator_element) count_element = selenium_utils.get_when_visible(driver, locator_count) self.members_count = int(count_element.text)
def select(self, value_name): """Selects autocomplete dropdown element based on element value.""" self.element.click() selenium_utils.get_when_visible( self._driver, (By.CSS_SELECTOR, "div[value={}]".format(value_name))).click()
def click_when_visible(self): """Wait for element to be visible and only then performs click.""" selenium_utils.get_when_visible(self._driver, self._locator).click()
def __init__(self, driver): super(InfoWidget, self).__init__(driver) self.child_cls_name = self.__class__.__name__ self.is_asmts_info_widget = ( self.child_cls_name.lower() == objects.ASSESSMENTS) self.list_all_headers_txt = [] self.list_all_values_txt = [] self.info_widget_locator = ( self._locators.INFO_PAGE_ELEM if self.is_info_page else self._locators.INFO_PANEL_ELEM) self.info_widget_elem = selenium_utils.get_when_visible( self._driver, self.info_widget_locator) # common for all objects self.title = base.Element( self.info_widget_elem, self._locators.TITLE_ENTERED) self.state_lbl_txt = self._elements.STATE.upper() self.state_txt = self.get_state_txt() self._extend_list_all_scopes( ["TITLE", self.state_lbl_txt], [self.title.text, self.state_txt]) self.info_3bbs_btn = self._browser.element( xpath=self._locators.BUTTON_3BBS_XPATH) self.inline_edit_controls = self._browser.elements( class_name="set-editable-group") # for Info Page if self.is_info_page: self.info_page_footer = base.Label( self.info_widget_elem, self._locators.TXT_FOOTER_CSS) self.modified_by = selenium_utils.get_when_visible( self.info_widget_elem, self._locators.TXT_MODIFIED_BY_CSS) _created_at_txt, _updated_at_txt = ( self.info_page_footer.text.split( string_utils.Symbols.WHITESPACE * 6)) self.created_at_txt = ( re.sub(element.Common.CREATED_AT, string_utils.Symbols.BLANK, _created_at_txt)) self.updated_at_txt = ( _updated_at_txt.splitlines()[2].replace( "on ", string_utils.Symbols.BLANK)) self._extend_list_all_scopes( [self._elements.CREATED_AT.upper(), self._elements.MODIFIED_BY.upper(), self._elements.UPDATED_AT.upper()], [self.created_at_txt, self.modified_by.text, self.updated_at_txt]) # for Info Panel else: self.panel = ( SnapshotedInfoPanel(self._driver, self.info_widget_elem) if (self.child_cls_name.lower() in objects.ALL_SNAPSHOTABLE_OBJS and self.is_snapshoted_panel) else InfoPanel(self._driver, self.info_widget_elem)) # for tab controller if not self.is_snapshoted_panel: self.tab_container_elem = self.info_widget_elem.find_element( *self._locators.TAB_CONTAINER_CSS) self.tab_container = ( tab_containers.AssessmentsTabContainer( self._driver, self.tab_container_elem) if self.is_asmts_info_widget else tab_containers.TabContainer( self._driver, self.tab_container_elem)) self.tab_container.tab_controller.active_tab = ( self.tab_container._elements.OBJ_TAB) # core element to find sub elements self.core_elem = (self.info_widget_elem if self.is_snapshoted_panel else self.tab_container.active_tab_elem) # for overridable methods self._extend_list_all_scopes_by_review_state() if not self.is_asmts_info_widget: self._extend_list_all_scopes_by_code() self._extend_list_all_scopes_by_cas() self.comment_area = self._comment_area()
def get_element(self): """ Return: selenium.webdriver.remote.webelement.WebElement """ return selenium_utils.get_when_visible(self._driver, self._locator)
def __init__(self, driver): super(SetValueForAsmtDropdown, self).__init__(driver) self.modal_elem = selenium_utils.get_when_visible( self._driver, locator.ModalSetValueForAsmtCA.MODAL_LOCATOR) self.modal_header_lbl = base.Label( self._driver, locator.ModalSetValueForAsmtCA.MODAL_HEADER)
def _wait_until_visible(self): for item_locator in self._locators: selenium_utils.get_when_visible(self._driver, item_locator)
def select_dashboard_tab(self): """Select 'Dashboard' tab on Object Widget Bar.""" Button(self._driver, locator.WidgetBar.DASHBOARD_TAB).click() return selenium_utils.get_when_visible( self._driver, locator.DashboardWidget.TAB_CONTAINER_CSS)
def info_widget_elem(self): """Returns info widget elem (obsolete). Use `self._root` or `self._active_tab_root` instead.""" return selenium_utils.get_when_visible( self._driver, self._locators.INFO_PAGE_ELEM)
def click_when_visible(self): """Wait for element to be visible and only then performs click.""" selenium_utils.get_when_visible(self._driver, self._locator).click()
def _wait_until_visible(self): for item_locator in self._locators: selenium_utils.get_when_visible(self._driver, item_locator)
def info_widget_elem(self): """Returns info widget elem (obsolete). Use `self._root` or `self._active_tab_root` instead.""" return selenium_utils.get_when_visible( self._driver, self._locators.INFO_PAGE_ELEM)
def select_dashboard_tab(self): """Select 'Dashboard' tab on Object Widget Bar.""" Button(self._driver, locator.WidgetBar.DASHBOARD_TAB).click() return selenium_utils.get_when_visible( self._driver, locator.DashboardWidget.TAB_CONTAINER_CSS)
def get_element(self): """ Return: selenium.webdriver.remote.webelement.WebElement """ return selenium_utils.get_when_visible(self._driver, self._locator)
def wait_for_counter_loaded(self): """Wait for elements' counter on Filter panel to be visible.""" return selenium_utils.get_when_visible( self._driver, locator.BaseWidgetGeneric.FILTER_PANE_COUNTER)
def wait_for_counter_loaded(self): """Wait for elements' counter on Filter panel to be visible.""" return selenium_utils.get_when_visible( self._driver, locator.BaseWidgetGeneric.FILTER_PANE_COUNTER)
def __init__(self, driver, locator_element, locator_count): super(Toggle, self).__init__(driver, locator_element) count_element = selenium_utils.get_when_visible(driver, locator_count) self.members_count = int(count_element.text)
def __init__(self, driver): super(InfoWidget, self).__init__(driver) self.child_cls_name = self.__class__.__name__ self.is_asmts_info_widget = ( self.child_cls_name.lower() == objects.ASSESSMENTS) self.list_all_headers_txt = [] self.list_all_values_txt = [] self.info_widget_locator = (self._locators.INFO_PAGE_ELEM if self.is_info_page else self._locators.INFO_PANEL_ELEM) self.info_widget_elem = selenium_utils.get_when_visible( self._driver, self.info_widget_locator) # common for all objects self.title = base.Element(self.info_widget_elem, self._locators.TITLE_ENTERED) self.state_lbl_txt = self._elements.STATE.upper() self.state_txt = self.get_state_txt() self._extend_list_all_scopes(["TITLE", self.state_lbl_txt], [self.title.text, self.state_txt]) self.info_3bbs_btn = selenium_utils.get_when_visible( self.info_widget_elem, self._locators.BUTTON_3BBS) # for Info Page if self.is_info_page: self.info_page_footer = base.Label(self.info_widget_elem, self._locators.TXT_FOOTER_CSS) self.modified_by = selenium_utils.get_when_visible( self.info_widget_elem, self._locators.TXT_MODIFIED_BY_CSS) _created_at_txt, _updated_at_txt = ( self.info_page_footer.text.split( string_utils.Symbols.WHITESPACE * 6)) self.created_at_txt = (re.sub(element.Common.CREATED_AT, string_utils.Symbols.BLANK, _created_at_txt)) self.updated_at_txt = (_updated_at_txt.splitlines()[2].replace( "on ", string_utils.Symbols.BLANK)) self._extend_list_all_scopes([ self._elements.CREATED_AT.upper(), self._elements.MODIFIED_BY.upper(), self._elements.UPDATED_AT.upper() ], [ self.created_at_txt, self.modified_by.text, self.updated_at_txt ]) # for Info Panel else: self.panel = ( SnapshotedInfoPanel(self._driver, self.info_widget_elem) if (self.child_cls_name.lower() in objects.ALL_SNAPSHOTABLE_OBJS and self.is_snapshoted_panel) else InfoPanel( self._driver, self.info_widget_elem)) # for tab controller if not self.is_snapshoted_panel: self.tab_container_elem = self.info_widget_elem.find_element( *self._locators.TAB_CONTAINER_CSS) self.tab_container = (tab_containers.AssessmentsTabContainer( self._driver, self.tab_container_elem) if self.is_asmts_info_widget else tab_containers.TabContainer( self._driver, self.tab_container_elem)) self.tab_container.tab_controller.active_tab = ( self.tab_container._elements.OBJ_TAB) # core element to find sub elements self.core_elem = (self.info_widget_elem if self.is_snapshoted_panel else self.tab_container.active_tab_elem) # for overridable methods self._extend_list_all_scopes_by_review_state() if not self.is_asmts_info_widget: self._extend_list_all_scopes_by_code() self._extend_list_all_scopes_by_cas()
def count(self): """Get current count that displayed in tab.""" widget_title = selenium_utils.get_when_visible( self._driver, self.locator_or_element).text return int(widget_title) if "(" not in widget_title else int(re.match( regex.WIDGET_TITLE_AND_COUNT, widget_title).group(2))