Revision 26e4800d
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 |
|
24 | 23 |
|
25 | 24 |
from ..extension_crafting import ExtraHTML |
26 | 25 |
from ..script_loader import load_script |
27 | 26 |
from .utils import * |
28 | 27 |
|
29 |
def reload_with_target(driver, target): |
|
30 |
current_url = driver.execute_script('return location.href') |
|
31 |
driver.execute_script( |
|
32 |
''' |
|
33 |
window.location.href = arguments[0]; |
|
34 |
window.location.reload(); |
|
35 |
''', |
|
36 |
f'{current_url}#{target}') |
|
37 |
|
|
38 | 28 |
unprivileged_page_info = { |
39 | 29 |
'url': 'https://example_a.com/something', |
40 | 30 |
'allow': False |
... | ... | |
145 | 135 |
possible values of page_info object passed in message from the content |
146 | 136 |
script. |
147 | 137 |
""" |
148 |
reload_with_target(driver, f'mock_page_info-{page_info_key}') |
|
138 |
initial_url = driver.current_url |
|
139 |
driver.get('about:blank') |
|
140 |
driver.get(f'{initial_url}#mock_page_info-{page_info_key}') |
|
149 | 141 |
|
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) |
|
142 |
by_id = driver.execute_script( |
|
143 |
''' |
|
144 |
const nodes = [...document.querySelectorAll("[id]")]; |
|
145 |
const reductor = (ob, node) => Object.assign(ob, {[node.id]: node}); |
|
146 |
return nodes.reduce(reductor, {}); |
|
147 |
''') |
|
160 | 148 |
|
161 | 149 |
if page_info_key == '': |
162 | 150 |
error_msg = 'Page info not avaialable. Try reloading the page.' |
... | ... | |
218 | 206 |
""" |
219 | 207 |
Test opening and closing the repo query view in popup. |
220 | 208 |
""" |
221 |
reload_with_target(driver, f'mock_page_info-blocked_rule') |
|
209 |
initial_url = driver.current_url |
|
210 |
driver.get('about:blank') |
|
211 |
driver.get(f'{initial_url}#mock_page_info-blocked_rule') |
|
222 | 212 |
|
223 |
driver.implicitly_wait(10) |
|
224 | 213 |
search_but = driver.find_element_by_id("search_resources_but") |
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) |
|
214 |
WebDriverWait(driver, 10).until(lambda d: search_but.is_displayed()) |
|
215 |
search_but.click() |
|
238 | 216 |
|
239 | 217 |
containers = dict([(name, driver.find_element_by_id(f'{name}_container')) |
240 | 218 |
for name in ('page_info', 'repo_query')]) |
Also available in: Unified diff
more improvements for abrowser&librewolf