aboutsummaryrefslogtreecommitdiff
path: root/test/unit/test_popup.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/test_popup.py')
-rw-r--r--test/unit/test_popup.py50
1 files changed, 14 insertions, 36 deletions
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')])