Revision 463e6830
Added by koszko almost 2 years ago
test/test_unit.py | ||
---|---|---|
19 | 19 |
# CC0 1.0 Universal License for more details. |
20 | 20 |
|
21 | 21 |
import pytest |
22 |
from .profiles import firefox_safe_mode |
|
23 |
from .server import do_an_internet |
|
22 |
from .profiles import firefox_safe_mode |
|
23 |
from .server import do_an_internet |
|
24 |
from .script_loader import load_script |
|
24 | 25 |
|
25 |
@pytest.fixture |
|
26 |
@pytest.fixture(scope="module")
|
|
26 | 27 |
def proxy(): |
27 | 28 |
httpd = do_an_internet() |
28 | 29 |
yield httpd |
29 | 30 |
httpd.shutdown() |
30 | 31 |
|
31 |
@pytest.fixture |
|
32 |
@pytest.fixture(scope="module")
|
|
32 | 33 |
def driver(proxy): |
33 | 34 |
with firefox_safe_mode() as driver: |
34 | 35 |
yield driver |
35 | 36 |
driver.quit() |
36 | 37 |
|
37 |
def test_basic(driver): |
|
38 |
driver.get('https://gotmyowndoma.in') |
|
39 |
element = driver.find_element_by_tag_name('title') |
|
40 |
title = driver.execute_script('return arguments[0].innerText;', element) |
|
41 |
assert "Schrodinger's Document" in title |
|
38 |
def test_proxy(driver): |
|
39 |
""" |
|
40 |
A trivial test case that verifies mocked web pages served by proxy can be |
|
41 |
accessed by the browser driven. |
|
42 |
""" |
|
43 |
for proto in ['http://', 'https://']: |
|
44 |
driver.get(proto + 'gotmyowndoma.in') |
|
45 |
element = driver.find_element_by_tag_name('title') |
|
46 |
title = driver.execute_script('return arguments[0].innerText;', element) |
|
47 |
assert "Schrodinger's Document" in title |
|
48 |
|
|
49 |
def test_script_loader(driver): |
|
50 |
""" |
|
51 |
A trivial test case that verifies Haketilo's .js files can be properly |
|
52 |
loaded into a test page together with their dependencies. |
|
53 |
""" |
|
54 |
driver.get('http://gotmyowndoma.in') |
|
55 |
driver.execute_script(load_script('common/stored_types.js', ['common'])) |
|
56 |
get_var_prefix = 'return window.haketilo_exports.TYPE_PREFIX.VAR;' |
|
57 |
assert driver.execute_script(get_var_prefix) == '_' |
Also available in: Unified diff
facilitate testing javascript functions
Haketilo's .js files can now be loaded together with their dependencies and
executed on a page opened in a selenium-driven Firefox instance.