Revision e1282a63
Added by koszko almost 2 years ago
| test/profiles.py | ||
|---|---|---|
| 31 | 31 |
|
| 32 | 32 |
from .misc_constants import * |
| 33 | 33 |
|
| 34 |
class HaketiloFirefox(webdriver.Firefox): |
|
| 35 |
""" |
|
| 36 |
This wrapper class around selenium.webdriver.Firefox adds a `loaded_scripts` |
|
| 37 |
instance property that gets resetted to an empty array every time the |
|
| 38 |
`get()` method is called. |
|
| 39 |
""" |
|
| 40 |
def __init__(self, *args, **kwargs): |
|
| 41 |
super().__init__(*args, **kwargs) |
|
| 42 |
self.reset_loaded_scripts() |
|
| 43 |
|
|
| 44 |
def reset_loaded_scripts(self): |
|
| 45 |
self.loaded_scripts = [] |
|
| 46 |
|
|
| 47 |
def get(self, *args, **kwargs): |
|
| 48 |
self.reset_loaded_scripts() |
|
| 49 |
super().get(*args, **kwargs) |
|
| 50 |
|
|
| 34 | 51 |
def set_profile_proxy(profile, proxy_host, proxy_port): |
| 52 |
""" |
|
| 53 |
Create a Firefox profile that uses the specified HTTP proxy for all |
|
| 54 |
protocols. |
|
| 55 |
""" |
|
| 35 | 56 |
# proxy type 1 designates "manual" |
| 36 | 57 |
profile.set_preference('network.proxy.type', 1)
|
| 37 | 58 |
profile.set_preference('network.proxy.no_proxies_on', '')
|
| ... | ... | |
| 49 | 70 |
def firefox_safe_mode(firefox_binary=default_firefox_binary, |
| 50 | 71 |
proxy_host=default_proxy_host, |
| 51 | 72 |
proxy_port=default_proxy_port): |
| 73 |
""" |
|
| 74 |
Initialize a Firefox instance controlled by selenium. The instance is |
|
| 75 |
started in safe mode. |
|
| 76 |
""" |
|
| 52 | 77 |
profile = webdriver.FirefoxProfile() |
| 53 | 78 |
set_profile_proxy(profile, proxy_host, proxy_port) |
| 54 | 79 |
set_profile_console_logging(profile) |
| ... | ... | |
| 56 | 81 |
options = Options() |
| 57 | 82 |
options.add_argument('--safe-mode')
|
| 58 | 83 |
|
| 59 |
return webdriver.Firefox(options=options, firefox_profile=profile,
|
|
| 60 |
firefox_binary=firefox_binary)
|
|
| 84 |
return HaketiloFirefox(options=options, firefox_profile=profile,
|
|
| 85 |
firefox_binary=firefox_binary) |
|
| 61 | 86 |
|
| 62 | 87 |
def firefox_with_profile(firefox_binary=default_firefox_binary, |
| 63 | 88 |
profile_dir=default_clean_profile_dir, |
| 64 | 89 |
proxy_host=default_proxy_host, |
| 65 | 90 |
proxy_port=default_proxy_port): |
| 91 |
""" |
|
| 92 |
Initialize a Firefox instance controlled by selenium. The instance is |
|
| 93 |
started using an empty profile (either the default one or the one passed to |
|
| 94 |
`configure` script). The empty profile is meant to make Firefox start with |
|
| 95 |
globally-installed extensions disabled. |
|
| 96 |
""" |
|
| 66 | 97 |
profile = webdriver.FirefoxProfile(profile_dir) |
| 67 | 98 |
set_profile_proxy(profile, proxy_host, proxy_port) |
| 68 | 99 |
set_profile_console_logging(profile) |
| 69 | 100 |
|
| 70 |
return webdriver.Firefox(firefox_profile=profile, |
|
| 71 |
firefox_binary=firefox_binary) |
|
| 101 |
return HaketiloFirefox(firefox_profile=profile, |
|
| 102 |
firefox_binary=firefox_binary) |
|
Also available in: Unified diff
finish implementing more efficient querying of URL patterns
The algorithm is implemented and tested. However, it is yet to be hooked into the actual extension.