Revision c699b640
Added by koszko over 1 year ago
| test/unit/conftest.py | ||
|---|---|---|
| 26 | 26 |
# proprietary program, I am not going to enforce this in court. |
| 27 | 27 |
|
| 28 | 28 |
import pytest |
| 29 |
from pathlib import Path |
|
| 30 |
from selenium.webdriver.support.ui import WebDriverWait |
|
| 31 |
from selenium.webdriver.support import expected_conditions as EC |
|
| 29 | 32 |
|
| 30 |
from ..profiles import firefox_safe_mode |
|
| 31 |
from ..server import do_an_internet |
|
| 32 |
from ..script_loader import load_script |
|
| 33 |
from ..profiles import firefox_safe_mode |
|
| 34 |
from ..server import do_an_internet |
|
| 35 |
from ..script_loader import load_script |
|
| 36 |
from ..extension_crafting import make_extension |
|
| 33 | 37 |
|
| 34 | 38 |
@pytest.fixture(scope="package") |
| 35 | 39 |
def proxy(): |
| ... | ... | |
| 43 | 47 |
yield driver |
| 44 | 48 |
driver.quit() |
| 45 | 49 |
|
| 50 |
@pytest.fixture() |
|
| 51 |
def webextension(driver, request): |
|
| 52 |
ext_data = request.node.get_closest_marker('ext_data')
|
|
| 53 |
if ext_data is None: |
|
| 54 |
raise Exception('"webextension" fixture requires "ext_data" marker to be set')
|
|
| 55 |
|
|
| 56 |
ext_path = make_extension(Path(driver.firefox_profile.path), |
|
| 57 |
**ext_data.args[0]) |
|
| 58 |
driver.get('https://gotmyowndoma.in/')
|
|
| 59 |
addon_id = driver.install_addon(str(ext_path), temporary=True) |
|
| 60 |
WebDriverWait(driver, 10).until( |
|
| 61 |
EC.title_contains("Extension's options page for testing")
|
|
| 62 |
) |
|
| 63 |
yield |
|
| 64 |
driver.uninstall_addon(addon_id) |
|
| 65 |
ext_path.unlink() |
|
| 66 |
|
|
| 46 | 67 |
script_injecting_script = '''\ |
| 47 | 68 |
/* |
| 48 | 69 |
* Selenium by default executes scripts in some weird one-time context. We want |
| ... | ... | |
| 63 | 84 |
document.body.append(script_elem); |
| 64 | 85 |
|
| 65 | 86 |
/* |
| 66 |
* To ease debugging, we want this script to forward signal all exceptions from
|
|
| 67 |
* the injectee.
|
|
| 87 |
* To ease debugging, we want this script to signal all exceptions from the
|
|
| 88 |
* injectee. |
|
| 68 | 89 |
*/ |
| 69 | 90 |
try {
|
| 70 | 91 |
if (window.haketilo_selenium_exception !== false) |
Also available in: Unified diff
facilitate creating and installing WebExtensions during tests
It is now possible to more conveniently test WebExtension APIs code by wrapping it into a test WebExtension and temporarily installing in the driven browser.