Revision 3611dd6a
Added by koszko over 1 year ago
| test/extension_crafting.py | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
# This file is part of Haketilo. |
| 8 | 8 |
# |
| 9 |
# Copyright (C) 2021 Wojtek Kosior <koszko@koszko.org> |
|
| 9 |
# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
|
|
| 10 | 10 |
# |
| 11 | 11 |
# This program is free software: you can redistribute it and/or modify |
| 12 | 12 |
# it under the terms of the GNU General Public License as published by |
| ... | ... | |
| 27 | 27 |
|
| 28 | 28 |
import json |
| 29 | 29 |
import zipfile |
| 30 |
import re |
|
| 31 |
import shutil |
|
| 32 |
import subprocess |
|
| 33 |
|
|
| 30 | 34 |
from pathlib import Path |
| 31 | 35 |
from uuid import uuid4 |
| 32 | 36 |
from tempfile import TemporaryDirectory |
| 33 |
import shutil |
|
| 34 |
import subprocess |
|
| 37 |
|
|
| 38 |
from selenium.webdriver.support.ui import WebDriverWait |
|
| 39 |
from selenium.common.exceptions import NoSuchElementException |
|
| 35 | 40 |
|
| 36 | 41 |
from .misc_constants import * |
| 37 | 42 |
|
| ... | ... | |
| 170 | 175 |
html.add_to_xpi(xpi) |
| 171 | 176 |
|
| 172 | 177 |
return destination_path |
| 178 |
|
|
| 179 |
extract_base_url_re = re.compile(r'^(.*)manifest.json$') |
|
| 180 |
|
|
| 181 |
def get_extension_base_url(driver): |
|
| 182 |
""" |
|
| 183 |
Extension's internall UUID is not directly exposed in Selenium. Instead, we |
|
| 184 |
can navigate to about:debugging and inspect the manifest URL present there |
|
| 185 |
to get the base url like: |
|
| 186 |
moz-extension://b225c78f-d108-4caa-8406-f38b37d8dee5/ |
|
| 187 |
which can then be used to navigate to extension-bundled pages. |
|
| 188 |
""" |
|
| 189 |
# For newer Firefoxes |
|
| 190 |
driver.get('about:debugging#/runtime/this-firefox')
|
|
| 191 |
|
|
| 192 |
def get_manifest_link_newer_ff(driver): |
|
| 193 |
try: |
|
| 194 |
return driver.find_element_by_class_name('qa-manifest-url')
|
|
| 195 |
except NoSuchElementException: |
|
| 196 |
pass |
|
| 197 |
|
|
| 198 |
try: |
|
| 199 |
details = driver.find_element_by_class_name('error-page-details')
|
|
| 200 |
except NoSuchElementException: |
|
| 201 |
return False |
|
| 202 |
|
|
| 203 |
if '#/runtime/this-firefox' in details.text: |
|
| 204 |
return "not_newer_ff" |
|
| 205 |
|
|
| 206 |
manifest_link = WebDriverWait(driver, 10).until(get_manifest_link_newer_ff) |
|
| 207 |
|
|
| 208 |
if manifest_link == "not_newer_ff": |
|
| 209 |
driver.get("about:debugging#addons")
|
|
| 210 |
driver.implicitly_wait(10) |
|
| 211 |
manifest_link = driver.find_element_by_class_name('manifest-url')
|
|
| 212 |
driver.implicitly_wait(0) |
|
| 213 |
|
|
| 214 |
manifest_url = manifest_link.get_attribute('href')
|
|
| 215 |
return extract_base_url_re.match(manifest_url).group(1) |
|
Also available in: Unified diff
facilitate running test environment with Haketilo loaded into browser