diff options
Diffstat (limited to 'test/unit/test_popup.py')
-rw-r--r-- | test/unit/test_popup.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/test/unit/test_popup.py b/test/unit/test_popup.py index da1812d..da125ec 100644 --- a/test/unit/test_popup.py +++ b/test/unit/test_popup.py @@ -20,6 +20,7 @@ Haketilo unit tests - repository querying import pytest import json from selenium.webdriver.support.ui import WebDriverWait +from selenium.common.exceptions import ElementNotInteractableException from ..extension_crafting import ExtraHTML from ..script_loader import load_script @@ -146,10 +147,16 @@ def test_popup_display(driver, execute_in_page, page_info_key): """ reload_with_target(driver, f'mock_page_info-{page_info_key}') - by_id = driver.execute_script(''' - const nodes = [...document.querySelectorAll("[id]")]; - return nodes.reduce((ob, node) => Object.assign(ob, {[node.id]: node}), {}); - '''); + def get_nodes_by_id(driver): + by_id = driver.execute_script( + ''' + const nodes = [...document.querySelectorAll("[id]")]; + const reductor = (ob, node) => Object.assign(ob, {[node.id]: node}); + return nodes.reduce(reductor, {}); + '''); + return by_id if by_id and 'repo_query_container' in by_id else None + + by_id = WebDriverWait(driver, 10).until(get_nodes_by_id) if page_info_key == '': error_msg = 'Page info not avaialable. Try reloading the page.' @@ -213,9 +220,22 @@ def test_popup_repo_query(driver, execute_in_page): """ reload_with_target(driver, f'mock_page_info-blocked_rule') + driver.implicitly_wait(10) search_but = driver.find_element_by_id("search_resources_but") - WebDriverWait(driver, 10).until(lambda d: search_but.is_displayed()) - search_but.click() + driver.implicitly_wait(0) + + # For unknown reasons waiting for search_but.is_displayed() to return True + # does not guarantee the button will be interactable afterwards under newer + # browsers. Hence, this workaround. + def click_search_but(driver): + try: + search_but.click() + return True + except ElementNotInteractableException: + pass + + WebDriverWait(driver, 10).until(click_search_but) + containers = dict([(name, driver.find_element_by_id(f'{name}_container')) for name in ('page_info', 'repo_query')]) assert not containers['page_info'].is_displayed() |