diff --git a/amuser/am_browser_ability.py b/amuser/am_browser_ability.py index 0a0c0b0..6afd361 100644 --- a/amuser/am_browser_ability.py +++ b/amuser/am_browser_ability.py @@ -47,32 +47,34 @@ class ArchivematicaBrowserAbility( def ss_api_key(self): if not self._ss_api_key: self.driver.get(self.get_ss_login_url()) - self.driver.find_element_by_id("id_username").send_keys(self.ss_username) - self.driver.find_element_by_id("id_password").send_keys(self.ss_password) - self.driver.find_element_by_css_selector( - c.varvn("SELECTOR_SS_LOGIN_BUTTON", self.vn) + self.driver.find_element(By.ID, "id_username").send_keys(self.ss_username) + self.driver.find_element(By.ID, "id_password").send_keys(self.ss_password) + self.driver.find_element( + By.CSS_SELECTOR, c.varvn("SELECTOR_SS_LOGIN_BUTTON", self.vn) ).click() self.driver.get(self.get_default_ss_user_edit_url()) block = WebDriverWait(self.driver, 20) block.until(EC.presence_of_element_located((By.CSS_SELECTOR, "code"))) - self._ss_api_key = self.driver.find_element_by_tag_name("code").text.strip() + self._ss_api_key = self.driver.find_element( + By.TAG_NAME, "code" + ).text.strip() return self._ss_api_key def get_displayed_tabs(self): ret = [] - for li_el in self.driver.find_element_by_css_selector( - "ul.navbar-nav" - ).find_elements_by_tag_name("li"): + for li_el in self.driver.find_element( + By.CSS_SELECTOR, "ul.navbar-nav" + ).find_elements(By.TAG_NAME, "li"): ret.append(li_el.text.strip().split("\n")[0]) return list(filter(None, ret)) def assert_sip_arrange_pane_not_displayed(self): for selector in ("form#search_form", "div#originals", "div#arrange"): try: - self.driver.find_element_by_css_selector(selector) + self.driver.find_element(By.CSS_SELECTOR, selector) except NoSuchElementException as exc: assert f"Unable to locate element: {selector}" in str(exc) - assert self.driver.find_element_by_css_selector("div#sip-container") + assert self.driver.find_element(By.CSS_SELECTOR, "div#sip-container") # ========================================================================== # Archival Storage Tab @@ -86,18 +88,20 @@ def wait_for_aip_in_archival_storage(self, aip_uuid): attempts = 0 while True: self.navigate(self.get_archival_storage_url(), reload=True) - self.driver.find_element_by_css_selector( - 'input[title="search query"]' + self.driver.find_element( + By.CSS_SELECTOR, 'input[title="search query"]' ).send_keys(aip_uuid) Select( - self.driver.find_element_by_css_selector('select[title="field name"]') + self.driver.find_element(By.CSS_SELECTOR, 'select[title="field name"]') ).select_by_visible_text("AIP UUID") Select( - self.driver.find_element_by_css_selector('select[title="query type"]') + self.driver.find_element(By.CSS_SELECTOR, 'select[title="query type"]') ).select_by_visible_text("Phrase") - self.driver.find_element_by_id("search_submit").click() + self.driver.find_element(By.ID, "search_submit").click() self.wait_for_presence("#archival-storage-entries_info") - summary_el = self.driver.find_element_by_id("archival-storage-entries_info") + summary_el = self.driver.find_element( + By.ID, "archival-storage-entries_info" + ) if summary_el.text.strip() == "Showing 0 to 0 of 0 entries": attempts += 1 if attempts > max_attempts: @@ -118,18 +122,18 @@ def request_aip_delete(self, aip_uuid): self.wait_for_presence(delete_tab_selector, timeout=self.apathetic_wait) while True: try: - self.driver.find_element_by_id("id_delete-uuid").click() + self.driver.find_element(By.ID, "id_delete-uuid").click() break except (ElementNotVisibleException, ElementNotInteractableException): - self.driver.find_element_by_css_selector(delete_tab_selector).click() + self.driver.find_element(By.CSS_SELECTOR, delete_tab_selector).click() time.sleep(self.optimistic_wait) - self.driver.find_element_by_id("id_delete-uuid").send_keys(aip_uuid) - self.driver.find_element_by_id("id_delete-reason").send_keys("Cuz wanna") - self.driver.find_element_by_css_selector( - 'button[name="submit-delete-form"]' + self.driver.find_element(By.ID, "id_delete-uuid").send_keys(aip_uuid) + self.driver.find_element(By.ID, "id_delete-reason").send_keys("Cuz wanna") + self.driver.find_element( + By.CSS_SELECTOR, 'button[name="submit-delete-form"]' ).click() - alert_text = self.driver.find_element_by_css_selector( - "div.alert-info" + alert_text = self.driver.find_element( + By.CSS_SELECTOR, "div.alert-info" ).text.strip() assert alert_text == "Delete request created successfully." @@ -182,19 +186,19 @@ def initiate_reingest(self, aip_uuid, reingest_type="metadata-only"): " {}".format(reingest_type, aip_uuid) ) while True: - type_input_el = self.driver.find_element_by_css_selector(type_selector) + type_input_el = self.driver.find_element(By.CSS_SELECTOR, type_selector) if type_input_el.is_displayed(): break else: - self.driver.find_element_by_css_selector(reingest_tab_selector).click() + self.driver.find_element(By.CSS_SELECTOR, reingest_tab_selector).click() time.sleep(self.optimistic_wait) - self.driver.find_element_by_css_selector(type_selector).click() - self.driver.find_element_by_css_selector( - "button[name=submit-reingest-form]" + self.driver.find_element(By.CSS_SELECTOR, type_selector).click() + self.driver.find_element( + By.CSS_SELECTOR, "button[name=submit-reingest-form]" ).click() self.wait_for_visibility("div.alert-success") - alert_text = self.driver.find_element_by_css_selector( - "div.alert-success" + alert_text = self.driver.find_element( + By.CSS_SELECTOR, "div.alert-success" ).text.strip() assert alert_text.startswith(f"Package {aip_uuid} sent to pipeline") assert alert_text.endswith("for re-ingest") @@ -209,18 +213,18 @@ def wait_for_dip_in_transfer_backlog(self, dip_uuid): seconds = 0 while True: self.navigate(self.get_transfer_backlog_url(), reload=True) - self.driver.find_element_by_css_selector( - 'input[title="search query"]' + self.driver.find_element( + By.CSS_SELECTOR, 'input[title="search query"]' ).send_keys(dip_uuid) Select( - self.driver.find_element_by_css_selector('select[title="field name"]') + self.driver.find_element(By.CSS_SELECTOR, 'select[title="field name"]') ).select_by_visible_text("Transfer UUID") Select( - self.driver.find_element_by_css_selector('select[title="query type"]') + self.driver.find_element(By.CSS_SELECTOR, 'select[title="query type"]') ).select_by_visible_text("Phrase") - self.driver.find_element_by_id("search_submit").click() + self.driver.find_element(By.ID, "search_submit").click() self.wait_for_presence("#backlog-entries_info") - summary_el = self.driver.find_element_by_id("backlog-entries_info") + summary_el = self.driver.find_element(By.ID, "backlog-entries_info") if summary_el.text.strip() == "Showing 0 to 0 of 0 entries": seconds += 1 if seconds > max_seconds: @@ -252,10 +256,10 @@ def upload_policy(self, policy_path): self.driver.execute_script( "document.getElementById('file').style.display='block'" ) - self.driver.find_element_by_css_selector("input[name=file]").send_keys( + self.driver.find_element(By.CSS_SELECTOR, "input[name=file]").send_keys( policy_path ) - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() def navigate_to_policies(self): self.navigate(self.get_policies_url()) @@ -269,7 +273,7 @@ def configure_handle(self, **kwargs): self.navigate(self.get_handle_config_url()) for key, val in kwargs.items(): dom_id = "id_" + key - input_el = self.driver.find_element_by_id(dom_id) + input_el = self.driver.find_element(By.ID, dom_id) if input_el.tag_name == "select": Select(input_el).select_by_visible_text(val) elif input_el.get_attribute("type") == "checkbox": @@ -281,18 +285,20 @@ def configure_handle(self, **kwargs): else: input_el.clear() input_el.send_keys(val) - submit_button = self.driver.find_element_by_css_selector("input[type=submit]") + submit_button = self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]") submit_button.click() self.wait_for_visibility("div.alert-info") assert ( - self.driver.find_element_by_css_selector(".alert-info").text.strip() + self.driver.find_element(By.CSS_SELECTOR, ".alert-info").text.strip() == "Saved." ), "Unable to confirm saving of Handle configuration" def get_es_indexing_config_text(self): self.navigate(self.get_admin_general_url()) try: - el = self.driver.find_element_by_css_selector("p.es-indexing-configuration") + el = self.driver.find_element( + By.CSS_SELECTOR, "p.es-indexing-configuration" + ) except NoSuchElementException: return None else: @@ -314,7 +320,7 @@ def save_default_processing_config(self): ) if self.driver.current_url != edit_default_processing_config_url: self.navigate(edit_default_processing_config_url) - self.driver.find_element_by_css_selector("input[value=Save]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[value=Save]").click() def get_processing_config_decision_options(self, **kwargs): """Return the options available for a given processing config decision @@ -342,10 +348,10 @@ def get_processing_config_decision_options(self, **kwargs): else: if not decision_id.startswith("id_"): decision_id = "id_" + decision_id - decision_el = self.driver.find_element_by_id(decision_id) + decision_el = self.driver.find_element(By.ID, decision_id) options = [] if decision_el.tag_name == "select": - for option_el in decision_el.find_elements_by_tag_name("option"): + for option_el in decision_el.find_elements(By.TAG_NAME, "option"): options.append(option_el.text.strip()) return options @@ -389,7 +395,7 @@ def set_processing_config_decision(self, **kwargs): else: if not decision_id.startswith("id_"): decision_id = "id_" + decision_id - decision_el = self.driver.find_element_by_id(decision_id) + decision_el = self.driver.find_element(By.ID, decision_id) if decision_el.tag_name == "select": decision_select = Select(decision_el) if choice_value_attr is not None: @@ -520,32 +526,34 @@ def setup_new_install(self): ss_api_key = self.ss_api_key self.create_first_user() self.wait_for_presence("#id_storage_service_apikey", 100) - self.driver.find_element_by_id("id_storage_service_apikey").send_keys( + self.driver.find_element(By.ID, "id_storage_service_apikey").send_keys( ss_api_key ) - self.driver.find_element_by_css_selector( - c.varvn("SELECTOR_DFLT_SS_REG", self.vn) + self.driver.find_element( + By.CSS_SELECTOR, c.varvn("SELECTOR_DFLT_SS_REG", self.vn) ).click() def create_first_user(self): """Create a test user via the /installer/welcome/ page interface.""" self.driver.get(self.get_installer_welcome_url()) self.wait_for_presence("#id_org_name") - self.driver.find_element_by_id("id_org_name").send_keys(c.DEFAULT_AM_USERNAME) - self.driver.find_element_by_id("id_org_identifier").send_keys( + self.driver.find_element(By.ID, "id_org_name").send_keys(c.DEFAULT_AM_USERNAME) + self.driver.find_element(By.ID, "id_org_identifier").send_keys( + c.DEFAULT_AM_USERNAME + ) + self.driver.find_element(By.ID, "id_username").send_keys(c.DEFAULT_AM_USERNAME) + self.driver.find_element(By.ID, "id_first_name").send_keys( c.DEFAULT_AM_USERNAME ) - self.driver.find_element_by_id("id_username").send_keys(c.DEFAULT_AM_USERNAME) - self.driver.find_element_by_id("id_first_name").send_keys(c.DEFAULT_AM_USERNAME) - self.driver.find_element_by_id("id_last_name").send_keys(c.DEFAULT_AM_USERNAME) - self.driver.find_element_by_id("id_email").send_keys("test@gmail.com") - self.driver.find_element_by_id("id_password1").send_keys(c.DEFAULT_AM_PASSWORD) - self.driver.find_element_by_id("id_password2").send_keys(c.DEFAULT_AM_PASSWORD) - self.driver.find_element_by_tag_name("button").click() + self.driver.find_element(By.ID, "id_last_name").send_keys(c.DEFAULT_AM_USERNAME) + self.driver.find_element(By.ID, "id_email").send_keys("test@gmail.com") + self.driver.find_element(By.ID, "id_password1").send_keys(c.DEFAULT_AM_PASSWORD) + self.driver.find_element(By.ID, "id_password2").send_keys(c.DEFAULT_AM_PASSWORD) + self.driver.find_element(By.TAG_NAME, "button").click() continue_button_selector = "input[value=Continue]" self.wait_for_presence(continue_button_selector, 100) - continue_button_el = self.driver.find_element_by_css_selector( - continue_button_selector + continue_button_el = self.driver.find_element( + By.CSS_SELECTOR, continue_button_selector ) continue_button_el.click() diff --git a/amuser/am_browser_auth_ability.py b/amuser/am_browser_auth_ability.py index 51a8a67..94e6ba4 100644 --- a/amuser/am_browser_auth_ability.py +++ b/amuser/am_browser_auth_ability.py @@ -29,11 +29,11 @@ def login(self): WebDriverWait(self.driver, self.pessimistic_wait).until(element_present) except TimeoutException: logger.warning("Timed out when waiting for login page to load") - username_elem = self.driver.find_element_by_id(username_input_id) + username_elem = self.driver.find_element(By.ID, username_input_id) username_elem.send_keys(self.am_username) - password_elem = self.driver.find_element_by_id(password_input_id) + password_elem = self.driver.find_element(By.ID, password_input_id) password_elem.send_keys(self.am_password) - submit_button_elem = self.driver.find_element_by_tag_name("button") + submit_button_elem = self.driver.find_element(By.TAG_NAME, "button") submit_button_elem.click() def login_ss(self): @@ -46,11 +46,11 @@ def login_ss(self): WebDriverWait(self.driver, self.pessimistic_wait).until(element_present) except TimeoutException: logger.warning("Timed out when waiting for SS login page to load") - username_elem = self.driver.find_element_by_id(username_input_id) + username_elem = self.driver.find_element(By.ID, username_input_id) username_elem.send_keys(self.ss_username) - password_elem = self.driver.find_element_by_id(password_input_id) + password_elem = self.driver.find_element(By.ID, password_input_id) password_elem.send_keys(self.ss_password) - submit_button_elem = self.driver.find_element_by_css_selector( - "input[type=submit]" + submit_button_elem = self.driver.find_element( + By.CSS_SELECTOR, "input[type=submit]" ) submit_button_elem.click() diff --git a/amuser/am_browser_file_explorer_ability.py b/amuser/am_browser_file_explorer_ability.py index d889b8e..3624b49 100644 --- a/amuser/am_browser_file_explorer_ability.py +++ b/amuser/am_browser_file_explorer_ability.py @@ -31,11 +31,11 @@ def add_transfer_directory(self, path): link. """ # Click the "Browse" button, if necessary. - if not self.driver.find_element_by_css_selector( - c.SELECTOR_DIV_TRANSFER_SOURCE_BROWSE + if not self.driver.find_element( + By.CSS_SELECTOR, c.SELECTOR_DIV_TRANSFER_SOURCE_BROWSE ).is_displayed(): - browse_button_elem = self.driver.find_element_by_css_selector( - c.SELECTOR_BUTTON_BROWSE_TRANSFER_SOURCES + browse_button_elem = self.driver.find_element( + By.CSS_SELECTOR, c.SELECTOR_BUTTON_BROWSE_TRANSFER_SOURCES ) browse_button_elem.click() # Wait for the File Explorer modal dialog to open. @@ -97,7 +97,7 @@ def _navigate_to_transfer_directory_and_click(self, path): if is_last: logger.info('Clicking to select folder "%s"', folder) # Click target (leaf) folder and then "Add" button. - folder_el = self.driver.find_element_by_xpath(folder_label_xpath) + folder_el = self.driver.find_element(By.XPATH, folder_label_xpath) self.click_folder_label(folder_el) time.sleep(self.pessimistic_wait) self.click_add_button() @@ -115,12 +115,12 @@ def click_add_folder(self, folder_id): """ block = WebDriverWait(self.driver, 10) block.until(EC.presence_of_element_located((By.ID, folder_id))) - folder_elem = self.driver.find_element_by_id(folder_id) + folder_elem = self.driver.find_element(By.ID, folder_id) hover = ActionChains(self.driver).move_to_element(folder_elem) hover.perform() time.sleep(self.micro_wait) # seems to be necessary (! jQuery animations?) - span_elem = self.driver.find_element_by_css_selector( - f"div#{folder_id} span.{c.CLASS_ADD_TRANSFER_FOLDER}" + span_elem = self.driver.find_element( + By.CSS_SELECTOR, f"div#{folder_id} span.{c.CLASS_ADD_TRANSFER_FOLDER}" ) hover = ActionChains(self.driver).move_to_element(span_elem) hover.perform() @@ -145,16 +145,16 @@ def click_folder_label(self, folder_el, offset=0): if counter > 10: return folder_el.click() - if not self.driver.find_element_by_css_selector( - c.SELECTOR_BUTTON_ADD_DIR_TO_TRANSFER + if not self.driver.find_element( + By.CSS_SELECTOR, c.SELECTOR_BUTTON_ADD_DIR_TO_TRANSFER ).is_enabled(): logger.info("The Add button has not become clickable.") raise WebDriverException("ADD is not clickable") logger.info("The Add button has become clickable.") except WebDriverException: counter += 1 - container_el = self.driver.find_element_by_css_selector( - ".transfer-tree-container" + container_el = self.driver.find_element( + By.CSS_SELECTOR, ".transfer-tree-container" ) self.driver.execute_script( f"arguments[0].scrollTop = {offset}", container_el @@ -173,7 +173,7 @@ def click_folder(self, folder_label_xpath, is_file=False, offset=0): block = WebDriverWait(self.driver, 10) block.until(EC.presence_of_element_located((By.XPATH, folder_label_xpath))) folder_icon_xpath = folder_label2icon_xpath(folder_label_xpath) - folder_icon_el = self.driver.find_element_by_xpath(folder_icon_xpath) + folder_icon_el = self.driver.find_element(By.XPATH, folder_icon_xpath) folder_icon_el.click() folder_children_xpath = folder_label2children_xpath(folder_label_xpath) block = WebDriverWait(self.driver, 10) @@ -183,8 +183,8 @@ def click_folder(self, folder_label_xpath, is_file=False, offset=0): # TODO: when clicking a file in the new interface (if ever this is # required), we may need different behaviour. except WebDriverException: - container_el = self.driver.find_element_by_css_selector( - ".transfer-tree-container" + container_el = self.driver.find_element( + By.CSS_SELECTOR, ".transfer-tree-container" ) self.driver.execute_script( f"arguments[0].scrollTop = {offset}", container_el @@ -200,7 +200,7 @@ def click_folder_old_browser(self, folder_id, is_file=False): """ block = WebDriverWait(self.driver, 10) block.until(EC.presence_of_element_located((By.ID, folder_id))) - folder_elem = self.driver.find_element_by_id(folder_id) + folder_elem = self.driver.find_element(By.ID, folder_id) hover = ActionChains(self.driver).move_to_element(folder_elem) hover.perform() time.sleep(self.micro_wait) # seems to be necessary (! jQuery animations?) @@ -209,7 +209,7 @@ def click_folder_old_browser(self, folder_id, is_file=False): class_ = "backbone-file-explorer-directory_entry_name" folder_id = folder_id.replace(".", r"\.") selector = f"div#{folder_id} span.{class_}" - span_elem = self.driver.find_element_by_css_selector(selector) + span_elem = self.driver.find_element(By.CSS_SELECTOR, selector) hover = ActionChains(self.driver).move_to_element(span_elem) hover.perform() span_elem.click() diff --git a/amuser/am_browser_ingest_ability.py b/amuser/am_browser_ingest_ability.py index adb9fa4..636e2e6 100644 --- a/amuser/am_browser_ingest_ability.py +++ b/amuser/am_browser_ingest_ability.py @@ -178,18 +178,18 @@ def _navigate_to_aip_directory_and_click(self, path): def add_dummy_metadata(self, sip_uuid): self.navigate(self.get_ingest_url()) - self.driver.find_element_by_id( - f"sip-row-{sip_uuid}" - ).find_element_by_css_selector("a.btn_show_metadata").click() + self.driver.find_element(By.ID, f"sip-row-{sip_uuid}").find_element( + By.CSS_SELECTOR, "a.btn_show_metadata" + ).click() self.navigate(self.get_metadata_add_url(sip_uuid)) for attr in self.metadata_attrs: - self.driver.find_element_by_id(f"id_{attr}").send_keys(self.dummy_val) + self.driver.find_element(By.ID, f"id_{attr}").send_keys(self.dummy_val) try: - self.driver.find_element_by_css_selector("input[value=Create]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[value=Create]").click() except NoSuchElementException: # Should be a "Create" button but sometimes during development the # metadata already exists so it is a "Save" button. - self.driver.find_element_by_css_selector("input[value=Save]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[value=Save]").click() def parse_normalization_report(self, sip_uuid): """Wait for the "Approve normalization" job to appear and then open the @@ -211,16 +211,16 @@ def parse_normalization_report(self, sip_uuid): self.login() self.driver.get(nrmlztn_rprt_url) self.wait_for_presence("table") - table_el = self.driver.find_element_by_css_selector("table") + table_el = self.driver.find_element(By.CSS_SELECTOR, "table") keys = [ td_el.text.strip().lower().replace(" ", "_") - for td_el in table_el.find_element_by_css_selector( - "thead tr" - ).find_elements_by_css_selector("th") + for td_el in table_el.find_element( + By.CSS_SELECTOR, "thead tr" + ).find_elements(By.CSS_SELECTOR, "th") ] - for tr_el in table_el.find_elements_by_css_selector("tbody tr"): + for tr_el in table_el.find_elements(By.CSS_SELECTOR, "tbody tr"): row = {} - for index, td_el in enumerate(tr_el.find_elements_by_css_selector("td")): + for index, td_el in enumerate(tr_el.find_elements(By.CSS_SELECTOR, "td")): row[keys[index]] = td_el.text report.append(row) return report diff --git a/amuser/am_browser_jobs_tasks_ability.py b/amuser/am_browser_jobs_tasks_ability.py index c9de0ef..0f8bfb5 100644 --- a/amuser/am_browser_jobs_tasks_ability.py +++ b/amuser/am_browser_jobs_tasks_ability.py @@ -4,6 +4,7 @@ import time from selenium.common.exceptions import NoSuchElementException +from selenium.webdriver.common.by import By from . import constants as c from . import selenium_ability @@ -28,13 +29,13 @@ def get_job_output(self, ms_name, transfer_uuid): ms_group_elem = self.get_transfer_micro_service_group_elem( group_name, transfer_uuid ) - for job_elem in ms_group_elem.find_elements_by_css_selector("div.job"): - for span_elem in job_elem.find_elements_by_css_selector( - "div.job-detail-microservice span" + for job_elem in ms_group_elem.find_elements(By.CSS_SELECTOR, "div.job"): + for span_elem in job_elem.find_elements( + By.CSS_SELECTOR, "div.job-detail-microservice span" ): if span_elem.text.strip() == ms_name: - return job_elem.find_element_by_css_selector( - "div.job-detail-currentstep span" + return job_elem.find_element( + By.CSS_SELECTOR, "div.job-detail-currentstep span" ).text.strip() return None @@ -56,7 +57,7 @@ def expose_job(self, ms_name, transfer_uuid, unit_type="transfer"): self.wait_for_transfer_micro_service_group(group_name, transfer_uuid) is_visible = ( self.get_transfer_micro_service_group_elem(group_name, transfer_uuid) - .find_element_by_css_selector("div.microservice-group + div") + .find_element(By.CSS_SELECTOR, "div.microservice-group + div") .is_displayed() ) if not is_visible: @@ -122,42 +123,42 @@ def _parse_tasks_table_am_gte_1_7(self, tasks_url, table_dict): self.login() self.driver.get(tasks_url) self.wait_for_presence("article.task") - for task_art_elem in self.driver.find_elements_by_css_selector("article.task"): + for task_art_elem in self.driver.find_elements(By.CSS_SELECTOR, "article.task"): row_dict = {} try: - row_dict["stdout"] = task_art_elem.find_element_by_css_selector( - ".panel-info pre" + row_dict["stdout"] = task_art_elem.find_element( + By.CSS_SELECTOR, ".panel-info pre" ).text.strip() except NoSuchElementException: row_dict["stdout"] = "" try: - row_dict["stderr"] = task_art_elem.find_element_by_css_selector( - ".panel-danger pre" + row_dict["stderr"] = task_art_elem.find_element( + By.CSS_SELECTOR, ".panel-danger pre" ).text.strip() except NoSuchElementException: row_dict["stderr"] = "" - row_dict["command"] = task_art_elem.find_element_by_css_selector( - "h3.panel-title.panel-title-simple" + row_dict["command"] = task_art_elem.find_element( + By.CSS_SELECTOR, "h3.panel-title.panel-title-simple" ).text.strip() - arguments = task_art_elem.find_element_by_css_selector( - "div.panel-primary div.shell-output pre" + arguments = task_art_elem.find_element( + By.CSS_SELECTOR, "div.panel-primary div.shell-output pre" ).text.strip() row_dict["arguments"] = utils.parse_task_arguments_to_list(arguments) - for dl_el in task_art_elem.find_elements_by_css_selector("div.row dl"): - for el in dl_el.find_elements_by_css_selector("*"): + for dl_el in task_art_elem.find_elements(By.CSS_SELECTOR, "div.row dl"): + for el in dl_el.find_elements(By.CSS_SELECTOR, "*"): if el.tag_name == "dt": attr = el.text.strip().lower().replace(" ", "_") else: val = el.text.strip() row_dict[attr] = val row_dict["task_uuid"] = ( - task_art_elem.find_element_by_css_selector("div.task-heading h4") + task_art_elem.find_element(By.CSS_SELECTOR, "div.task-heading h4") .text.strip() .split()[1] ) table_dict["tasks"][row_dict["task_uuid"]] = row_dict next_tasks_url = None - for link_button in self.driver.find_elements_by_css_selector("a.btn"): + for link_button in self.driver.find_elements(By.CSS_SELECTOR, "a.btn"): if link_button.text.strip() == "Next page": next_tasks_url = "{}{}".format( self.am_url, link_button.get_attribute("href") @@ -182,13 +183,13 @@ def get_job_uuid( ms_group_elem = self.get_transfer_micro_service_group_elem( group_name, transfer_uuid ) - for job_elem in ms_group_elem.find_elements_by_css_selector("div.job"): - for span_elem in job_elem.find_elements_by_css_selector( - "div.job-detail-microservice span" + for job_elem in ms_group_elem.find_elements(By.CSS_SELECTOR, "div.job"): + for span_elem in job_elem.find_elements( + By.CSS_SELECTOR, "div.job-detail-microservice span" ): if utils.squash(span_elem.text) == utils.squash(ms_name): - job_output = job_elem.find_element_by_css_selector( - "div.job-detail-currentstep span" + job_output = job_elem.find_element( + By.CSS_SELECTOR, "div.job-detail-currentstep span" ).text.strip() if job_output in job_outputs: return (span_elem.get_attribute("title").strip(), job_output) @@ -217,7 +218,7 @@ def get_job_uuid( def process_task_header_row(row_elem, row_dict): """Parse the text in the first tasks , the one "File UUID:".""" - for line in row_elem.find_element_by_tag_name("td").text.strip().split("\n"): + for line in row_elem.find_element(By.TAG_NAME, "td").text.strip().split("\n"): line = line.strip() if line.startswith("("): line = line[1:] @@ -232,7 +233,7 @@ def process_task_command_row(row_elem, row_dict): """Parse the text in the second tasks , the one specifying command and arguments. """ - command_text = row_elem.find_element_by_tag_name("td").text.strip().split(":")[1] + command_text = row_elem.find_element(By.TAG_NAME, "td").text.strip().split(":")[1] command, *arguments = command_text.split() row_dict["command"] = command arguments = " ".join(arguments) @@ -242,13 +243,13 @@ def process_task_command_row(row_elem, row_dict): def process_task_stdout_row(row_elem, row_dict): """Parse out the tasks's stdout from the .""" - row_dict["stdout"] = row_elem.find_element_by_tag_name("pre").text.strip() + row_dict["stdout"] = row_elem.find_element(By.TAG_NAME, "pre").text.strip() return row_dict def process_task_stderr_row(row_elem, row_dict): """Parse out the tasks's stderr from the
.""" - row_dict["stderr"] = row_elem.find_element_by_tag_name("pre").text.strip() + row_dict["stderr"] = row_elem.find_element(By.TAG_NAME, "pre").text.strip() return row_dict @@ -262,12 +263,12 @@ def get_tasks_row_type(row_elem): if row_elem.get_attribute("class").strip(): return "header" try: - row_elem.find_element_by_css_selector("td.stdout") + row_elem.find_element(By.CSS_SELECTOR, "td.stdout") return "stdout" except NoSuchElementException: pass try: - row_elem.find_element_by_css_selector("td.stderror") + row_elem.find_element(By.CSS_SELECTOR, "td.stderror") return "stderr" except NoSuchElementException: pass diff --git a/amuser/am_browser_preservation_planning_ability.py b/amuser/am_browser_preservation_planning_ability.py index 9d96966..37ca5f7 100644 --- a/amuser/am_browser_preservation_planning_ability.py +++ b/amuser/am_browser_preservation_planning_ability.py @@ -2,6 +2,7 @@ import logging from selenium.common.exceptions import NoSuchElementException +from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from . import selenium_ability @@ -25,8 +26,8 @@ def navigate_to_normalization_rules(self): self.navigate(self.get_normalization_rules_url()) def search_rules(self, search_term): - search_input_el = self.driver.find_element_by_css_selector( - "#DataTables_Table_0_filter input" + search_input_el = self.driver.find_element( + By.CSS_SELECTOR, "#DataTables_Table_0_filter input" ) search_input_el.send_keys(search_term) @@ -34,7 +35,7 @@ def click_first_rule_replace_link(self): """Click the "replace" link of the first rule in the FPR rules table visible on the page. """ - for a_el in self.driver.find_elements_by_tag_name("a"): + for a_el in self.driver.find_elements(By.TAG_NAME, "a"): if a_el.text.strip() == "Replace": a_el.click() break @@ -43,13 +44,13 @@ def wait_for_rule_edit_interface(self): self.wait_for_presence("input[type=submit]") def set_fpr_command(self, command_name): - command_select_el = self.driver.find_element_by_id("id_f-command") + command_select_el = self.driver.find_element(By.ID, "id_f-command") command_select_el.click() Select(command_select_el).select_by_visible_text(command_name) def save_fpr_command(self): - command_select_el = self.driver.find_element_by_css_selector( - "input[type=submit]" + command_select_el = self.driver.find_element( + By.CSS_SELECTOR, "input[type=submit]" ) command_select_el.click() self.wait_for_presence("#DataTables_Table_0") @@ -74,10 +75,10 @@ def navigate_to_first_policy_check_validation_command(self): """ policy_command_url = None policy_command_descriptions = [] - commands_table_el = self.driver.find_element_by_id("DataTables_Table_0") - for row_el in commands_table_el.find_elements_by_tag_name("tr"): + commands_table_el = self.driver.find_element(By.ID, "DataTables_Table_0") + for row_el in commands_table_el.find_elements(By.TAG_NAME, "tr"): try: - anchor_el = row_el.find_element_by_tag_name("a") + anchor_el = row_el.find_element(By.TAG_NAME, "a") except NoSuchElementException: pass else: @@ -118,11 +119,11 @@ def get_policy_command(self, policy_file, policy_path): # Get the text of the command. policy_command = None next_el = False - for el in self.driver.find_element_by_tag_name( - "dl" - ).find_elements_by_css_selector("*"): + for el in self.driver.find_element(By.TAG_NAME, "dl").find_elements( + By.CSS_SELECTOR, "*" + ): if next_el: - policy_command = el.find_element_by_tag_name("pre").text.strip() + policy_command = el.find_element(By.TAG_NAME, "pre").text.strip() break if el.text.strip() == "Command": next_el = True @@ -149,20 +150,20 @@ def save_policy_check_command(self, policy_command, description): description, ) self.navigate(self.get_create_command_url()) - for option in self.driver.find_element_by_id( - "id_tool" - ).find_elements_by_tag_name("option"): + for option in self.driver.find_element(By.ID, "id_tool").find_elements( + By.TAG_NAME, "option" + ): if "MediaConch" in option.text: option.click() break - self.driver.find_element_by_id("id_description").send_keys(description) + self.driver.find_element(By.ID, "id_description").send_keys(description) js_script = 'document.getElementById("id_command").value =' " `{}`;".format( policy_command ) self.driver.execute_script(js_script) - self.driver.find_element_by_id("id_script_type").send_keys("Python") - self.driver.find_element_by_id("id_command_usage").send_keys("Validation") - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.ID, "id_script_type").send_keys("Python") + self.driver.find_element(By.ID, "id_command_usage").send_keys("Validation") + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() logger.info("Created the FPR policy check command") def ensure_fpr_rule(self, purpose, format_, command_description): @@ -184,16 +185,16 @@ def ensure_fpr_rule(self, purpose, format_, command_description): return logger.info("Creating the needed FPR rule.") self.navigate(self.get_create_rule_url()) - Select(self.driver.find_element_by_id("id_f-purpose")).select_by_visible_text( + Select(self.driver.find_element(By.ID, "id_f-purpose")).select_by_visible_text( purpose ) - Select(self.driver.find_element_by_id("id_f-format")).select_by_visible_text( + Select(self.driver.find_element(By.ID, "id_f-format")).select_by_visible_text( format_ ) - Select(self.driver.find_element_by_id("id_f-command")).select_by_visible_text( + Select(self.driver.find_element(By.ID, "id_f-command")).select_by_visible_text( command_description ) - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() logger.info("Created the needed FPR rule.") def fpr_rule_already_exists(self, purpose, format_, command_description): @@ -202,7 +203,7 @@ def fpr_rule_already_exists(self, purpose, format_, command_description): """ self.navigate(self.get_rules_url()) self.search_for_fpr_rule(purpose, format_, command_description) - info_el = self.driver.find_element_by_id("DataTables_Table_0_info") + info_el = self.driver.find_element(By.ID, "DataTables_Table_0_info") if info_el.text.strip().startswith("Showing 0 to 0 of 0 entries"): return False return True @@ -221,15 +222,15 @@ def ensure_fpr_rule_enabled(self, purpose, format_, command_description): self.navigate(self.get_rules_url()) self.search_for_fpr_rule(purpose, format_, command_description) self.wait_for_presence("#DataTables_Table_0_info") - info_el = self.driver.find_element_by_id("DataTables_Table_0_info") + info_el = self.driver.find_element(By.ID, "DataTables_Table_0_info") if info_el.text.strip().startswith("Showing 0 to 0 of 0 entries"): return disabled_rules = [ row - for row in self.driver.find_elements_by_css_selector( - "#DataTables_Table_0 tbody tr" + for row in self.driver.find_elements( + By.CSS_SELECTOR, "#DataTables_Table_0 tbody tr" ) - if row.find_element_by_css_selector("td:nth-child(5)").text == "No" + if row.find_element(By.CSS_SELECTOR, "td:nth-child(5)").text == "No" ] if not disabled_rules: logger.info( @@ -246,8 +247,8 @@ def ensure_fpr_rule_enabled(self, purpose, format_, command_description): ) ) rule = disabled_rules[0] - rule.find_element_by_css_selector("td:nth-child(6) a:nth-child(3)").click() - self.driver.find_element_by_css_selector("input[value=Enable]").click() + rule.find_element(By.CSS_SELECTOR, "td:nth-child(6) a:nth-child(3)").click() + self.driver.find_element(By.CSS_SELECTOR, "input[value=Enable]").click() @staticmethod def get_policy_command_description(policy_file): diff --git a/amuser/am_browser_ss_ability.py b/amuser/am_browser_ss_ability.py index bc35d73..a8ad4e6 100644 --- a/amuser/am_browser_ss_ability.py +++ b/amuser/am_browser_ss_ability.py @@ -4,6 +4,7 @@ import time from selenium.common.exceptions import NoSuchElementException +from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from . import base @@ -31,24 +32,24 @@ def approve_aip_delete_request(self, aip_uuid): SS GUI. """ self.navigate(self.get_ss_package_delete_request_url()) - self.driver.find_element_by_id( - "DataTables_Table_0_filter" - ).find_element_by_tag_name("input").send_keys(aip_uuid) + self.driver.find_element(By.ID, "DataTables_Table_0_filter").find_element( + By.TAG_NAME, "input" + ).send_keys(aip_uuid) matching_rows = [] - for row_el in self.driver.find_elements_by_css_selector( - "table#DataTables_Table_0 tbody tr" + for row_el in self.driver.find_elements( + By.CSS_SELECTOR, "table#DataTables_Table_0 tbody tr" ): - if len(row_el.find_elements_by_tag_name("td")) == 7: + if len(row_el.find_elements(By.TAG_NAME, "td")) == 7: matching_rows.append(row_el) if len(matching_rows) != 1: raise ArchivematicaBrowserStorageServiceAbilityError( "More than one delete request row {} matches AIP" " {}".format(len(matching_rows), aip_uuid) ) - matching_rows[0].find_element_by_tag_name("textarea").send_keys("Cuz wanna") - matching_rows[0].find_element_by_css_selector('input[name="approve"]').click() - assert self.driver.find_element_by_css_selector( - "div.alert-success" + matching_rows[0].find_element(By.TAG_NAME, "textarea").send_keys("Cuz wanna") + matching_rows[0].find_element(By.CSS_SELECTOR, 'input[name="approve"]').click() + assert self.driver.find_element( + By.CSS_SELECTOR, "div.alert-success" ).text.strip() == ("Request approved: Package deleted successfully.") def search_for_aip_in_storage_service(self, aip_uuid): @@ -59,21 +60,23 @@ def search_for_aip_in_storage_service(self, aip_uuid): attempts = 0 self.navigate(self.get_packages_url()) self.wait_for_presence('#DataTables_Table_0_filter input[type="text"]') - self.driver.find_element_by_css_selector("input[type=text]").send_keys(aip_uuid) + self.driver.find_element(By.CSS_SELECTOR, "input[type=text]").send_keys( + aip_uuid + ) while True: # DataTables_Table_0 - row_els = self.driver.find_elements_by_css_selector( - "#DataTables_Table_0 tr" + row_els = self.driver.find_elements( + By.CSS_SELECTOR, "#DataTables_Table_0 tr" ) result = [] header = row_els[0] keys = [ th_el.text.strip().lower().replace(" ", "_") - for th_el in header.find_elements_by_tag_name("th") + for th_el in header.find_elements(By.TAG_NAME, "th") ] for row_el in row_els[1:]: row_dict = {} - for index, td_el in enumerate(row_el.find_elements_by_tag_name("td")): + for index, td_el in enumerate(row_el.find_elements(By.TAG_NAME, "td")): row_dict[keys[index]] = td_el.text.strip() result.append(row_dict) # check if rows have been retrieved from the server yet @@ -122,30 +125,30 @@ def create_ss_space(self, attributes): # Visiting this URL creates a default GPG key when there is none self.navigate(self.get_gpg_keys_url()) self.navigate(self.get_spaces_create_url()) - form_el = self.driver.find_element_by_css_selector( - 'form[action="/spaces/create/"]' + form_el = self.driver.find_element( + By.CSS_SELECTOR, 'form[action="/spaces/create/"]' ) - protocol_el = self.driver.find_element_by_id("protocol_form") + protocol_el = self.driver.find_element(By.ID, "protocol_form") for parent in (form_el, protocol_el): - for p_el in parent.find_elements_by_tag_name("p"): - for el in p_el.find_elements_by_css_selector("*"): + for p_el in parent.find_elements(By.TAG_NAME, "p"): + for el in p_el.find_elements(By.CSS_SELECTOR, "*"): if el.tag_name == "label": label_text = el.text.strip().lower().replace(":", "") for key, val in attributes.items(): if key.lower() == label_text: input_id = el.get_attribute("for") - input_el = self.driver.find_element_by_id(input_id) + input_el = self.driver.find_element(By.ID, input_id) if input_el.tag_name == "select": Select(input_el).select_by_visible_text(val) else: input_el.send_keys(val) - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() self.wait_for_presence("div.alert-success", self.nihilistic_wait) assert ( - self.driver.find_element_by_css_selector("div.alert-success").text.strip() + self.driver.find_element(By.CSS_SELECTOR, "div.alert-success").text.strip() == "Space saved." ) - header = self.driver.find_element_by_tag_name("h1").text.strip() + header = self.driver.find_element(By.TAG_NAME, "h1").text.strip() space_uuid = header.split()[0].replace('"', "").replace(":", "") return space_uuid @@ -154,17 +157,17 @@ def create_ss_location(self, space_uuid, attributes): attributes ``attributes``. """ self.navigate(self.get_locations_create_url(space_uuid)) - form_el = self.driver.find_element_by_css_selector( - f'form[action="/spaces/{space_uuid}/location_create/"]' + form_el = self.driver.find_element( + By.CSS_SELECTOR, f'form[action="/spaces/{space_uuid}/location_create/"]' ) - for p_el in form_el.find_elements_by_tag_name("p"): - for el in p_el.find_elements_by_css_selector("*"): + for p_el in form_el.find_elements(By.TAG_NAME, "p"): + for el in p_el.find_elements(By.CSS_SELECTOR, "*"): if el.tag_name == "label": label_text = el.text.strip().lower().replace(":", "") for key, val in attributes.items(): if key.lower() == label_text: input_id = el.get_attribute("for") - input_el = self.driver.find_element_by_id(input_id) + input_el = self.driver.find_element(By.ID, input_id) if input_el.tag_name == "select": Select(input_el).select_by_visible_text(val) else: @@ -175,11 +178,11 @@ def create_ss_location(self, space_uuid, attributes): # be changed for setups with multiple pipelines. if label_text == "pipeline": input_id = el.get_attribute("for") - select_el = self.driver.find_element_by_id(input_id) + select_el = self.driver.find_element(By.ID, input_id) select = Select(select_el) select.select_by_index(0) - self.driver.find_element_by_css_selector("input[type=submit]").click() - header = self.driver.find_element_by_tag_name("h1").text.strip() + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() + header = self.driver.find_element(By.TAG_NAME, "h1").text.strip() location_uuid = header.split()[0].replace('"', "").replace(":", "") return location_uuid @@ -190,9 +193,9 @@ def get_existing_spaces(self): existing_spaces = [] self.navigate(self.get_spaces_url()) space_urls = [] - for div_el in self.driver.find_elements_by_css_selector("div.space"): - space_detail_anchor = div_el.find_element_by_xpath( - 'dl/dd/ul/li/a[text() = "View Details and Locations"]' + for div_el in self.driver.find_elements(By.CSS_SELECTOR, "div.space"): + space_detail_anchor = div_el.find_element( + By.XPATH, 'dl/dd/ul/li/a[text() = "View Details and Locations"]' ) space_urls.append(space_detail_anchor.get_attribute("href")) for space_url in space_urls: @@ -202,9 +205,9 @@ def get_existing_spaces(self): space_uuid = space_uuid[:-1] space_uuid = space_uuid.split("/")[-1] space = {"uuid": space_uuid} - space_div_el = self.driver.find_element_by_css_selector("div.space dl") + space_div_el = self.driver.find_element(By.CSS_SELECTOR, "div.space dl") last_key = None - for el in space_div_el.find_elements_by_css_selector("dt, dd"): + for el in space_div_el.find_elements(By.CSS_SELECTOR, "dt, dd"): text = el.text.strip() if el.tag_name == "dt": last_key = text.lower() @@ -220,16 +223,16 @@ def get_existing_locations(self, space_uuid): existing_locations = [] self.navigate(self.get_space_url(space_uuid)) location_urls = {} - for tr_el in self.driver.find_elements_by_css_selector("tbody tr"): - loc_uuid_td_el = tr_el.find_element_by_xpath("td[position()=5]") + for tr_el in self.driver.find_elements(By.CSS_SELECTOR, "tbody tr"): + loc_uuid_td_el = tr_el.find_element(By.XPATH, "td[position()=5]") loc_uuid = loc_uuid_td_el.text.strip() location_urls[loc_uuid] = self.get_location_url(loc_uuid) for loc_uuid, loc_url in location_urls.items(): self.navigate(loc_url) location = {"uuid": loc_uuid} - loc_div_el = self.driver.find_element_by_css_selector("div.location dl") + loc_div_el = self.driver.find_element(By.CSS_SELECTOR, "div.location dl") last_key = None - for el in loc_div_el.find_elements_by_css_selector("dt, dd"): + for el in loc_div_el.find_elements(By.CSS_SELECTOR, "dt, dd"): text = el.text.strip() if el.tag_name == "dt": last_key = text.lower() @@ -268,10 +271,10 @@ def add_replicator_to_default_aip_stor_loc(self, replicator_location_uuid): standard Archivematica Directory" is THE default AIP Storage location. """ self.navigate(self.get_locations_url()) - search_el = self.driver.find_element_by_css_selector("input[type=text]") + search_el = self.driver.find_element(By.CSS_SELECTOR, "input[type=text]") search_el.send_keys("Store AIP in standard Archivematica Directory") - row_els = self.driver.find_elements_by_css_selector( - "#DataTables_Table_0 > tbody > tr" + row_els = self.driver.find_elements( + By.CSS_SELECTOR, "#DataTables_Table_0 > tbody > tr" ) if not row_els: raise ArchivematicaBrowserStorageServiceAbilityError( @@ -281,7 +284,7 @@ def add_replicator_to_default_aip_stor_loc(self, replicator_location_uuid): new_row_els = [] for row_el in row_els: row_text = [] - for td_el in row_el.find_elements_by_css_selector("td"): + for td_el in row_el.find_elements(By.CSS_SELECTOR, "td"): row_text.append(td_el.text.strip().lower()) if "encrypted" not in "".join(row_text): new_row_els.append(row_el) @@ -291,9 +294,9 @@ def add_replicator_to_default_aip_stor_loc(self, replicator_location_uuid): raise ArchivematicaBrowserStorageServiceAbilityError( "Unable to find a unique default AIP storage location" ) - cell_el = row_els[0].find_elements_by_css_selector("td")[9] + cell_el = row_els[0].find_elements(By.CSS_SELECTOR, "td")[9] edit_a_el = None - for a_el in cell_el.find_elements_by_css_selector("a"): + for a_el in cell_el.find_elements(By.CSS_SELECTOR, "a"): if a_el.text.strip() == "Edit": edit_a_el = a_el if not edit_a_el: @@ -303,8 +306,8 @@ def add_replicator_to_default_aip_stor_loc(self, replicator_location_uuid): ) edit_a_el.click() self.wait_for_presence("select#id_replicators") - replicators_select_el = self.driver.find_element_by_css_selector( - "select#id_replicators" + replicators_select_el = self.driver.find_element( + By.CSS_SELECTOR, "select#id_replicators" ) replicators_select = Select(replicators_select_el) found_replicator = False @@ -319,7 +322,7 @@ def add_replicator_to_default_aip_stor_loc(self, replicator_location_uuid): " for the default AIP Storage" " location".format(replicator_location_uuid) ) - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() def import_gpg_key(self, key_path): """Navigate to the GPG key import page and attempt to import the GPG @@ -329,10 +332,10 @@ def import_gpg_key(self, key_path): """ self.navigate(self.get_import_gpg_key_url()) with open(key_path) as filei: - self.driver.find_element_by_id("id_ascii_armor").send_keys(filei.read()) - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.ID, "id_ascii_armor").send_keys(filei.read()) + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() self.wait_for_presence("div.alert", 20) - return self.driver.find_element_by_css_selector("div.alert").text.strip() + return self.driver.find_element(By.CSS_SELECTOR, "div.alert").text.strip() def get_gpg_key_search_matches(self, search_string): """Navigate to the GPG keys page and return the fingerprints of all @@ -340,15 +343,15 @@ def get_gpg_key_search_matches(self, search_string): """ fingerprints = [] self.navigate(self.get_gpg_keys_url()) - self.driver.find_element_by_css_selector("input[type=text]").send_keys( + self.driver.find_element(By.CSS_SELECTOR, "input[type=text]").send_keys( search_string ) - for row_el in self.driver.find_elements_by_css_selector( - "table#DataTables_Table_0 tbody tr" + for row_el in self.driver.find_elements( + By.CSS_SELECTOR, "table#DataTables_Table_0 tbody tr" ): try: fingerprints.append( - row_el.find_elements_by_tag_name("td")[1].text.strip() + row_el.find_elements(By.TAG_NAME, "td")[1].text.strip() ) except IndexError: pass @@ -361,9 +364,11 @@ def delete_gpg_key(self, key_name): string. """ self.navigate(self.get_gpg_keys_url()) - self.driver.find_element_by_css_selector("input[type=text]").send_keys(key_name) - matches = self.driver.find_elements_by_css_selector( - "table#DataTables_Table_0 tbody tr" + self.driver.find_element(By.CSS_SELECTOR, "input[type=text]").send_keys( + key_name + ) + matches = self.driver.find_elements( + By.CSS_SELECTOR, "table#DataTables_Table_0 tbody tr" ) try: assert len(matches) == 1 @@ -376,14 +381,14 @@ def delete_gpg_key(self, key_name): ) raise else: - matches[0].find_element_by_xpath('td[3]/a[text() = "Delete"]').click() + matches[0].find_element(By.XPATH, 'td[3]/a[text() = "Delete"]').click() try: - self.driver.find_element_by_css_selector("input[value=Delete]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[value=Delete]").click() try: return ( True, - self.driver.find_element_by_css_selector( - "div.alert-success" + self.driver.find_element( + By.CSS_SELECTOR, "div.alert-success" ).text.strip(), ) except NoSuchElementException: @@ -391,25 +396,25 @@ def delete_gpg_key(self, key_name): except NoSuchElementException: return ( False, - self.driver.find_element_by_css_selector( - "div.alert-error" + self.driver.find_element( + By.CSS_SELECTOR, "div.alert-error" ).text.strip(), ) def disable_default_transfer_backlog(self): self.navigate(self.get_locations_url()) - search_el = self.driver.find_element_by_css_selector("input[type=text]") + search_el = self.driver.find_element(By.CSS_SELECTOR, "input[type=text]") search_el.send_keys("Default transfer backlog") - row_els = self.driver.find_elements_by_css_selector( - "#DataTables_Table_0 > tbody > tr" + row_els = self.driver.find_elements( + By.CSS_SELECTOR, "#DataTables_Table_0 > tbody > tr" ) if len(row_els) != 1: raise ArchivematicaBrowserStorageServiceAbilityError( "Unable to find a unique default transfer backlog location" ) - cell_el = row_els[0].find_elements_by_css_selector("td")[9] + cell_el = row_els[0].find_elements(By.CSS_SELECTOR, "td")[9] disable_a_el = enable_a_el = None - for a_el in cell_el.find_elements_by_css_selector("a"): + for a_el in cell_el.find_elements(By.CSS_SELECTOR, "a"): if a_el.text.strip() == "Disable": disable_a_el = a_el if a_el.text.strip() == "Enable": @@ -427,11 +432,11 @@ def create_new_gpg_key(self): self.navigate(self.get_create_gpg_key_url()) new_key_name = f"GPGKey {utils.unixtimestamp()}" new_key_email = "{}@example.com".format(new_key_name.lower().replace(" ", "")) - self.driver.find_element_by_id("id_name_real").send_keys(new_key_name) - self.driver.find_element_by_id("id_name_email").send_keys(new_key_email) - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.ID, "id_name_real").send_keys(new_key_name) + self.driver.find_element(By.ID, "id_name_email").send_keys(new_key_email) + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() self.wait_for_presence("div.alert-success", self.nihilistic_wait) - alert_text = self.driver.find_element_by_css_selector("div.alert-success").text + alert_text = self.driver.find_element(By.CSS_SELECTOR, "div.alert-success").text new_key_fingerprint = alert_text.split()[2] return new_key_name, new_key_email, new_key_fingerprint @@ -441,7 +446,7 @@ def change_encrypted_space_key(self, space_uuid, new_key_repr=None): any other key. """ self.navigate(self.get_space_edit_url(space_uuid)) - select = Select(self.driver.find_element_by_id("id_protocol-key")) + select = Select(self.driver.find_element(By.ID, "id_protocol-key")) if new_key_repr: select.select_by_visible_text(new_key_repr) else: @@ -450,10 +455,10 @@ def change_encrypted_space_key(self, space_uuid, new_key_repr=None): if option.text != currently_selected: select.select_by_visible_text(option.text) break - self.driver.find_element_by_css_selector("input[type=submit]").click() + self.driver.find_element(By.CSS_SELECTOR, "input[type=submit]").click() # Nihilistic wait is the only value working on Docker at present... and # may still need to be longer. Wait needed to accumulate GPG entropy. self.wait_for_presence("div.alert-success", self.nihilistic_wait) - assert self.driver.find_element_by_css_selector( - "div.alert-success" + assert self.driver.find_element( + By.CSS_SELECTOR, "div.alert-success" ).text.strip() == ("Space saved.") diff --git a/amuser/am_browser_transfer_ability.py b/amuser/am_browser_transfer_ability.py index 8f348dc..294526a 100644 --- a/amuser/am_browser_transfer_ability.py +++ b/amuser/am_browser_transfer_ability.py @@ -5,6 +5,7 @@ from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import StaleElementReferenceException +from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from . import constants as c @@ -92,21 +93,23 @@ def remove_top_transfer(self, top_transfer_elem): """Remove the topmost transfer: click on its "Remove" button and click "Confirm". """ - remove_elem = top_transfer_elem.find_element_by_css_selector("a.btn_remove_sip") + remove_elem = top_transfer_elem.find_element( + By.CSS_SELECTOR, "a.btn_remove_sip" + ) if remove_elem: remove_elem.click() dialog_selector = "div.ui-dialog" self.wait_for_presence(dialog_selector) - remove_sip_confirm_dialog_elems = self.driver.find_elements_by_css_selector( - "div.ui-dialog" + remove_sip_confirm_dialog_elems = self.driver.find_elements( + By.CSS_SELECTOR, "div.ui-dialog" ) for dialog_elem in remove_sip_confirm_dialog_elems: if dialog_elem.is_displayed(): remove_sip_confirm_dialog_elem = dialog_elem break - for ( - button_elem - ) in remove_sip_confirm_dialog_elem.find_elements_by_css_selector("button"): + for button_elem in remove_sip_confirm_dialog_elem.find_elements( + By.CSS_SELECTOR, "button" + ): if button_elem.text.strip() == "Confirm": button_elem.click() self.wait_for_invisibility(dialog_selector) @@ -118,8 +121,8 @@ def remove_top_transfer(self, top_transfer_elem): def get_top_transfer(self): """Get the topmost transfer ('.sip')
in the transfers tab.""" - transfer_elems = self.driver.find_elements_by_css_selector( - c.SELECTOR_TRANSFER_DIV + transfer_elems = self.driver.find_elements( + By.CSS_SELECTOR, c.SELECTOR_TRANSFER_DIV ) if transfer_elems: return transfer_elems[0] @@ -137,14 +140,14 @@ def wait_for_transfer_to_appear(self, transfer_name, name_is_prefix=False): transfer_uuid_div_selector = "div.sip-detail-uuid" self.wait_for_presence(transfer_name_div_selector) transfer_uuid = correct_transfer_div_elem = None - for transfer_div_elem in self.driver.find_elements_by_css_selector( - c.SELECTOR_TRANSFER_DIV + for transfer_div_elem in self.driver.find_elements( + By.CSS_SELECTOR, c.SELECTOR_TRANSFER_DIV ): - transfer_name_div_elem = transfer_div_elem.find_element_by_css_selector( - transfer_name_div_selector + transfer_name_div_elem = transfer_div_elem.find_element( + By.CSS_SELECTOR, transfer_name_div_selector ) - transfer_uuid_div_elem = transfer_div_elem.find_element_by_css_selector( - transfer_uuid_div_selector + transfer_uuid_div_elem = transfer_div_elem.find_element( + By.CSS_SELECTOR, transfer_uuid_div_selector ) # Identify the transfer by its name. The complication here is that # AM detects a narrow browser window and hides the UUID in the @@ -164,7 +167,7 @@ def wait_for_transfer_to_appear(self, transfer_name, name_is_prefix=False): transfer_name_in_dom, ) transfer_name = transfer_name_in_dom - abbr_elem = transfer_name_div_elem.find_element_by_tag_name("abbr") + abbr_elem = transfer_name_div_elem.find_element(By.TAG_NAME, "abbr") if abbr_elem and abbr_elem.is_displayed(): transfer_uuid = abbr_elem.get_attribute("title").strip() else: @@ -191,8 +194,8 @@ def wait_for_transfer_to_appear(self, transfer_name, name_is_prefix=False): return transfer_uuid, correct_transfer_div_elem, transfer_name def click_start_transfer_button(self): - start_transfer_button_elem = self.driver.find_element_by_css_selector( - c.SELECTOR_BUTTON_START_TRANSFER + start_transfer_button_elem = self.driver.find_element( + By.CSS_SELECTOR, c.SELECTOR_BUTTON_START_TRANSFER ) start_transfer_button_elem.click() @@ -209,30 +212,30 @@ def navigate_to_transfer_tab(self): def enter_transfer_name(self, transfer_name): """Enter a transfer name into the text input.""" - # transfer_name_elem = self.driver.find_element_by_id('transfer-name') - transfer_name_elem = self.driver.find_element_by_css_selector( - c.SELECTOR_INPUT_TRANSFER_NAME + # transfer_name_elem = self.driver.find_element(By.ID, 'transfer-name') + transfer_name_elem = self.driver.find_element( + By.CSS_SELECTOR, c.SELECTOR_INPUT_TRANSFER_NAME ) transfer_name_elem.send_keys(transfer_name) def set_transfer_type(self, transfer_type): """Select transfer type ``transfer_type`` in the