aboutsummaryrefslogtreecommitdiff
path: root/test/profiles.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/profiles.py')
-rwxr-xr-xtest/profiles.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/test/profiles.py b/test/profiles.py
index 1530aea..795a0db 100755
--- a/test/profiles.py
+++ b/test/profiles.py
@@ -27,7 +27,8 @@ Browser profiles and Selenium driver initialization
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
-import time
+import json
+from shutil import rmtree
from .misc_constants import *
@@ -35,7 +36,8 @@ 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.
+ `get()` method is called and also facilitates removing the temporary
+ profile directory after Firefox quits.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -48,6 +50,11 @@ class HaketiloFirefox(webdriver.Firefox):
self.reset_loaded_scripts()
super().get(*args, **kwargs)
+ def quit(self, *args, **kwargs):
+ profile_path = self.firefox_profile.path
+ super().quit(*args, **kwargs)
+ rmtree(profile_path, ignore_errors=True)
+
def set_profile_proxy(profile, proxy_host, proxy_port):
"""
Create a Firefox profile that uses the specified HTTP proxy for all
@@ -67,6 +74,20 @@ def set_profile_proxy(profile, proxy_host, proxy_port):
def set_profile_console_logging(profile):
profile.set_preference('devtools.console.stdout.content', True)
+# The function below seems not to work for extensions that are
+# temporarily-installed in Firefox safe mode. Testing is needed to see if it
+# works with non-temporary extensions (without safe mode).
+def set_webextension_uuid(profile, extension_id, uuid=default_extension_uuid):
+ """
+ Firefox would normally assign a unique, random UUID to installed extension.
+ This UUID is needed to easily navigate to extension's settings page (and
+ other extension's pages). Since there's no way to learn such UUID with
+ current WebDriver implementation, this function works around this by telling
+ Firefox to use a predefined UUID for a certain extension.
+ """
+ profile.set_preference('extensions.webextensions.uuids',
+ json.dumps({extension_id: uuid}))
+
def firefox_safe_mode(firefox_binary=default_firefox_binary,
proxy_host=default_proxy_host,
proxy_port=default_proxy_port):
@@ -97,6 +118,7 @@ def firefox_with_profile(firefox_binary=default_firefox_binary,
profile = webdriver.FirefoxProfile(profile_dir)
set_profile_proxy(profile, proxy_host, proxy_port)
set_profile_console_logging(profile)
+ set_webextension_uuid(profile, default_haketilo_id)
return HaketiloFirefox(firefox_profile=profile,
firefox_binary=firefox_binary)