summaryrefslogtreecommitdiff
path: root/test/unit/test_popup.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-31 18:06:13 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-31 18:06:13 +0100
commitad69f9c86b950cc84ca103e65824b9c9129d3999 (patch)
treea4314c8a5031b9fb2a278021b2388b86190c2823 /test/unit/test_popup.py
parent4c6a2323d90e9321ec2b78e226167b3013ea69ab (diff)
downloadbrowser-extension-ad69f9c86b950cc84ca103e65824b9c9129d3999.tar.gz
browser-extension-ad69f9c86b950cc84ca103e65824b9c9129d3999.zip
add support for testing with other browsers (especially Abrowser and Librewolf)
There are still some spurious failures when running under those newer browsers. Those will be systematically investigated and fixed.
Diffstat (limited to 'test/unit/test_popup.py')
-rw-r--r--test/unit/test_popup.py32
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()