def _get_latest_filter_elements(self): """Return elements of last filter parameter""" return { "name": base.DropdownStatic( self._driver, selenium_utils.get_when_all_visible( self._driver, self._locators.FILTER_ATTRIBUTE_NAME)[-1]), "operator": base.DropdownStatic( self._driver, selenium_utils.get_when_all_visible( self._driver, self._locators.FILTER_OPERATOR)[-1]), "compare": base.DropdownStatic( self._driver, selenium_utils.get_when_all_visible( self._driver, self._locators.FILTER_ATTRIBUTE_COMPARE)[-1]), "value": base.TextInputField( self._driver, selenium_utils.get_when_all_visible( self._driver, self._locators.FILTER_ATTRIBUTE_VALUE)[-1]) }
def _wait_to_be_init(self): """Wait when all rows will be visible and ppl emails will be loaded into last row. """ selenium_utils.wait_for_js_to_load(self._driver) selenium_utils.get_when_all_visible( self._driver, self._locators.TREE_VIEW_ITEMS_W_PPL)
def select_by_titles(self, list_titles): """Select checkboxes according titles.""" selenium_utils.get_when_all_visible(self._driver, self.locator_titles) objs_titles = self._driver.find_elements(*self.locator_titles) objs_checkboxes = self._driver.find_elements(*self.locator_checkboxes) objs = zip(objs_titles, objs_checkboxes) self._unselect_unnecessary(objs, list_titles) self._select_necessary(objs, list_titles)
def get_mapping_statuses(self): """Get list of mapping statuses by given titles""" selenium_utils.get_when_all_visible(self._driver, self.locator_titles) objs_titles = self._driver.find_elements(*self.locator_titles) objs_checkboxes = self._driver.find_elements(*self.locator_checkboxes) objs = [ MappingStatusAttrs(obj[0], obj[1][0], obj[1][1]) for obj in zip( [obj.text for obj in objs_titles], [[string_utils.get_bool_from_string(obj.get_attribute("checked")), string_utils.get_bool_from_string(obj.get_attribute("disabled"))] for obj in objs_checkboxes])] return objs
def get_mapping_statuses(self): """Get list of mapping statuses by given titles""" selenium_utils.get_when_all_visible(self._driver, self.locator_titles) objs_titles = self._driver.find_elements(*self.locator_titles) objs_checkboxes = self._driver.find_elements(*self.locator_checkboxes) objs = [ MappingStatusAttrs(obj[0], obj[1][0], obj[1][1]) for obj in zip( [obj.text for obj in objs_titles], [[obj.is_selected(), not obj.is_enabled()] for obj in objs_checkboxes])] return objs
def select_assignee_user(self, user_email): """Select assignee user from dropdown on submit for review popup.""" elem = self._driver.find_element(*WidgetInfoControl.ASSIGN_REVIEWER_EMPTY) elem.send_keys(user_email) selenium_utils.wait_for_js_to_load(self._driver) selenium_utils.get_when_all_visible(self._driver, WidgetInfoControl. ASSIGN_REVIEWER_DROPDOWN) base.ElementsList( self._driver, self._driver.find_element(*WidgetInfoControl. ASSIGN_REVIEWER_DROPDOWN)).get_item( user_email).click()
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 _init_items(self): """Init list of input items into multi input field.""" self._items = [ MultiInputItem(self._driver, el) for el in selenium_utils.get_when_all_visible( self._driver, self._locators.ITEMS) ]
def get_rows(self): """Get WebElements of rows in "table_element" scope Return list of WebElement: [WebElement, WebElement ...] """ if not self._rows: self._rows = selenium_utils.get_when_all_visible( self.table_element, self._locators.ROWS) return self._rows
def get_tree_view_header_elements(self): """Get tree view header as list of WebElements from the current widget. """ _locator_header = (By.CSS_SELECTOR, self._locators.HEADER.format(self.obj_name)) self._tree_view_header_elements = selenium_utils.get_when_all_visible( self._driver, _locator_header)
def get_mapped_snapshots_titles(self): """Return titles of mapped snapshots on Assessment Modal. Return: list of str """ return [base.Label(self._driver, el.find_element( *self._locators.MAPPED_SNAPSHOT_TITLE_CSS)).text for el in selenium_utils.get_when_all_visible( self._driver, self._locators.MAPPED_SNAPSHOTS_CSS)]
def get_value_by_header_text(self, header_text): """Get text of value element by header element text used searching in text scopes of headers and values. """ # pylint: disable=not-an-iterable headers_and_values = selenium_utils.get_when_all_visible( self._driver, self._locators.HEADERS_AND_VALUES) return [scope.text.splitlines()[1] for scope in headers_and_values if header_text in scope.text][0]
def dropdown_items(self): """Return list of DropdownMenu Items defined by "li" tag""" if not self._dropdown_items: elements_on_dropdown = selenium_utils.get_when_all_visible( self.dropdown_element, self._locators.DROPDOWN_ITEMS_CSS) self._dropdown_items = [DropdownMenuItem(self._driver, el) for el in elements_on_dropdown] return self._dropdown_items
def get_tree_view_items_elements(self): """Get Tree View items as list of elements from current widget.""" _locator_items = (By.CSS_SELECTOR, self._locators.ITEMS.format(self.obj_name)) selenium_utils.get_when_invisible(self._driver, self._locators.SPINNER) selenium_utils.wait_until_not_present(self._driver, self._locators.ITEM_LOADING) self._tree_view_items_elements = selenium_utils.get_when_all_visible( self._driver, _locator_items)
def dropdown_items(self): """Return list of DropdownMenu Items defined by "li" tag""" if not self._dropdown_items: elements_on_dropdown = selenium_utils.get_when_all_visible( self.dropdown_element, self._locators.DROPDOWN_ITEMS_CSS) self._dropdown_items = [ DropdownMenuItem(self._driver, el) for el in elements_on_dropdown ] return self._dropdown_items
def get_mappable_via_add_widgets_objs_aliases(self): """Returns the aliases of all currently available for mapping objects via 'Add Tab' button in Horizontal Nav Bar. Return: list of str """ # pylint: disable=invalid-name self.button_add_widget.click() add_elements = selenium_utils.get_when_all_visible( self._driver, locator.WidgetBarButtonAddDropdown.ALL_MAPPABLE_WIDGETS_OBJS) return [add_el.text for add_el in add_elements]
def get_tree_view_items_elements(self): """Get tree view items as list of WebElements from the current widget. """ _locator_items = (By.CSS_SELECTOR, self._locators.ITEMS.format(self.obj_name)) selenium_utils.get_when_invisible(self._driver, self._locators.SPINNER) selenium_utils.wait_until_not_present( self._driver, self._locators.ITEM_LOADING) self._tree_view_items_elements = selenium_utils.get_when_all_visible( self._driver, _locator_items)
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): """Check consistency of log item by passed log element. 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_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_EMAIL) } selenium_utils.wait_until_not_present(_driver, locator.Common.SPINNER_CSS) log_list = selenium_utils.get_when_all_visible( log_panel_element, tab_locators.LOG_LIST_CSS) return [check_log_item(el) for el in log_list]
def get_tree_view_items_elements(self): """Get Tree View items as list of elements from current widget. If no items in tree view return empty list. """ _locator_items = (By.CSS_SELECTOR, self._locators.ITEMS) self.wait_loading_after_actions() has_no_record_found = selenium_utils.is_element_exist( self._driver, self.locator_no_results_message) self._tree_view_items_elements = ([] if has_no_record_found else selenium_utils.get_when_all_visible( self._driver, _locator_items)) return self._tree_view_items_elements
def get_tree_view_items_elements(self): """Get Tree View items as list of elements from current widget. If no items in tree view return empty list. """ _locator_items = ( By.CSS_SELECTOR, self._locators.ITEMS) self.wait_loading_after_actions() has_no_record_found = selenium_utils.is_element_exist( self._driver, self.locator_no_results_message) self._tree_view_items_elements = ( [] if has_no_record_found else selenium_utils.get_when_all_visible(self._driver, _locator_items)) return self._tree_view_items_elements
def _set_custom_attributes_list(self): """Set custom attributes list with Custom Attribute objects from current opened content item. """ for row in selenium_utils.get_when_all_visible(self._driver, self._locators.ROW): attrs = [i.text for i in row.find_elements(*self._locators.CELL_IN_ROW)] self.custom_attributes_list.append( CustomAttributeEntity( title=attrs[0], type=objects.get_singular(objects.CUSTOM_ATTRIBUTES), attribute_type=attrs[1], mandatory=get_bool_value_from_arg(attrs[2]), definition_type=self._item_name))
def _set_custom_attributes_list(self): """Set custom attributes list with Custom Attribute objects from current opened content item. """ for row in selenium_utils.get_when_all_visible(self._driver, self._locators.ROW_CSS): attrs = [i.text for i in row.find_elements( *self._locators.CELL_IN_ROW_CSS)] # todo: add PO and getting 'multi_choice_options' via 'Edit' btn self.custom_attributes_list.append( CustomAttributeDefinitionsFactory().create( title=attrs[0], attribute_type=attrs[1], mandatory=StringMethods.get_bool_value_from_arg(attrs[2]), definition_type=self._item_name, multi_choice_options=None))
def _set_custom_attributes_list(self): """ Set custom attributes list with CustomAttribute objects from the current opened content item. """ for elem in selenium_utils.get_when_all_visible( self._driver, self._locator.ROW): attr = [ i.text for i in elem.find_elements(*self._locator.CELL_IN_ROW) ] self.custom_attributes_list.append( CustomAttribute(title=attr[0], ca_type=attr[1], is_mandatory=get_bool_from_string(attr[2]), definition_type=self._item_name))
def get_tree_view_items_elements(self): """Get Tree View items as list of elements from current widget. If no items in tree view return empty list. """ _locator_items = (By.CSS_SELECTOR, self._locators.ITEMS.format(self.widget_name)) selenium_utils.get_when_invisible(self._driver, self._locators.SPINNER) selenium_utils.wait_until_not_present(self._driver, self._locators.ITEM_LOADING) selenium_utils.wait_for_js_to_load(self._driver) has_no_record_found = selenium_utils.is_element_exist( self._driver, self._locators.NO_RESULTS_MESSAGE) self._tree_view_items_elements = ([] if has_no_record_found else selenium_utils.get_when_all_visible( self._driver, _locator_items))
def _get_latest_filter_elements(self): """Return elements of last filter parameter""" latest_filter_elem = self._driver.find_elements( *self._locators.FILTER_ROW_CSS) latest_filter = { "name": base.DropdownStatic( latest_filter_elem[-1], self._locators.FILTER_ATTRIBUTE_NAME), "compare_op": base.DropdownStatic( latest_filter_elem[-1], self._locators.FILTER_ATTRIBUTE_COMPARE), "value": base.TextInputField( latest_filter_elem[-1], self._locators.FILTER_ATTRIBUTE_VALUE), "operator": None} if len(latest_filter_elem) > 1: latest_filter["operator"] = base.DropdownStatic( self._driver, selenium_utils.get_when_all_visible( self._driver, self._locators.FILTER_OPERATOR)[-1]) return latest_filter
def _init_tree_view_items(self): """Init Tree View items as list of TreeViewItem from current widget. If no items in tree view return empty list. """ _locator_items = (By.CSS_SELECTOR, self._locators.ITEMS) self.wait_loading_after_actions() has_no_record_found = selenium_utils.is_element_exist( self._driver, self.locator_no_results_message) self._tree_view_items = ([] if has_no_record_found else [ TreeViewItem(driver=self._driver, locator_or_element=element, item_btn_locator=(By.CSS_SELECTOR, self._locators.ITEM_EXPAND_BTN)) for element in selenium_utils.get_when_all_visible( self._driver, _locator_items) ]) return self._tree_view_items
def _get_latest_filter_elements(self): """Return elements of last filter parameter""" latest_filter_elem = self._driver.find_elements( *self._locators.FILTER_ROW_CSS) latest_filter = { "name": base.DropdownAutocomplete( latest_filter_elem[-1], self._locators.FILTER_ATTRIBUTE_NAME), "compare_op": base.DropdownStatic( latest_filter_elem[-1], self._locators.FILTER_ATTRIBUTE_COMPARE), "value": base.TextInputField( latest_filter_elem[-1], self._locators.FILTER_ATTRIBUTE_VALUE), "operator": None} if len(latest_filter_elem) > 1: latest_filter["operator"] = base.DropdownStatic( self.modal_elem, selenium_utils.get_when_all_visible( self.modal_elem, self._locators.FILTER_OPERATOR)[-1]) return latest_filter
def changelog_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): """Check consistency of log item by passed log element. 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_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 == users.FAKE_SUPER_USER.email) } selenium_utils.wait_until_not_present( _driver, locator.Common.SPINNER_CSS) log_list = selenium_utils.get_when_all_visible( log_panel_element, tab_locators.LOG_LIST_CSS) return [check_log_item(el) for el in log_list]
def _init_tree_view_items(self): """Init Tree View items as list of TreeViewItem from current widget. If no items in tree view return empty list. """ _locator_items = ( By.CSS_SELECTOR, self._locators.ITEMS) self.wait_loading_after_actions() has_no_record_found = selenium_utils.is_element_exist( self._driver, self.locator_no_results_message) self._tree_view_items = ( [] if has_no_record_found else [ TreeViewItem( driver=self._driver, locator_or_element=element, item_btn_locator=( By.CSS_SELECTOR, self._locators.ITEM_EXPAND_BTN)) for element in selenium_utils.get_when_all_visible( self._driver, _locator_items)]) return self._tree_view_items
def _set_tree_view_items(self): """Set tree view items list with TreeViewItem objects from the current widget. """ items_locator = (By.CSS_SELECTOR, self._locator.ITEMS.format(self.object_name)) selenium_utils.get_when_invisible(self._driver, self._locator.SPINNER) selenium_utils.wait_until_not_present(self._driver, self._locator.ITEM_LOADING) elements = selenium_utils.get_when_all_visible(self._driver, items_locator) self._tree_view_items = [ TreeViewItem(driver=self._driver, text=el.text, expand_btn=el.find_element( By.CSS_SELECTOR, self._locator.ITEM_EXPAND_BUTTON)) for el in elements ]
def wait_and_get_pagination_controllers(self): """Wait for pagination controllers on filter panel and footer to be visible. First element have to belong filter panel, second - to footer. """ # pylint: disable=invalid-name exp_pagination_count = counters.PAGINATION_CTRLS_COUNT pagination_elements = selenium_utils.get_when_all_visible( self._driver, self._locators_filter.PAGINATION_CONTROLLERS_CSS) if pagination_elements: if len(pagination_elements) == exp_pagination_count: return pagination_elements else: raise ValueError(messages.ExceptionsMessages. err_pagination_count.format(exp_pagination_count)) else: raise exceptions.NoSuchElementException( messages.ExceptionsMessages.err_pagination_elements.format(",".join( ["".join(pag_el.text.splitlines()) for pag_el in pagination_elements])))
def __init__(self, driver): super(AuditsInfoWidget, self).__init__(driver) self.title = base.Label(driver, self._locator.TITLE) self.title_entered = base.Label(driver, self._locator.TITLE_ENTERED) self.state = base.Label(driver, self._locator.STATE) self.audit_lead = base.Label(driver, self._locator.AUDIT_LEAD) self.code = base.Label(driver, self._locator.CODE) # scopes self.headers_and_values = selenium_utils.get_when_all_visible( driver, self._locator.HEADERS_AND_VALUES) self.audit_lead_entered_text = self.get_value_by_header_text( self.audit_lead.text) self.code_entered_text = self.get_value_by_header_text(self.code.text) # scope self.list_headers_text = [ self.title.text, self._locator.elements.STATUS.upper(), self.audit_lead.text, self.code.text] self.list_values_text = [ self.title_entered.text, objects.get_normal_form(self.state.text), self.audit_lead_entered_text, self.code_entered_text]
def cell_values(self): """Return list of text from each cell""" return [cell.text for cell in selenium_utils.get_when_all_visible( self.element, self._locators.CELL)]
def _init_items(self): """Init list of input items into multi input field.""" self._items = [ MultiInputItem(self._driver, el) for el in selenium_utils.get_when_all_visible( self._driver, self._locators.ITEMS)]
def get_tree_view_header_elements(self): """Get Tree View header as list of elements from current widget.""" _locator_header = (By.CSS_SELECTOR, self._locators.HEADER) self._tree_view_header_elements = selenium_utils.get_when_all_visible( self._driver, _locator_header)
def _init_tree_view_headers(self): """Init Tree View headers as list of elements from current widget.""" _locator_header = (By.CSS_SELECTOR, self._locators.HEADER) self._tree_view_headers = selenium_utils.get_when_all_visible( self._driver, _locator_header)