diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/test_patterns_query_manager.py | 13 | ||||
-rw-r--r-- | test/unit/test_popup.py | 50 |
2 files changed, 21 insertions, 42 deletions
diff --git a/test/unit/test_patterns_query_manager.py b/test/unit/test_patterns_query_manager.py index 4662e8a..13d0add 100644 --- a/test/unit/test_patterns_query_manager.py +++ b/test/unit/test_patterns_query_manager.py @@ -265,7 +265,7 @@ def test_pqm_script_injection(driver, execute_in_page): json_txt = run_content_script() if json_txt and json.loads(json_txt) == {}: break; - assert attempt != 2 + assert attempt != 1 driver.switch_to.window(windows[0]) execute_in_page(load_script('common/indexeddb.js')) @@ -283,7 +283,7 @@ def test_pqm_script_injection(driver, execute_in_page): json.loads(tree_json) if all([m['identifier'] in tree_json for m in sample_mappings]): break - assert attempt != 2 + assert attempt != 1 driver.switch_to.window(windows[0]) execute_in_page( @@ -300,7 +300,8 @@ def test_pqm_script_injection(driver, execute_in_page): }''', [sm['identifier'] for sm in sample_mappings]) - for attempt in range(10): - if json.loads(run_content_script()) == {}: - break - assert attempt != 9 + for attempt in range(2): + json_txt = run_content_script() + if json_txt and json.loads(json_txt) == {}: + break; + assert attempt != 1 diff --git a/test/unit/test_popup.py b/test/unit/test_popup.py index da125ec..3163adb 100644 --- a/test/unit/test_popup.py +++ b/test/unit/test_popup.py @@ -20,21 +20,11 @@ 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 from .utils import * -def reload_with_target(driver, target): - current_url = driver.execute_script('return location.href') - driver.execute_script( - ''' - window.location.href = arguments[0]; - window.location.reload(); - ''', - f'{current_url}#{target}') - unprivileged_page_info = { 'url': 'https://example_a.com/something', 'allow': False @@ -145,18 +135,16 @@ def test_popup_display(driver, execute_in_page, page_info_key): possible values of page_info object passed in message from the content script. """ - reload_with_target(driver, f'mock_page_info-{page_info_key}') + initial_url = driver.current_url + driver.get('about:blank') + driver.get(f'{initial_url}#mock_page_info-{page_info_key}') - 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) + by_id = driver.execute_script( + ''' + const nodes = [...document.querySelectorAll("[id]")]; + const reductor = (ob, node) => Object.assign(ob, {[node.id]: node}); + return nodes.reduce(reductor, {}); + ''') if page_info_key == '': error_msg = 'Page info not avaialable. Try reloading the page.' @@ -218,23 +206,13 @@ def test_popup_repo_query(driver, execute_in_page): """ Test opening and closing the repo query view in popup. """ - reload_with_target(driver, f'mock_page_info-blocked_rule') + initial_url = driver.current_url + driver.get('about:blank') + driver.get(f'{initial_url}#mock_page_info-blocked_rule') - driver.implicitly_wait(10) search_but = driver.find_element_by_id("search_resources_but") - 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) + WebDriverWait(driver, 10).until(lambda d: search_but.is_displayed()) + search_but.click() containers = dict([(name, driver.find_element_by_id(f'{name}_container')) for name in ('page_info', 'repo_query')]) |