def select_member_by_num(self, num): """Select member from list of members by number (start from 0). Args: num (int) Return: lib.page.widget.info.Widget """ # pylint: disable=not-callable selenium_utils.wait_for_js_to_load(self._driver) self._set_members_listed() try: member = self.members_listed[num] # wait for the listed items animation to stop selenium_utils.wait_until_stops_moving(member) selenium_utils.click_via_js(self._driver, member) # wait for the info pane animation to stop info_panel = selenium_utils.get_when_clickable( self._driver, locator.ObjectWidget.INFO_PANE) selenium_utils.wait_until_stops_moving(info_panel) return self.info_widget_cls(self._driver) except exceptions.StaleElementReferenceException: self.members_listed = self._driver.find_elements( *locator.ObjectWidget.MEMBERS_TITLE_LIST) return self.select_member_by_num(num) except exceptions.TimeoutException: # sometimes the click to the listed member results in hover return self.select_member_by_num(num)
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 __init__(self, driver): """ Args: driver (CustomDriver) """ self._driver = driver if driver.title: # only Login page doesn't have title and jQuery selenium_utils.wait_for_js_to_load(driver)
def export_objects(self): """Select 'Export Objects' button to confirm export objects to test's temporary directory as CSV file. """ button_export_objs = self.export_page.find_element( *self._locators.BUTTON_EXPORT_OBJECTS) base.Button(self._driver, button_export_objs).click() selenium_utils.wait_for_js_to_load(self._driver)
def wait_loading_after_actions(self): """Wait loading elements of Tree View after made some action with object(s) under Tree View. """ selenium_utils.wait_until_not_present( self._driver, self._locators.ITEM_LOADING) selenium_utils.get_when_invisible(self._driver, self._locators.SPINNER) selenium_utils.wait_for_js_to_load(self._driver)
def click_export_objs(self): """Click to 'Export Objects' button to confirm export objects according to selected before export format (Google Sheet or CSV). """ self.export_objs_btn.click() selenium_utils.get_when_invisible( self.export_page, self._locators.EXPORT_OBJECTS_SPINNER_CSS) selenium_utils.wait_for_js_to_load(self._driver)
def get_headers_and_values_dict_from_cas_scopes(self, is_gcas_not_lcas=True): # noqa: ignore=C901 """Get text of all CAs headers and values elements scopes and convert it to dictionary. If 'is_gcas_not_lcas' then get GCAs, if not 'is_gcas_not_lcas' then get LCAs. Example: :return {'ca_header1': 'ca_value1', 'ca_header2': 'ca_value2', ...} """ # pylint: disable=invalid-name # pylint: disable=too-many-branches selenium_utils.wait_for_js_to_load(self._driver) cas_locator = (self._locators.CAS_HEADERS_AND_VALUES if is_gcas_not_lcas else self._locators.LCAS_HEADERS_AND_VALUES) cas_headers_and_values = self.info_widget_elem.find_elements(*cas_locator) dict_cas_scopes = {} if len(cas_headers_and_values) >= 1: list_text_cas_scopes = [] for scope in cas_headers_and_values: ca_header_text = scope.text.splitlines()[0] if len(scope.text.splitlines()) >= 2: if scope.text.splitlines()[1].strip(): list_text_cas_scopes.append( [ca_header_text, scope.text.splitlines()[1]]) else: list_text_cas_scopes.append([ca_header_text, None]) if len(scope.text.splitlines()) == 1: if (element.AdminWidgetCustomAttributes.CHECKBOX.upper() in ca_header_text): list_text_cas_scopes.append( [ca_header_text, unicode(int(base.Checkbox(self._driver, scope.find_element( *self._locators.CAS_CHECKBOXES)).is_checked_via_js())) ]) else: list_text_cas_scopes.append([ca_header_text, None]) if not is_gcas_not_lcas: self.collect_lcas_attr_name_value( ca_header_text, list_text_cas_scopes, scope) cas_headers, _cas_values = [list(text_cas_scope) for text_cas_scope in zip(*list_text_cas_scopes)] # conversion cas_values = [] for ca_val in _cas_values: if ca_val is None: cas_values.append(None) elif ca_val == users.SUPERUSER_EMAIL: # Example User cas_values.append( unicode(objects.get_singular(objects.PEOPLE).title())) elif "/" in ca_val and len(ca_val) == 10: # Date _date = ca_val.split("/") cas_values.append(unicode("{y}-{m}-{d}".format( y=_date[2], m=_date[0], d=_date[1]))) else: # Other cas_values.append(ca_val) dict_cas_scopes = dict(zip(cas_headers, cas_values)) return dict_cas_scopes
def active_tab(self, tab_name): """Set active tab according to passed 'tab_name'. If passed 'tab_name' equal current active_tab do nothing. """ if tab_name != self.active_tab.text: self._active_tab = self.get_item(tab_name) selenium_utils.scroll_into_view(self._driver, self._active_tab.element) self._active_tab.click() selenium_utils.wait_for_js_to_load(self._driver)
def raise_issue(self, issue_entity): """Click on "raise issue" button then fill IssueCreate modal and save the Issue. """ raise_btn = base.Button(self._driver, self.table_element.find_element( *self._locators.TAB_BUTTON)) raise_btn.click() object_modal.get_modal_obj("issue", self._driver).submit_obj(issue_entity) selenium_utils.wait_for_js_to_load(self._driver)
def raise_issue(self, issue_entity): """Click on "raise issue" button then fill IssueCreate modal and save the Issue. """ raise_btn = base.Button(self._driver, self.table_element.find_element( *self._locators.TAB_BUTTON)) raise_btn.click() create_new_object.IssuesCreate(self._driver).fill_minimal_data( issue_entity.title, issue_entity.slug).save_and_close() selenium_utils.wait_for_js_to_load(self._driver)
def map_dest_objs(self, dest_objs_type, dest_objs_titles, is_asmts_generation=False): """Filter, search destination objects according to them type and titles. Map found destination objects to source object. If is_asmts_generation then TextFilterDropdown is using. """ selenium_utils.wait_for_js_to_load(self._driver) self.search_dest_objs(dest_objs_type, dest_objs_titles, is_asmts_generation=is_asmts_generation) self._select_dest_objs_to_map(objs_titles=dest_objs_titles) self._confirm_map_selected()
def wait_member_deleted(self, count): """Wait until elements' counter on filter panel refreshed with new value. Args: count (str) """ selenium_utils.wait_for_js_to_load(self._driver) if count != '1': new_count = ' {}'.format(int(count) - 1) selenium_utils.wait_for_element_text( self._driver, self._locators_filter.PAGINATION_CONTROLLERS_CSS, new_count) else: self.verify_counter_not_loaded()
def wait_member_deleted(self, count): """Wait until elements' counter on filter panel refreshed with new value. Args: count (str) """ selenium_utils.wait_for_js_to_load(self._driver) if count != '1': new_count = ' {}'.format(int(count) - 1) selenium_utils.wait_for_element_text( self._driver, locator.BaseWidgetGeneric.FILTER_PANE_COUNTER, new_count) else: self.verify_counter_not_loaded()
def get_header_and_value_txt_from_custom_scopes(self, header_text): """Get one header and one value elements text from custom scopes elements according to header text. Example: If header_text is 'header' :return ['header', 'value'] """ # pylint: disable=not-an-iterable # pylint: disable=invalid-name selenium_utils.wait_for_js_to_load(self._driver) all_headers_and_values = self.core_elem.find_elements( *self._locators.HEADERS_AND_VALUES) return next((scope.text.splitlines() + [None] if len(scope.text.splitlines()) == 1 else scope.text.splitlines()[:2] for scope in all_headers_and_values if header_text in scope.text), [None, None])
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 added_objs(self): """Returns objects added to the task group.""" prefix = "fa-" objs = [] selenium_utils.wait_for_js_to_load(self._driver) obj_rows = (self._root.element(class_name="tree-structure").lis( class_name="task-group-objects__list-item")) for obj_row in obj_rows: # define object type by icon class icon = obj_row.element(tag_name="i").wait_until(lambda e: e.present) obj_name = [ item.replace(prefix, "") for item in icon.classes if item.startswith(prefix) and item != prefix + "fw"][0] obj_title = obj_row.text factory = entity_factory_common.get_factory_by_obj_name(obj_name)() objs.append(factory.create_empty(title=obj_title)) return objs
def fill_lcas_attr_values(self): """Fill all local custom attribute with values.""" selenium_utils.wait_for_js_to_load(self._driver) cas_headers_and_values = self.info_widget_elem.find_elements( *locator.WidgetInfoAssessment.LCAS_HEADERS_AND_VALUES) dict_cas_scopes = {} if len(cas_headers_and_values) >= 1: for scope in cas_headers_and_values: ca_type = scope.get_attribute("class") if "custom-attribute-date" in ca_type: ca_elem = base.DateCustomAttribute( scope, locator.WidgetInfoPanel.DATE_CA_FIELDS, locator.WidgetInfoPanel.DATE_CA_INPUT) ca_elem.set_value() dict_cas_scopes.update({scope.text: ca_elem.get_value()}) selenium_utils.wait_for_element_text( self._driver, locator.WidgetInfoPanel.CA_SAVED_STATUS, element.GenericWidget.ALL_CHANGES_SAVED) return dict_cas_scopes
def get_header_and_value_text_from_custom_scopes(self, header_text, custom_scopes_locator=None): """Get one header and one value elements text from custom scopes elements according to scopes locator and header text. Example: If header_text is 'header' :return ['header', 'value'] """ # pylint: disable=not-an-iterable # pylint: disable=invalid-name selenium_utils.wait_for_js_to_load(self._driver) if not self.all_headers_and_values: if custom_scopes_locator: self.all_headers_and_values = self._driver.find_elements( *custom_scopes_locator) if not custom_scopes_locator and self.locator_headers_and_values: self.all_headers_and_values = self._driver.find_elements( *self.locator_headers_and_values) header_and_value = next((scope.text.splitlines()[:2] for scope in self.all_headers_and_values if header_text in scope.text), [None, None]) return header_and_value
def wait_loading_after_actions(self): """Wait loading elements of Tree View after made some action with object(s) under Tree View. """ from lib.utils.test_utils import wait_for selenium_utils.wait_until_not_present( self._driver, self._locators.ITEM_LOADING_CSS) selenium_utils.get_when_invisible( self._driver, self._locators.TREE_SPINNER_CSS) if "MAPPER_TREE_SPINNER_NO_RESULT" in self._locators.__dict__: 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 wait_for(is_result_ready) selenium_utils.wait_for_doc_is_ready(self._driver) selenium_utils.wait_for_js_to_load(self._driver)
def is_bulk_verify_displayed(self): """Returns whether 'Bulk Verify' option is displayed in 3bbs menu.""" selenium_utils.wait_for_js_to_load(self._driver) return self.bulk_verify_option.exists
def submit_query(self): """Submit query that was entered to field.""" self.button_submit.click() selenium_utils.wait_for_js_to_load(self._driver)
def get_items_count(self): """Get elements' count from counter on filter panel.""" selenium_utils.wait_for_js_to_load(self._driver) return self.wait_for_counter_loaded().text.split()[2]
def confirm_update(self): """Confirm update object.""" selenium_utils.wait_for_js_to_load(self._driver) self.button_update.click() selenium_utils.get_when_invisible( self._driver, self._locators.BUTTON_CONFIRM)
def archive(self): """Archives the workflow.""" self.three_bbs.select_archive() selenium_utils.wait_for_js_to_load(self._driver)
def approve_review(self, obj): """Approve review scenario.""" widget = self.open_info_page_of_obj(obj) widget.click_approve_review() selenium_utils.wait_for_js_to_load(self.driver) return self.info_widget_cls(self.driver)
def _click_btn_by_text(self, btn_text): """Click on the button with btn_text.""" selenium_utils.wait_for_js_to_load(self._driver) self.modal.button(text=btn_text).click() self.modal.wait_until_not( method=lambda e: e.present, timeout=ux.TWO_MIN_USER_WAIT)
def _select_search_dest_objs(self): """Click Search button to search objects according set filters.""" base.Button(self.modal_elem, self._locators.BUTTON_SEARCH).click() selenium_utils.wait_for_js_to_load(self._driver)
def clear_query(self): """Clear query that was entered to field.""" self.button_clear.click() selenium_utils.wait_for_js_to_load(self._driver)
def click_propose_changes(self): """Click on Propose Changes button.""" self.propose_changes_btn.click() selenium_utils.wait_for_js_to_load(self._driver)
def open_submit_for_review_popup(self): """Open submit for control popup by clicking on corresponding button.""" self.request_review_btn.click() selenium_utils.wait_for_js_to_load(self._driver)
def related_proposals(self): """Open related proposals tab.""" self.tabs.ensure_tab(self.proposals_tab) selenium_utils.wait_for_js_to_load(self._driver) return related_proposals.RelatedProposals()
def get_items_count(self): """Get elements' count from pagination controller on filter panel.""" selenium_utils.wait_for_js_to_load(self._driver) return self.wait_and_get_pagination_controllers()[0].text.split( "of ")[1]
def click_decline_btn(self): """Click on the decline button.""" selenium_utils.wait_for_js_to_load(self._driver) self._decline_btn.click() self._modal.wait_until_not_present()
def _select_search_dest_objs(self): """Click Search button to search objects according set filters.""" base.Button(self._driver, self._locators.BUTTON_SEARCH).click() selenium_utils.wait_for_js_to_load(self._driver)
def open_submit_for_review_popup(self): """Open submit for control popub by clicking on corresponding button.""" self._driver.find_element( *WidgetInfoControl.LINK_SUBMIT_FOR_REVIEW).click() selenium_utils.wait_for_js_to_load(self._driver)
def open_export_page(self): selenium_utils.open_url(self.export_page_url) selenium_utils.wait_for_js_to_load(self._driver)
def click_submit(self): """Click submit.""" self._driver.find_element(*WidgetInfoControl.SUBMIT_REVIEW_BUTTON).click() selenium_utils.wait_for_js_to_load(self._driver)
def _click_btn_by_text(self, btn_text): """Click on the button with btn_text.""" selenium_utils.wait_for_js_to_load(self._driver) self.modal.button(text=btn_text).click() self.modal.wait_until_not( method=lambda e: e.present, timeout=timeouts.TWO_MIN_USER_WAIT)
def __init__(self, _driver=None): super(Component, self).__init__() if self._driver.title: # only Login page doesn't have title and jQuery selenium_utils.wait_for_js_to_load(self._driver)
def click_request(self): """Click Request button.""" self.request_button.click() selenium_utils.wait_for_js_to_load(self._driver)