aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-15 14:22:09 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-15 14:22:09 +0100
commit5ed09841865eb0c309f1501c6de15fc454478db7 (patch)
tree256c04d3680245a3a1e67ceedda30339568eeddb /test
parent92fc67cfa135526cef75311c3ee1a14e248c3060 (diff)
downloadbrowser-extension-5ed09841865eb0c309f1501c6de15fc454478db7.tar.gz
browser-extension-5ed09841865eb0c309f1501c6de15fc454478db7.zip
fix loading initial data and verify it in automated tests
Diffstat (limited to 'test')
-rw-r--r--test/test_integration.py51
-rw-r--r--test/unit/test_indexeddb.py10
2 files changed, 54 insertions, 7 deletions
diff --git a/test/test_integration.py b/test/test_integration.py
index db5ae43..8d8d08d 100644
--- a/test/test_integration.py
+++ b/test/test_integration.py
@@ -18,12 +18,55 @@ Haketilo integration tests
# CC0 1.0 Universal License for more details.
import pytest
+import re
+
from selenium.webdriver.support.ui import WebDriverWait
+from selenium.common.exceptions import NoSuchElementException
+
+extract_base_url_re = re.compile(r'^(.*)manifest.json$')
+
+def get_extension_base_url(driver):
+ """
+ Extension's internall UUID is not directly exposed in Selenium. Instead, we
+ can navigate to about:debugging and inspect the manifest URL present there
+ to get the base url like:
+ moz-extension://b225c78f-d108-4caa-8406-f38b37d8dee5/
+ which can then be used to navigate to extension-bundled pages.
+ """
+ driver.implicitly_wait(10)
+ try:
+ # For newer Firefoxes
+ driver.get('about:debugging#/runtime/this-firefox')
+ manifest_link = driver.find_element_by_class_name('qa-manifest-url')
+ except NoSuchElementException:
+ driver.get("about:debugging#addons")
+ manifest_link = driver.find_element_by_class_name('manifest-url')
+ driver.implicitly_wait(0)
+
+ manifest_url = manifest_link.get_attribute('href')
+ return extract_base_url_re.match(manifest_url).group(1)
@pytest.mark.usefixtures('haketilo')
def test_integration(driver):
- #from time import sleep
- #sleep(100000)
+ """
+ Verify that the entire extension functions properly. Also verify bunlded
+ default settings get loaded properly.
+ """
+ base_url = get_extension_base_url(driver)
+ driver.get(base_url + 'html/settings.html')
+
+ for tab_head_id, item_text in [
+ ('resources_head', 'Haketilo demonstrational script'),
+ ('mappings_head', 'Haketilo demonstrational message'),
+ ]:
+ driver.find_element_by_id(tab_head_id).click()
+ lst = driver.find_element_by_css_selector('.active_tab .item_list')
+ assert lst.is_displayed()
+ assert item_text in lst.text
+
+ driver.find_element_by_id('repos_head').click()
+ lst = driver.find_element_by_css_selector('.active_tab .text_entries')
+ assert 'https://hydrilla.koszko.org/api_v1' in lst.text
- # TODO!!!
- pass
+ # TODO: do some more tests, including popup interaction and repository
+ # querying
diff --git a/test/unit/test_indexeddb.py b/test/unit/test_indexeddb.py
index 9f31480..c2d5427 100644
--- a/test/unit/test_indexeddb.py
+++ b/test/unit/test_indexeddb.py
@@ -429,11 +429,14 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text):
},
'file': {
'sha256': sample_files_by_sha256
- }
+ },
+ 'repo': [
+ 'https://hydril2.la/'
+ ]
}
execute_in_page('returnval(save_items(arguments[0]));', sample_data)
execute_in_page('returnval(set_setting("option22", "abc"));')
- execute_in_page('returnval(set_repo("https://hydril2.la"));')
+ execute_in_page('returnval(set_repo("https://hydril3.la/"));')
execute_in_page('returnval(set_allowed("ftp://a.bc/"));')
driver.switch_to.window(windows[0])
@@ -442,7 +445,8 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text):
('resource_helloapple-copy', sample_resource2),
('mapping_helloapple-copy', sample_mapping2),
('setting_option22', {'name': 'option22', 'value': 'abc'}),
- ('repo_https://hydril2.la', {'url': 'https://hydril2.la'}),
+ ('repo_https://hydril2.la/', {'url': 'https://hydril2.la/'}),
+ ('repo_https://hydril3.la/', {'url': 'https://hydril3.la/'}),
('blocking_ftp://a.bc/', {'pattern': 'ftp://a.bc/', 'allow': True})
]:
assert json.loads(driver.find_element_by_id(elem_id).text) == json_value