diff --git a/server/test_all.py b/server/test_all.py index cc25917..0162a16 100755 --- a/server/test_all.py +++ b/server/test_all.py @@ -1,6 +1,10 @@ #!/usr/bin env python3 from pathlib import Path from time import sleep +from contextlib import contextmanager +from tempfile import TemporaryDirectory +import re +import json from selenium import webdriver # type: ignore import pyautogui # type: ignore @@ -9,11 +13,38 @@ import pyautogui # type: ignore addon_path = (Path(__file__).parent.parent / 'build').absolute() +@contextmanager def get_webdriver(): - profile = webdriver.FirefoxProfile() - driver = webdriver.Firefox(profile, firefox_binary='/L/soft/firefox-dev/firefox/firefox') - driver.install_addon(str(addon_path), temporary=True) - return driver + with TemporaryDirectory() as td: + profile = webdriver.FirefoxProfile(td) + driver = webdriver.Firefox(profile, firefox_binary='/L/soft/firefox-dev/firefox/firefox') + driver.install_addon(str(addon_path), temporary=True) + + # necessary to trigger prefs.js initialisation.. + driver.get('http://example.com') + sleep(1) + + moz_profile = Path(driver.capabilities['moz:profile']) + prefs_file = moz_profile / 'prefs.js' + addon_id = None + print(prefs_file) + for line in prefs_file.read_text().splitlines(): + print(line) + # temporary-addon\":\"53104c22-acd0-4d44-904c-22d11d31559a\"}") + m = re.search(r'temporary-addon.....([0-9a-z-]+)."', line) + if m is None: + continue + addon_id = m.group(1) + print("ADDON " + addon_id) + assert addon_id is not None + + options = f'moz-extension://{addon_id}/options.html' + print(options) + driver.get(options) + import ipdb; ipdb.set_trace() + + yield driver + # TODO close driver? # TODO need to fix hotkey! @@ -34,16 +65,17 @@ def trigger_grasp(): # pyautogui.locateOnScreen('/L/soft/browser-extensions/grasp/unicorn.png') print("sending hotkey!") + import ipdb; ipdb.set_trace() pyautogui.hotkey('ctrl', 'alt', 'c') def test(): - driver = get_webdriver() - driver.get('https://en.wikipedia.org/wiki/Automation') + with get_webdriver() as driver: + driver.get('https://en.wikipedia.org/wiki/Automation') - sleep(2) # just in case.. - # TODO select something? - trigger_grasp() + sleep(2) # just in case.. + # TODO select something? + trigger_grasp() def main():