1
|
# SPDX-License-Identifier: CC0-1.0
|
2
|
|
3
|
"""
|
4
|
Haketilo integration tests
|
5
|
"""
|
6
|
|
7
|
# This file is part of Haketilo
|
8
|
#
|
9
|
# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
|
10
|
#
|
11
|
# This program is free software: you can redistribute it and/or modify
|
12
|
# it under the terms of the CC0 1.0 Universal License as published by
|
13
|
# the Creative Commons Corporation.
|
14
|
#
|
15
|
# This program is distributed in the hope that it will be useful,
|
16
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
# CC0 1.0 Universal License for more details.
|
19
|
|
20
|
import pytest
|
21
|
import re
|
22
|
|
23
|
from selenium.webdriver.support.ui import WebDriverWait
|
24
|
from selenium.common.exceptions import NoSuchElementException
|
25
|
|
26
|
extract_base_url_re = re.compile(r'^(.*)manifest.json$')
|
27
|
|
28
|
def get_extension_base_url(driver):
|
29
|
"""
|
30
|
Extension's internall UUID is not directly exposed in Selenium. Instead, we
|
31
|
can navigate to about:debugging and inspect the manifest URL present there
|
32
|
to get the base url like:
|
33
|
moz-extension://b225c78f-d108-4caa-8406-f38b37d8dee5/
|
34
|
which can then be used to navigate to extension-bundled pages.
|
35
|
"""
|
36
|
driver.implicitly_wait(10)
|
37
|
try:
|
38
|
# For newer Firefoxes
|
39
|
driver.get('about:debugging#/runtime/this-firefox')
|
40
|
manifest_link = driver.find_element_by_class_name('qa-manifest-url')
|
41
|
except NoSuchElementException:
|
42
|
driver.get("about:debugging#addons")
|
43
|
manifest_link = driver.find_element_by_class_name('manifest-url')
|
44
|
driver.implicitly_wait(0)
|
45
|
|
46
|
manifest_url = manifest_link.get_attribute('href')
|
47
|
return extract_base_url_re.match(manifest_url).group(1)
|
48
|
|
49
|
@pytest.mark.usefixtures('haketilo')
|
50
|
def test_integration(driver):
|
51
|
"""
|
52
|
Verify that the entire extension functions properly. Also verify bunlded
|
53
|
default settings get loaded properly.
|
54
|
"""
|
55
|
base_url = get_extension_base_url(driver)
|
56
|
driver.get(base_url + 'html/settings.html')
|
57
|
|
58
|
for tab_head_id, item_text in [
|
59
|
('resources_head', 'Haketilo demonstrational script'),
|
60
|
('mappings_head', 'Haketilo demonstrational message'),
|
61
|
]:
|
62
|
driver.find_element_by_id(tab_head_id).click()
|
63
|
lst = driver.find_element_by_css_selector('.active_tab .item_list')
|
64
|
assert lst.is_displayed()
|
65
|
assert item_text in lst.text
|
66
|
|
67
|
driver.find_element_by_id('repos_head').click()
|
68
|
lst = driver.find_element_by_css_selector('.active_tab .text_entries')
|
69
|
assert 'https://hydrilla.koszko.org/api_v1' in lst.text
|
70
|
|
71
|
# TODO: do some more tests, including popup interaction and repository
|
72
|
# querying
|