Revision ad69f9c8
Added by koszko over 1 year ago
test/unit/test_popup.py | ||
---|---|---|
20 | 20 |
import pytest |
21 | 21 |
import json |
22 | 22 |
from selenium.webdriver.support.ui import WebDriverWait |
23 |
from selenium.common.exceptions import ElementNotInteractableException |
|
23 | 24 |
|
24 | 25 |
from ..extension_crafting import ExtraHTML |
25 | 26 |
from ..script_loader import load_script |
... | ... | |
146 | 147 |
""" |
147 | 148 |
reload_with_target(driver, f'mock_page_info-{page_info_key}') |
148 | 149 |
|
149 |
by_id = driver.execute_script(''' |
|
150 |
const nodes = [...document.querySelectorAll("[id]")]; |
|
151 |
return nodes.reduce((ob, node) => Object.assign(ob, {[node.id]: node}), {}); |
|
152 |
'''); |
|
150 |
def get_nodes_by_id(driver): |
|
151 |
by_id = driver.execute_script( |
|
152 |
''' |
|
153 |
const nodes = [...document.querySelectorAll("[id]")]; |
|
154 |
const reductor = (ob, node) => Object.assign(ob, {[node.id]: node}); |
|
155 |
return nodes.reduce(reductor, {}); |
|
156 |
'''); |
|
157 |
return by_id if by_id and 'repo_query_container' in by_id else None |
|
158 |
|
|
159 |
by_id = WebDriverWait(driver, 10).until(get_nodes_by_id) |
|
153 | 160 |
|
154 | 161 |
if page_info_key == '': |
155 | 162 |
error_msg = 'Page info not avaialable. Try reloading the page.' |
... | ... | |
213 | 220 |
""" |
214 | 221 |
reload_with_target(driver, f'mock_page_info-blocked_rule') |
215 | 222 |
|
223 |
driver.implicitly_wait(10) |
|
216 | 224 |
search_but = driver.find_element_by_id("search_resources_but") |
217 |
WebDriverWait(driver, 10).until(lambda d: search_but.is_displayed()) |
|
218 |
search_but.click() |
|
225 |
driver.implicitly_wait(0) |
|
226 |
|
|
227 |
# For unknown reasons waiting for search_but.is_displayed() to return True |
|
228 |
# does not guarantee the button will be interactable afterwards under newer |
|
229 |
# browsers. Hence, this workaround. |
|
230 |
def click_search_but(driver): |
|
231 |
try: |
|
232 |
search_but.click() |
|
233 |
return True |
|
234 |
except ElementNotInteractableException: |
|
235 |
pass |
|
236 |
|
|
237 |
WebDriverWait(driver, 10).until(click_search_but) |
|
238 |
|
|
219 | 239 |
containers = dict([(name, driver.find_element_by_id(f'{name}_container')) |
220 | 240 |
for name in ('page_info', 'repo_query')]) |
221 | 241 |
assert not containers['page_info'].is_displayed() |
Also available in: Unified diff
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.