aboutsummaryrefslogtreecommitdiff
path: root/test/test_integration.py
blob: 8d8d08de8fbe08d5b510f20a046e2cfb3500087b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# SPDX-License-Identifier: CC0-1.0

"""
Haketilo integration tests
"""

# This file is part of Haketilo
#
# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
# the Creative Commons Corporation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 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):
    """
    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: do some more tests, including popup interaction and repository
    # querying