aboutsummaryrefslogtreecommitdiff
path: root/test/profiles.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/profiles.py')
-rwxr-xr-xtest/profiles.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/test/profiles.py b/test/profiles.py
index d6a4efc..1530aea 100755
--- a/test/profiles.py
+++ b/test/profiles.py
@@ -31,7 +31,28 @@ import time
from .misc_constants import *
+class HaketiloFirefox(webdriver.Firefox):
+ """
+ This wrapper class around selenium.webdriver.Firefox adds a `loaded_scripts`
+ instance property that gets resetted to an empty array every time the
+ `get()` method is called.
+ """
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.reset_loaded_scripts()
+
+ def reset_loaded_scripts(self):
+ self.loaded_scripts = []
+
+ def get(self, *args, **kwargs):
+ self.reset_loaded_scripts()
+ super().get(*args, **kwargs)
+
def set_profile_proxy(profile, proxy_host, proxy_port):
+ """
+ Create a Firefox profile that uses the specified HTTP proxy for all
+ protocols.
+ """
# proxy type 1 designates "manual"
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.no_proxies_on', '')
@@ -49,6 +70,10 @@ def set_profile_console_logging(profile):
def firefox_safe_mode(firefox_binary=default_firefox_binary,
proxy_host=default_proxy_host,
proxy_port=default_proxy_port):
+ """
+ Initialize a Firefox instance controlled by selenium. The instance is
+ started in safe mode.
+ """
profile = webdriver.FirefoxProfile()
set_profile_proxy(profile, proxy_host, proxy_port)
set_profile_console_logging(profile)
@@ -56,16 +81,22 @@ def firefox_safe_mode(firefox_binary=default_firefox_binary,
options = Options()
options.add_argument('--safe-mode')
- return webdriver.Firefox(options=options, firefox_profile=profile,
- firefox_binary=firefox_binary)
+ return HaketiloFirefox(options=options, firefox_profile=profile,
+ firefox_binary=firefox_binary)
def firefox_with_profile(firefox_binary=default_firefox_binary,
profile_dir=default_clean_profile_dir,
proxy_host=default_proxy_host,
proxy_port=default_proxy_port):
+ """
+ Initialize a Firefox instance controlled by selenium. The instance is
+ started using an empty profile (either the default one or the one passed to
+ `configure` script). The empty profile is meant to make Firefox start with
+ globally-installed extensions disabled.
+ """
profile = webdriver.FirefoxProfile(profile_dir)
set_profile_proxy(profile, proxy_host, proxy_port)
set_profile_console_logging(profile)
- return webdriver.Firefox(firefox_profile=profile,
- firefox_binary=firefox_binary)
+ return HaketiloFirefox(firefox_profile=profile,
+ firefox_binary=firefox_binary)