Revision ee0a4a93
Added by koszko over 1 year ago
README.md | ||
---|---|---|
59 | 59 |
|
60 | 60 |
### Configuring |
61 | 61 |
|
62 |
*Note: like building, testing can be performed out-of-source.*
|
|
62 |
*Note: like building, testing can be performed out-of-source; this can be useful when testing under multiple browsers simultaneously*
|
|
63 | 63 |
|
64 | 64 |
Running tests requires you to pass some additional information to `configure`. Relevant options are: |
65 | 65 |
|
test/haketilo_test/__main__.py | ||
---|---|---|
40 | 40 |
|
41 | 41 |
def fail(msg, error_code): |
42 | 42 |
print('Error:', msg) |
43 |
print('Usage:', sys.argv[0], '[--load-haketilo]', '[certificates_directory] [proxy_port]')
|
|
43 |
print('Usage:', sys.argv[0], '[--load-haketilo]', '[certificates_directory]') |
|
44 | 44 |
sys.exit(error_code) |
45 | 45 |
|
46 | 46 |
load_haketilo = False |
... | ... | |
55 | 55 |
if not certdir.is_dir(): |
56 | 56 |
fail('selected certificate directory does not exist.', 2) |
57 | 57 |
|
58 |
argv_idx += 1 |
|
59 |
|
|
60 |
port = sys.argv[argv_idx] if len(sys.argv) > argv_idx \ |
|
61 |
else str(default_proxy_port) |
|
62 |
|
|
63 |
if not port.isnumeric(): |
|
64 |
fail('port must be an integer.', 3) |
|
65 |
|
|
66 |
httpd = do_an_internet(certdir, int(port)) |
|
67 |
driver = firefox_safe_mode(proxy_port=int(port)) |
|
58 |
httpd = do_an_internet(certdir) |
|
59 |
driver = firefox_safe_mode(proxy_port=httpd.server_port) |
|
68 | 60 |
|
69 | 61 |
if load_haketilo: |
70 | 62 |
driver.install_addon(str(Path.cwd() / 'mozilla-build.zip'), temporary=True) |
test/haketilo_test/conftest.py | ||
---|---|---|
46 | 46 |
|
47 | 47 |
@pytest.fixture(scope="session") |
48 | 48 |
def _driver(proxy): |
49 |
with firefox_safe_mode() as driver: |
|
49 |
with firefox_safe_mode(proxy.server_port) as driver:
|
|
50 | 50 |
yield driver |
51 | 51 |
driver.quit() |
52 | 52 |
|
... | ... | |
57 | 57 |
driver.switch_to.window(driver.window_handles[0]) |
58 | 58 |
|
59 | 59 |
@pytest.fixture() |
60 |
def driver(_driver, request): |
|
60 |
def driver(proxy, _driver, request):
|
|
61 | 61 |
nav_target = request.node.get_closest_marker('get_page') |
62 | 62 |
nav_target = nav_target.args[0] if nav_target else 'about:blank' |
63 | 63 |
|
64 | 64 |
second_driver = request.node.get_closest_marker('second_driver') |
65 | 65 |
|
66 | 66 |
if second_driver: |
67 |
with firefox_safe_mode() as _driver: |
|
67 |
with firefox_safe_mode(proxy.server_port) as _driver:
|
|
68 | 68 |
_driver.get(nav_target) |
69 | 69 |
yield _driver |
70 | 70 |
_driver.quit() |
test/haketilo_test/misc_constants.py | ||
---|---|---|
46 | 46 |
conf_settings[match.group(1).strip()] = match.group(2) |
47 | 47 |
|
48 | 48 |
default_proxy_host = '127.0.0.1' |
49 |
default_proxy_port = 1337 |
|
50 | 49 |
|
51 | 50 |
default_cert_dir = Path.cwd() / 'certs' |
52 | 51 |
|
test/haketilo_test/profiles.py | ||
---|---|---|
80 | 80 |
profile.set_preference('extensions.webextensions.uuids', |
81 | 81 |
json.dumps({extension_id: uuid})) |
82 | 82 |
|
83 |
def firefox_safe_mode(firefox_binary=conf_settings['BROWSER_BINARY'], |
|
84 |
proxy_host=default_proxy_host, |
|
85 |
proxy_port=default_proxy_port): |
|
83 |
def firefox_safe_mode(proxy_port, proxy_host=default_proxy_host, |
|
84 |
firefox_binary=conf_settings['BROWSER_BINARY']): |
|
86 | 85 |
""" |
87 | 86 |
Initialize a Firefox instance controlled by selenium. The instance is |
88 | 87 |
started in safe mode. |
... | ... | |
97 | 96 |
return HaketiloFirefox(options=options, firefox_profile=profile, |
98 | 97 |
firefox_binary=firefox_binary) |
99 | 98 |
|
100 |
def firefox_with_profile(firefox_binary=conf_settings['BROWSER_BINARY'], |
|
101 |
profile_dir=conf_settings['CLEAN_PROFILE'], |
|
102 |
proxy_host=default_proxy_host, |
|
103 |
proxy_port=default_proxy_port): |
|
99 |
def firefox_with_profile(proxy_port, proxy_host=default_proxy_host, |
|
100 |
firefox_binary=conf_settings['BROWSER_BINARY'], |
|
101 |
profile_dir=conf_settings['CLEAN_PROFILE']): |
|
104 | 102 |
""" |
105 | 103 |
Initialize a Firefox instance controlled by selenium. The instance is |
106 | 104 |
started using an empty profile (either the default one or the one passed to |
test/haketilo_test/server.py | ||
---|---|---|
33 | 33 |
from threading import Thread |
34 | 34 |
import traceback |
35 | 35 |
|
36 |
from selenium.webdriver.common.utils import free_port |
|
37 |
|
|
36 | 38 |
from .proxy_core import ProxyRequestHandler, ThreadingHTTPServer |
37 | 39 |
from .misc_constants import * |
38 | 40 |
from .world_wide_library import catalog as internet |
... | ... | |
99 | 101 |
if resp_body: |
100 | 102 |
self.wfile.write(resp_body) |
101 | 103 |
|
102 |
def do_an_internet(certdir=default_cert_dir, port=default_proxy_port):
|
|
104 |
def do_an_internet(certdir=default_cert_dir, port=None):
|
|
103 | 105 |
"""Start up the proxy/server""" |
106 |
if port is None: |
|
107 |
port = free_port() |
|
108 |
|
|
104 | 109 |
class RequestHijackerWithCertdir(RequestHijacker): |
105 | 110 |
def __init__(self, *args, **kwargs): |
106 | 111 |
super().__init__(*args, certdir=certdir, **kwargs) |
Also available in: Unified diff
automatically pick up a free port to run the HTTP proxy on
It is now possible to run multiple
make test
commands in parallel (e.g. testing abrowser and librewolf simultaneously after runningconfigure
for each of them in 2 different directories).